Metro c#中缺少String.Intern()方法方法、Metro、String、Intern

由网友(薄荷味的夏~)分享简介:如何在 Metro c# 中获取字符串实习生方法.如果在 windows 8 c# 中找不到,是否有任何等效的方法来维护系统对指定字符串的引用.How to get string intern method in Metro c#. if not found in windows 8 c#, is there any...

如何在 Metro c# 中获取字符串实习生方法.如果在 windows 8 c# 中找不到,是否有任何等效的方法来维护系统对指定字符串的引用.

How to get string intern method in Metro c#. if not found in windows 8 c#, is there any equivalent method to maintain system's reference to the specified String.

推荐答案

这是 CLR 中内置的语言投影不可避免的副作用,它启用了.NET for Metro 风格应用程序"api.该投影将从 WinRT api 调用获得的字符串映射到 System.String.底层字符串根本不是托管字符串,也不存在于垃圾收集堆上.它是一种 HSTRING. 语言投影使它表现得像一个 System.String

This is an inevitable side-effect of the language projection built into the CLR that enables the ".NET for Metro style apps" api. That projection maps a string that was obtained from a WinRT api call to System.String. The underlying string is not a managed string at all and doesn't live on the garbage collected heap. It is an HSTRING. The language projection makes it behave like a System.String

因此,在该 api 中,String 类没有非常特定于托管字符串的方法.像 Intern() 和 IsInterned() 一样,它只能用于托管字符串.Copy、Clone 和 GetEnumerator 也一样.对此没有解决方法,对 mscorlib 中托管 String 类的访问完全被引用程序集阻止,它将类型转发到 System.Runtime.dll.如果没有这种方法,你必须让它工作.

Accordingly, in that api, the String class doesn't have the methods that are very specific to managed strings. Like Intern() and IsInterned(), that can only work for managed strings. Copy, Clone and GetEnumerator are awol too. There's no workaround for this, access to the managed String class in mscorlib is entirely blocked by the reference assemblies, it gets type forwarded to System.Runtime.dll. You'll have to make it work without that method.

阅读全文

相关推荐

最新文章