博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
windows8 Metro App用Javascript来调用C#的library
阅读量:7094 次
发布时间:2019-06-28

本文共 1124 字,大约阅读时间需要 3 分钟。

(转自:http://www.ronaldwidha.net/2012/05/10/winrt-calling-c-csharp-class-libraries-from-winjs-javascript/)

WinRT: Calling C# (CSharp) class libraries from WinJS Javascript

I must say Microsoft is doing a great job with supporting polyglot programming. With .Net CLR support for numerous languages from C#, VB, F#, IronRuby, IronPython and all that – and now WinRT with C++, C# and JS. This post is going to quickly show how you could call a C# class from Javascript within WinRT.

 

1. Add a class library

I assume you have an existing Javascript Metro Application Project. So now what you have to do is just add a C# Metro Class Library. Add a class. Notice a few rules:

  1. Root namespace has to match assembly name
  2. class has to be sealed
  3. and 
namespace ClassLibrary1 { public sealed class Class1 { public string test() { return String.Empty; } } }

 

2. Change type of the project to WinMD

Right click solution, properties, under application tab, change output type to WinMD File.

image

3. Reference project from the JS Metro Application Project

4. Consume the class from JS

var csharpclass = new ClassLibrary1.Class1(); csharpclass.test();

 

 

 

转载地址:http://mdxql.baihongyu.com/

你可能感兴趣的文章
Linux 驱动加载到内核中编译<1>
查看>>
MyBatis-Spring 使用总结
查看>>
[Angular 2] Understanding OpaqueToken
查看>>
MyEclipse安装EGit插件方法
查看>>
亲测 logminer挖掘
查看>>
设计模式原则 依赖倒置
查看>>
redis设置密码
查看>>
H264编码技术[3]
查看>>
解决 docker: Error response from daemon: ... : net/http: TLS handshake timeout.
查看>>
[置顶] Android中使用Movie显示gif动态图
查看>>
php MongoDB driver 查询实例
查看>>
ASP.NET 前端Ajax获取数据并刷新
查看>>
Java NIO5:通道和文件通道
查看>>
Ambari架构原理
查看>>
Oracle 通过子查询批量添加、修改表数据
查看>>
在Map对象中获取属性,注意判断为空
查看>>
php的pear编程: phpDocumentor的使用?
查看>>
Win10系列:C#应用控件基础23
查看>>
三元运算符
查看>>
Oracle管理监控之使用utl_mail自动邮件报警配置
查看>>