19 Ocak 2009, PAZARTESİ
Eğer bir sınıf, genel bir sınıftan türetilmiş olup olmadığını kontrol edin
Türetilmiş sınıfları ile benim projeye genel bir Dersim var.
public class GenericClass<T> : GenericInterface<T>
{
}
public class Test : GenericClass<SomeType>
{
}
Type
nesne GenericClass
den türetilmiş olup olmadığını öğrenmek için herhangi bir yolu var mı?
t.IsSubclassOf(typeof(GenericClass<>))
çalışmıyor.
CEVAP
19 Ocak 2009, PAZARTESİ
Bu kodu deneyin
static bool IsSubclassOfRawGeneric(Type generic, Type toCheck) {
while (toCheck != null && toCheck != typeof(object)) {
var cur = toCheck.IsGenericType ? toCheck.GetGenericTypeDefinition() : toCheck;
if (generic == cur) {
return true;
}
toCheck = toCheck.BaseType;
}
return false;
}
Bunu Paylaş:
Zayıf Bağlantı - eğer bir sınıf mevcut...
Eğer herhangi bir ata sınıf jQuery kul...
Eğer nesne dizisi olup olmadığını kont...
Eğer jQuery ile checkbox işaretli olup...
Eğer nesne bir WordPress kullanmak bir...