简体   繁体   中英

Separate GUIDs in Generic classes in C#

I've created the following class:

[Guid("4469031d-23e0-483c-8566-ce978ccc9a6f")]
class MyGenericContianer<BasicType> : SomeOtherContainer
{
}

This causes the folowing two classes to have the same GUID:

MyGenericContianer<int> x;
MyGenericContianer<float> y;

I need each specific type to have it's own GUID. How would you do this?

You would need to do this with inheritance.

class MyGenericContianer<BasicType> : SomeOtherContainer { }

[Guid("4469031d-23e0-483c-8566-ce978ccc9a6f")]
class Container1: MyGenericContainer<X> { }

[Guid("5569031d-23e0-483c-8566-ce978ccc9a6f")]
class Container2: MyGenericContainer<Y> { }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM