开发者

Trouble checking dynamic entity

开发者 https://www.devze.com 2023-02-07 02:53 出处:网络
Greetings, A old colleague of mine made this code: public abstract class PagedViewModelBase<T> : PartnerViewModelBase, IPagedCollectionView where T : Entity, IEditableObject, new()

Greetings,

A old colleague of mine made this code:

public abstract class PagedViewModelBase<T> : PartnerViewModelBase, IPagedCollectionView where T : Entity, IEditableObject, new()

Now I want to check what the type/value is of T.. I've tried using "T is Model but it gives me the er开发者_开发百科ror "'T' is a 'type parameter' but is used like a 'variable'".

How can I check if "T" is of a particular model ?


You could try the following check

typeof(T) == typeof(Model)


In most cases you can check it with this code


typeof(Model).IsAssignableFrom(typeof(T));

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号