zoukankan      html  css  js  c++  java
  • windows8 Metro App用Javascript来调用C#的library

    (转自: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 there’s a few more restriction
    namespace ClassLibrary1 { publicsealedclass Class1 { publicstring 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();

    Read more: Walthrough creating a simple component in C# and calling it from JavaScript

  • 相关阅读:
    格式与布局
    iframe
    tp
    头信息
    php 文件下载
    socket
    Flex 布局2
    Flex 布局
    下拉刷新
    选取一种类中含有某一属性值得元素的集合
  • 原文地址:https://www.cnblogs.com/imlucky/p/3223478.html
Copyright © 2011-2022 走看看