![](/img/trans.png)
[英]How to get the generic type parameters for a ENVDTE CodeInterface?
[英]How can I get the generic constraints from CodeInterface as a CodeType object?
我在Visual Studio 2010中使用DTE檢查C#類並自動生成代碼。
當我遇到實現通用接口的類時,我想將類型約束作為CodeType
對象進行訪問。
例:
class ServiceProviderCollection : IList<IServiceProvider> {}
我有代表ServiceProviderCollection
的CodeClass
對象。 我可以獲得CodeInterface
為對象IList<IServiceProvider>
通過使用CodeClass.ImplementedInterfaces
。 但是我不知道如何從那里到達代表IServiceProvider
的CodeInterface
對象。
我可以通過解析CodeInterface.FullName並獲取<和>之間的字符串來找到類型約束的名稱 ,但這還不夠。
如果重要的話,我正在使用C#來實現這一點。
鑒於Microsoft專注於Roslyn以完全替代此模型,因此解析FullName
可能是唯一的方法。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.