Are automatically generated GUIDs for types in .NET consistent?

↘锁芯ラ 提交于 2019-11-26 20:51:54

问题


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.


回答1:


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.




回答2:


It's not documented so i wouldn't completly rely on them, said that the implementation may or may not change in the future.



来源:https://stackoverflow.com/questions/5649883/are-automatically-generated-guids-for-types-in-net-consistent

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!