【问题标题】:how to pass or inject standard .net object in windows runtime class如何在 Windows 运行时类中传递或注入标准 .net 对象
【发布时间】:2020-04-21 21:54:48
【问题描述】:

我有一个 WinRT 项目,它有一个 WinRT 类。现在,我想将 .net 标准对象注入或传递到 WinRT 类的构造函数或方法中。但不知何故,它不允许。虽然如果我使用标准 .net 类的静态方法,那么我可以访问和调用静态方法。

所以,只想知道有没有办法在 WinRT 类中传入用户定义的接口或类型。

我经历过这个article

但找不到任何东西

【问题讨论】:

  • 您能否提供更多信息,甚至可以提供您正在尝试使用的一些代码(以及它给您带来的错误)?通常,WinRT 不理解 .NET 对象。

标签: c# .net uwp windows-runtime


【解决方案1】:

如何在 Windows 运行时类中传递或注入标准 .net 对象

您可以制作.Net Standard 类库并打包.Net Standard 对象,然后在Windows 运行时组件中引用它。然后在uwp项目中调用runtime方法。

代码段

public sealed class RunTimeCore
{
    public static string GetString()
    {
        return TestLib.TestTool.GetString();
    }
}


public class TestTool
{
    public static string GetString() {

        return "hello";
    }
}

用法

var str = RuntimeComponent.RunTimeCore.GetString();

【讨论】:

    猜你喜欢
    • 2022-01-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-07-09
    • 2016-01-17
    • 1970-01-01
    • 2015-05-29
    • 1970-01-01
    相关资源
    最近更新 更多