您说您有理由从System.Type 继承,即使我同意@mootinator,以下是您其他问题的一些答案:
有没有简单的方法来继承 Type?
没有。
我必须实现所有方法吗?
是的。
如果有,是否有任何参考资料?
您将override-关键字添加到每个Properties 和Methods
这是一个如何开始的示例,您需要 override 每个 abstract 属性和方法。
public class Test : Type
{
public override Guid GUID
{
get { throw new NotImplementedException(); }
}
}
这是一个完全可编译的class,它覆盖了所有需要的properties 和methods,但没有实现任何东西。
public class Test : Type
{
public override Guid GUID
{
get { throw new NotImplementedException(); }
}
public override bool IsDefined(Type attributeType, bool inherit)
{
throw new NotImplementedException();
}
public override object[] GetCustomAttributes(bool inherit)
{
throw new NotImplementedException();
}
public override string Name
{
get { throw new NotImplementedException(); }
}
protected override bool HasElementTypeImpl()
{
throw new NotImplementedException();
}
public override object[]
GetCustomAttributes(Type attributeType, bool inherit)
{
throw new NotImplementedException();
}
public override Type UnderlyingSystemType
{
get { throw new NotImplementedException(); }
}
public override Type GetElementType()
{
throw new NotImplementedException();
}
protected override bool IsCOMObjectImpl()
{
throw new NotImplementedException();
}
protected override bool IsPrimitiveImpl()
{
throw new NotImplementedException();
}
protected override bool IsPointerImpl()
{
throw new NotImplementedException();
}
protected override bool IsByRefImpl()
{
throw new NotImplementedException();
}
protected override bool IsArrayImpl()
{
throw new NotImplementedException();
}
protected override System.Reflection.TypeAttributes
GetAttributeFlagsImpl()
{
throw new NotImplementedException();
}
public override System.Reflection.MemberInfo[]
GetMember(string name, System.Reflection.BindingFlags bindingAttr)
{
return base.GetMember(name, bindingAttr);
}
public override Type
GetNestedType(string name, System.Reflection.BindingFlags bindingAttr)
{
throw new NotImplementedException();
}
public override System.Reflection.PropertyInfo[]
GetProperties(System.Reflection.BindingFlags bindingAttr)
{
throw new NotImplementedException();
}
protected override System.Reflection.PropertyInfo
GetPropertyImpl(string name, System.Reflection.BindingFlags bindingAttr,
System.Reflection.Binder binder, Type returnType, Type[] types,
System.Reflection.ParameterModifier[] modifiers)
{
throw new NotImplementedException();
}
public override System.Reflection.MemberInfo[]
GetMembers(System.Reflection.BindingFlags bindingAttr)
{
throw new NotImplementedException();
}
public override Type[] GetNestedTypes(System.Reflection.BindingFlags bindingAttr)
{
throw new NotImplementedException();
}
public override System.Reflection.EventInfo[] GetEvents()
{
return base.GetEvents();
}
public override Type[] GetInterfaces()
{
throw new NotImplementedException();
}
public override Type GetInterface(string name, bool ignoreCase)
{
throw new NotImplementedException();
}
public override System.Reflection.EventInfo[]
GetEvents(System.Reflection.BindingFlags bindingAttr)
{
throw new NotImplementedException();
}
public override System.Reflection.FieldInfo[]
GetFields(System.Reflection.BindingFlags bindingAttr)
{
throw new NotImplementedException();
}
public override System.Reflection.EventInfo
GetEvent(string name, System.Reflection.BindingFlags bindingAttr)
{
throw new NotImplementedException();
}
public override System.Reflection.FieldInfo
GetField(string name, System.Reflection.BindingFlags bindingAttr)
{
throw new NotImplementedException();
}
public override System.Reflection.MethodInfo[]
GetMethods(System.Reflection.BindingFlags bindingAttr)
{
throw new NotImplementedException();
}
protected override System.Reflection.MethodInfo
GetMethodImpl(string name, System.Reflection.BindingFlags bindingAttr,
System.Reflection.Binder binder, System.Reflection.CallingConventions callConvention,
Type[] types, System.Reflection.ParameterModifier[] modifiers)
{
throw new NotImplementedException();
}
public override System.Reflection.ConstructorInfo[] GetConstructors(System.Reflection.BindingFlags bindingAttr)
{
throw new NotImplementedException();
}
protected override System.Reflection.ConstructorInfo
GetConstructorImpl(System.Reflection.BindingFlags bindingAttr, System.Reflection.Binder binder,
System.Reflection.CallingConventions callConvention, Type[] types,
System.Reflection.ParameterModifier[] modifiers)
{
throw new NotImplementedException();
}
public override Type BaseType
{
get { throw new NotImplementedException(); }
}
public override string AssemblyQualifiedName
{
get { throw new NotImplementedException(); }
}
public override string Namespace
{
get { throw new NotImplementedException(); }
}
public override string FullName
{
get { throw new NotImplementedException(); }
}
public override System.Reflection.Assembly Assembly
{
get { throw new NotImplementedException(); }
}
public override System.Reflection.Module Module
{
get { throw new NotImplementedException(); }
}
public override object
InvokeMember(string name, System.Reflection.BindingFlags invokeAttr,
System.Reflection.Binder binder, object target, object[] args,
System.Reflection.ParameterModifier[] modifiers,
System.Globalization.CultureInfo culture, string[] namedParameters)
{
throw new NotImplementedException();
}
}
这些是您需要实现的属性获取
- GUID
- 基本类型
- AssemblyQualifiedName
- 命名空间
- 全名
- 组装
- 模块
- 基础系统类型
- 姓名
这些是您需要实现的方法
- InvokeMember
- GetConstructorImpl
- 获取构造函数
- GetMethodImpl
- GetMethods
- 获取字段
- 获取事件
- 获取字段
- 获取事件
- 获取接口
- 获取接口
- 获取事件
- GetNestedTypes
- 获取会员
- GetPropertyImpl
- 获取属性
- GetNestedType
- 获取会员
- GetAttributeFlagsImpl
- IsArrayImpl
- IsByRefImpl
- IsPointerImpl
- IsPrimitiveImpl
- IsCOMObjectImpl
- 获取元素类型
- GetCustomAttributes
- HasElementTypeImpl
- GetCustomAttributes
- 已定义
如您所见,为了消除所有编译错误,您需要重写很多内容,所以要么您有充分的理由想要这样做,要么您应该考虑从另一个类/结构或只是创建一个新的类/结构。