你说你有你的理由从System.Type
继承,即使我同意@mootinator,这里有一些回答您的其他问题:
有没有简单的方法来继承类型?
号
我一定要实现所有的方法呢?
是的。
如果是这样,那么有没有任何参考文献呢?
您添加override
-keyword到每个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
- BASETYPE
- AssemblyQualifiedName
- 命名空间
- 全名
- 奥丝mbly
- 模块
- UnderlyingSystemType
- 名称
这些都是你需要实现
- InvokeMember
- GetConstructorImpl方法
- GetConstructors
- GetMethodImpl
- 的getMethods
- getfield命令
- GetEvent
- GetFields
- GetEvents
- GetInterface
- GetInterfaces
- GetEvents
- GetNestedTypes
- 个GetMembers
- GetPropertyImpl
- 的GetProperties
- GetNestedType
- GetMember
- GetAttributeFlagsImpl
- IsArrayImpl
- IsByRefImpl
- IsPointerImpl
- IsPrimitiveImpl
- ISCO MObjectImpl
- GetElementType
- GetCustomAttributes
- HasElementTypeImpl
- GetCustomAttributes
- IsDefined
正如你可以看到,有相当多的,你需要,以消除所有的编译错误覆盖,所以要么你有一个很好的理由想要做到这一点,或者你应该考虑重写另一个类/结构,或者只是创建一个新的类/结构。
**为什么**你需要子类'Type'?请解释一下,因为这没有意义。 –
听起来有点狂野,为什么你需要继承System.Type? – DEHAAS
只有当你试图扩展当前的反射系统(或者实现你自己的,我想)时,你应该继承'Type'。否则,你可以声明一个新的'struct',不需要继承。 – dlev