我发现类继承自接口:
var baseType = typeof(ICustomSerialization);
Assembly assembly = baseType.Assembly;
var subClass = assembly.GetTypes().Where(t => t.IsSubclassOf(baseType) );
如果类有属性和参数名称:
[CustomAttribute(Name="Soap")]
class CustomSoapSerializer : ICustomSerialization
这是一种通过反射获得此属性的名称属性的方法?
试试这个
public static class CustomAttributeProviderExtensions
{
public static TAttribute[] GetCustomAttributes<TAttribute>(this ICustomAttributeProvider self)
where TAttribute:Attribute
{
return (TAttribute[])self.GetCustomAttributes(typeof(TAttribute), true);
}
}
和
的用法var baseType = typeof(ICustomSerialization);
Assembly assembly = baseType.Assembly;
var subClass = assembly.GetTypes().Where(t => baseType.IsAssignableFrom(t))
.Where(t=>t.GetCustomAttributes<CustomAttribute>().Any(x=>x.Name == "Soap"))
.ToList();