簡體   English   中英

C# 中的通用類中的單獨 GUID

[英]Separate GUIDs in Generic classes in C#

我創建了以下 class:

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

這會導致以下兩個類具有相同的 GUID:

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

我需要每種特定類型都有自己的 GUID。 你會怎么做?

您需要使用 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> { }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM