Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
680 views
in Technique[技术] by (71.8m points)

windows 8 - String.Intern() method missing in metro 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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...