|
| 1 | +// Licensed to the .NET Foundation under one or more agreements. |
| 2 | +// The .NET Foundation licenses this file to you under the MIT license. |
| 3 | +// See the LICENSE file in the project root for more information. |
| 4 | + |
| 5 | +// TypeDelegator |
| 6 | +// |
| 7 | +// This class wraps a Type object and delegates all methods to that Type. |
| 8 | + |
| 9 | +using CultureInfo = System.Globalization.CultureInfo; |
| 10 | + |
| 11 | +namespace System.Reflection |
| 12 | +{ |
| 13 | + [Serializable] |
| 14 | + public class TypeDelegator : TypeInfo |
| 15 | + { |
| 16 | + public override bool IsAssignableFrom(TypeInfo typeInfo) |
| 17 | + { |
| 18 | + if (typeInfo == null) |
| 19 | + return false; |
| 20 | + return IsAssignableFrom(typeInfo.AsType()); |
| 21 | + } |
| 22 | + |
| 23 | + protected Type typeImpl; |
| 24 | + |
| 25 | + protected TypeDelegator() { } |
| 26 | + |
| 27 | + public TypeDelegator(Type delegatingType) |
| 28 | + { |
| 29 | + if (delegatingType == null) |
| 30 | + throw new ArgumentNullException(nameof(delegatingType)); |
| 31 | + |
| 32 | + typeImpl = delegatingType; |
| 33 | + } |
| 34 | + |
| 35 | + public override Guid GUID => typeImpl.GUID; |
| 36 | + public override int MetadataToken => typeImpl.MetadataToken; |
| 37 | + |
| 38 | + public override object InvokeMember(string name, BindingFlags invokeAttr, Binder binder, object target, |
| 39 | + object[] args, ParameterModifier[] modifiers, CultureInfo culture, string[] namedParameters) |
| 40 | + { |
| 41 | + return typeImpl.InvokeMember(name, invokeAttr, binder, target, args, modifiers, culture, namedParameters); |
| 42 | + } |
| 43 | + |
| 44 | + public override Module Module => typeImpl.Module; |
| 45 | + public override Assembly Assembly => typeImpl.Assembly; |
| 46 | + public override RuntimeTypeHandle TypeHandle => typeImpl.TypeHandle; |
| 47 | + public override string Name => typeImpl.Name; |
| 48 | + public override string FullName => typeImpl.FullName; |
| 49 | + public override string Namespace => typeImpl.Namespace; |
| 50 | + public override string AssemblyQualifiedName => typeImpl.AssemblyQualifiedName; |
| 51 | + public override Type BaseType => typeImpl.BaseType; |
| 52 | + |
| 53 | + protected override ConstructorInfo GetConstructorImpl(BindingFlags bindingAttr, Binder binder, |
| 54 | + CallingConventions callConvention, Type[] types, ParameterModifier[] modifiers) |
| 55 | + { |
| 56 | + return typeImpl.GetConstructor(bindingAttr, binder, callConvention, types, modifiers); |
| 57 | + } |
| 58 | + |
| 59 | + public override ConstructorInfo[] GetConstructors(BindingFlags bindingAttr) => typeImpl.GetConstructors(bindingAttr); |
| 60 | + |
| 61 | + protected override MethodInfo GetMethodImpl(string name, BindingFlags bindingAttr, Binder binder, |
| 62 | + CallingConventions callConvention, Type[] types, ParameterModifier[] modifiers) |
| 63 | + { |
| 64 | + // This is interesting there are two paths into the impl. One that validates |
| 65 | + // type as non-null and one where type may be null. |
| 66 | + if (types == null) |
| 67 | + return typeImpl.GetMethod(name, bindingAttr); |
| 68 | + else |
| 69 | + return typeImpl.GetMethod(name, bindingAttr, binder, callConvention, types, modifiers); |
| 70 | + } |
| 71 | + |
| 72 | + public override MethodInfo[] GetMethods(BindingFlags bindingAttr) => typeImpl.GetMethods(bindingAttr); |
| 73 | + |
| 74 | + public override FieldInfo GetField(string name, BindingFlags bindingAttr) => typeImpl.GetField(name, bindingAttr); |
| 75 | + public override FieldInfo[] GetFields(BindingFlags bindingAttr) => typeImpl.GetFields(bindingAttr); |
| 76 | + |
| 77 | + public override Type GetInterface(string name, bool ignoreCase) => typeImpl.GetInterface(name, ignoreCase); |
| 78 | + |
| 79 | + public override Type[] GetInterfaces() => typeImpl.GetInterfaces(); |
| 80 | + |
| 81 | + public override EventInfo GetEvent(string name, BindingFlags bindingAttr) => typeImpl.GetEvent(name, bindingAttr); |
| 82 | + |
| 83 | + public override EventInfo[] GetEvents() => typeImpl.GetEvents(); |
| 84 | + |
| 85 | + protected override PropertyInfo GetPropertyImpl(string name, BindingFlags bindingAttr, Binder binder, |
| 86 | + Type returnType, Type[] types, ParameterModifier[] modifiers) |
| 87 | + { |
| 88 | + if (returnType == null && types == null) |
| 89 | + return typeImpl.GetProperty(name, bindingAttr); |
| 90 | + else |
| 91 | + return typeImpl.GetProperty(name, bindingAttr, binder, returnType, types, modifiers); |
| 92 | + } |
| 93 | + |
| 94 | + public override PropertyInfo[] GetProperties(BindingFlags bindingAttr) => typeImpl.GetProperties(bindingAttr); |
| 95 | + public override EventInfo[] GetEvents(BindingFlags bindingAttr) => typeImpl.GetEvents(bindingAttr); |
| 96 | + public override Type[] GetNestedTypes(BindingFlags bindingAttr) => typeImpl.GetNestedTypes(bindingAttr); |
| 97 | + public override Type GetNestedType(string name, BindingFlags bindingAttr) => typeImpl.GetNestedType(name, bindingAttr); |
| 98 | + public override MemberInfo[] GetMember(string name, MemberTypes type, BindingFlags bindingAttr) => typeImpl.GetMember(name, type, bindingAttr); |
| 99 | + public override MemberInfo[] GetMembers(BindingFlags bindingAttr) => typeImpl.GetMembers(bindingAttr); |
| 100 | + |
| 101 | + protected override TypeAttributes GetAttributeFlagsImpl() => typeImpl.Attributes; |
| 102 | + |
| 103 | + protected override bool IsArrayImpl() => typeImpl.IsArray; |
| 104 | + protected override bool IsPrimitiveImpl() => typeImpl.IsPrimitive; |
| 105 | + protected override bool IsByRefImpl() => typeImpl.IsByRef; |
| 106 | + protected override bool IsPointerImpl() => typeImpl.IsPointer; |
| 107 | + protected override bool IsValueTypeImpl() => typeImpl.IsValueType; |
| 108 | + protected override bool IsCOMObjectImpl() => typeImpl.IsCOMObject; |
| 109 | + public override bool IsConstructedGenericType => typeImpl.IsConstructedGenericType; |
| 110 | + public override Type GetElementType() => typeImpl.GetElementType(); |
| 111 | + protected override bool HasElementTypeImpl() => typeImpl.HasElementType; |
| 112 | + |
| 113 | + public override Type UnderlyingSystemType => typeImpl.UnderlyingSystemType; |
| 114 | + |
| 115 | + // ICustomAttributeProvider |
| 116 | + public override object[] GetCustomAttributes(bool inherit) => typeImpl.GetCustomAttributes(inherit); |
| 117 | + public override object[] GetCustomAttributes(Type attributeType, bool inherit) => typeImpl.GetCustomAttributes(attributeType, inherit); |
| 118 | + |
| 119 | + public override bool IsDefined(Type attributeType, bool inherit) => typeImpl.IsDefined(attributeType, inherit); |
| 120 | + public override InterfaceMapping GetInterfaceMap(Type interfaceType) => typeImpl.GetInterfaceMap(interfaceType); |
| 121 | + } |
| 122 | +} |
0 commit comments