是自动生成的GUID在.NET一致的类型? [英] Are automatically generated GUIDs for types in .NET consistent?

查看:124
本文介绍了是自动生成的GUID在.NET一致的类型?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是自动生成的GUID C#的类型是否一致?例如,如果我得到一个GUID为我的接口,IFoo的(的typeof(的IFoo).GUID ),第一次运行程序,我会得到相同的GUID每次我运行程序?

Are the automatically generated GUIDs for C# Types consistent? For example, if I get a GUID for my interface, IFoo (typeof(IFoo).GUID), the first time a run the program, will I get that same GUID everytime I run the program?

我有我的本地机器上测试过它,它似乎永远是相同的,但我不知道我是否可以依靠它始终是相同的跨机器。

I have tested it locally on my machine, and it seems to always be the same, but I'm not sure if I can rely on it always being the same across machines.

推荐答案

请参阅:的 System.Type.GUID稳定。看来,该方法的当前实现依赖于一个由CLR本身实现的内部通话。除非微软明确了合同自动生成的GUID(在<一个href="http://msdn.microsoft.com/en-us/library/system.type.guid.aspx"><$c$c>Type.GUID文档在这个问题上目前沉默),我不会依靠观察到的行为。可以肯定的约一致性,我建议明确装修类型与<一个问题href="http://msdn.microsoft.com/en-us/library/system.runtime.interopservices.guidattribute.aspx"><$c$c>GuidAttribute.

See: System.Type.GUID stability. It appears that the current implementation of the method relies an internal call that is implemented by the CLR itself. Unless Microsoft clarifies the contracts for the auto-generated Guids (the Type.GUID documentation is currently silent on this issue), I wouldn't rely on the observed behaviour. To be sure about consistency, I recommend explicitly decorating the types in question with the GuidAttribute.

这篇关于是自动生成的GUID在.NET一致的类型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆