Code:
/ Net / Net / 3.5.50727.3053 / DEVDIV / depot / DevDiv / releases / whidbey / netfxsp / ndp / clr / src / BCL / System / Reflection / XXXInfos.cs / 6 / XXXInfos.cs
// ==++==
//
// Copyright(c) Microsoft Corporation. All rights reserved.
//
// ==--==
using System;
using System.Reflection;
using System.Runtime.ConstrainedExecution;
using System.Globalization;
using System.Threading;
using System.Diagnostics;
using System.Security.Permissions;
using System.Collections;
using System.Runtime.CompilerServices;
using System.Security;
using System.Text;
using System.Reflection.Emit;
using System.Runtime.InteropServices;
using RuntimeTypeCache = System.RuntimeType.RuntimeTypeCache;
using CorElementType = System.Reflection.CorElementType;
using System.Runtime.Serialization;
using System.Reflection.Cache;
using MdToken = System.Reflection.MetadataToken;
namespace System.Reflection
{
[Serializable()]
[ClassInterface(ClassInterfaceType.None)]
[ComDefaultInterface(typeof(_MemberInfo))]
[PermissionSetAttribute(SecurityAction.InheritanceDemand, Name="FullTrust")]
[System.Runtime.InteropServices.ComVisible(true)]
public abstract class MemberInfo : ICustomAttributeProvider, _MemberInfo
{
#region Consts
//
// Invocation cached flags. Those are used in unmanaged code as well
// so be careful if you change them
//
internal const uint INVOCATION_FLAGS_UNKNOWN = 0x00000000;
internal const uint INVOCATION_FLAGS_INITIALIZED = 0x00000001;
// it's used for both method and field to signify that no access is allowed
internal const uint INVOCATION_FLAGS_NO_INVOKE = 0x00000002;
internal const uint INVOCATION_FLAGS_NEED_SECURITY = 0x00000004;
internal const uint INVOCATION_FLAGS_NO_CTOR_INVOKE = 0x00000008;
// because field and method are different we can reuse the same bits
// method
internal const uint INVOCATION_FLAGS_IS_CTOR = 0x00000010;
internal const uint INVOCATION_FLAGS_RISKY_METHOD = 0x00000020;
internal const uint INVOCATION_FLAGS_SECURITY_IMPOSED = 0x00000040;
internal const uint INVOCATION_FLAGS_IS_DELEGATE_CTOR = 0x00000080;
internal const uint INVOCATION_FLAGS_CONTAINS_STACK_POINTERS = 0x00000100;
// field
internal const uint INVOCATION_FLAGS_SPECIAL_FIELD = 0x00000010;
internal const uint INVOCATION_FLAGS_FIELD_SPECIAL_CAST = 0x00000020;
// temporary flag used for flagging invocation of method vs ctor
// this flag never appears on the instance m_invocationFlag and is simply
// passed down from within ConstructorInfo.Invoke()
internal const uint INVOCATION_FLAGS_CONSTRUCTOR_INVOKE = 0x10000000;
#endregion
#region Constructor
protected MemberInfo() {}
#endregion
#region Internal Methods
internal virtual bool CacheEquals(object o) { throw new NotImplementedException(); }
#endregion
#region Legacy Remoting Cache
// The size of CachedData is accounted for by BaseObjectWithCachedData in object.h.
// This member is currently being used by Remoting for caching remoting data. If you
// need to cache data here, talk to the Remoting team to work out a mechanism, so that
// both caching systems can happily work together.
private InternalCache m_cachedData;
internal InternalCache Cache
{
get
{
// This grabs an internal copy of m_cachedData and uses
// that instead of looking at m_cachedData directly because
// the cache may get cleared asynchronously. This prevents
// us from having to take a lock.
InternalCache cache = m_cachedData;
if (cache == null)
{
cache = new InternalCache("MemberInfo");
InternalCache ret = Interlocked.CompareExchange(ref m_cachedData, cache, null);
if (ret != null)
cache = ret;
GC.ClearCache += new ClearCacheHandler(OnCacheClear);
}
return cache;
}
}
internal void OnCacheClear(Object sender, ClearCacheEventArgs cacheEventArgs)
{
m_cachedData = null;
}
#endregion
#region Public Abstract\Virtual Members
public abstract MemberTypes MemberType { get; }
public abstract String Name { get; }
public abstract Type DeclaringType { get; }
public abstract Type ReflectedType { get; }
public abstract Object[] GetCustomAttributes(bool inherit);
public abstract Object[] GetCustomAttributes(Type attributeType, bool inherit);
public abstract bool IsDefined(Type attributeType, bool inherit);
public virtual int MetadataToken { get { throw new InvalidOperationException(); } }
internal virtual int MetadataTokenInternal { get { return MetadataToken; } }
public virtual Module Module
{
get
{
if (this is Type)
return((Type)this).Module;
throw new NotImplementedException();
}
}
// this method is required so Object.GetType is not made final virtual by the compiler
Type _MemberInfo.GetType() { return base.GetType(); }
#endregion
void _MemberInfo.GetTypeInfoCount(out uint pcTInfo)
{
throw new NotImplementedException();
}
void _MemberInfo.GetTypeInfo(uint iTInfo, uint lcid, IntPtr ppTInfo)
{
throw new NotImplementedException();
}
void _MemberInfo.GetIDsOfNames([In] ref Guid riid, IntPtr rgszNames, uint cNames, uint lcid, IntPtr rgDispId)
{
throw new NotImplementedException();
}
void _MemberInfo.Invoke(uint dispIdMember, [In] ref Guid riid, uint lcid, short wFlags, IntPtr pDispParams, IntPtr pVarResult, IntPtr pExcepInfo, IntPtr puArgErr)
{
throw new NotImplementedException();
}
}
[Serializable()]
[ClassInterface(ClassInterfaceType.None)]
[ComDefaultInterface(typeof(_MethodBase))]
[PermissionSetAttribute( SecurityAction.InheritanceDemand, Name="FullTrust" )]
[System.Runtime.InteropServices.ComVisible(true)]
public abstract class MethodBase : MemberInfo, _MethodBase
{
#region Static Members
public static MethodBase GetMethodFromHandle(RuntimeMethodHandle handle)
{
if (handle.IsNullHandle())
throw new ArgumentException(Environment.GetResourceString("Argument_InvalidHandle"));
MethodBase m = RuntimeType.GetMethodBase(handle);
if (m.DeclaringType != null && m.DeclaringType.IsGenericType)
throw new ArgumentException(String.Format(
CultureInfo.CurrentCulture, Environment.GetResourceString("Argument_MethodDeclaringTypeGeneric"),
m, m.DeclaringType.GetGenericTypeDefinition()));
return m;
}
[System.Runtime.InteropServices.ComVisible(false)]
public static MethodBase GetMethodFromHandle(RuntimeMethodHandle handle, RuntimeTypeHandle declaringType)
{
if (handle.IsNullHandle())
throw new ArgumentException(Environment.GetResourceString("Argument_InvalidHandle"));
return RuntimeType.GetMethodBase(declaringType, handle);
}
[DynamicSecurityMethod] // Specify DynamicSecurityMethod attribute to prevent inlining of the caller.
[MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var has to be marked non-inlineable
public static MethodBase GetCurrentMethod()
{
StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller;
return RuntimeMethodInfo.InternalGetCurrentMethod(ref stackMark);
}
#endregion
#region Constructor
protected MethodBase() { }
#endregion
#region Internal Members
internal virtual bool IsOverloaded { get { throw new NotSupportedException(Environment.GetResourceString("InvalidOperation_Method")); } }
internal virtual RuntimeMethodHandle GetMethodHandle() { return MethodHandle; }
#endregion
#region Public Abstract\Virtual Members
internal virtual Type GetReturnType() { throw new NotImplementedException(); }
internal virtual ParameterInfo[] GetParametersNoCopy() { return GetParameters (); }
public abstract ParameterInfo[] GetParameters();
public abstract MethodImplAttributes GetMethodImplementationFlags();
public abstract RuntimeMethodHandle MethodHandle { get; }
public abstract MethodAttributes Attributes { get; }
public abstract Object Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture);
public virtual CallingConventions CallingConvention { get { return CallingConventions.Standard; } }
[System.Runtime.InteropServices.ComVisible(true)]
public virtual Type[] GetGenericArguments() { throw new NotSupportedException(Environment.GetResourceString("NotSupported_SubclassOverride")); }
public virtual bool IsGenericMethodDefinition { get { return false; } }
public virtual bool ContainsGenericParameters { get { return false; } }
public virtual bool IsGenericMethod { get { return false; } }
#endregion
#region _MethodBase Implementation
Type _MethodBase.GetType() { return base.GetType(); }
bool _MethodBase.IsPublic { get { return IsPublic; } }
bool _MethodBase.IsPrivate { get { return IsPrivate; } }
bool _MethodBase.IsFamily { get { return IsFamily; } }
bool _MethodBase.IsAssembly { get { return IsAssembly; } }
bool _MethodBase.IsFamilyAndAssembly { get { return IsFamilyAndAssembly; } }
bool _MethodBase.IsFamilyOrAssembly { get { return IsFamilyOrAssembly; } }
bool _MethodBase.IsStatic { get { return IsStatic; } }
bool _MethodBase.IsFinal { get { return IsFinal; } }
bool _MethodBase.IsVirtual { get { return IsVirtual; } }
bool _MethodBase.IsHideBySig { get { return IsHideBySig; } }
bool _MethodBase.IsAbstract { get { return IsAbstract; } }
bool _MethodBase.IsSpecialName { get { return IsSpecialName; } }
bool _MethodBase.IsConstructor { get { return IsConstructor; } }
#endregion
#region Public Members
[DebuggerStepThroughAttribute]
[Diagnostics.DebuggerHidden]
public Object Invoke(Object obj, Object[] parameters)
{
return Invoke(obj,BindingFlags.Default,null,parameters,null);
}
public bool IsPublic { get { return(Attributes & MethodAttributes.MemberAccessMask) == MethodAttributes.Public; } }
public bool IsPrivate { get { return(Attributes & MethodAttributes.MemberAccessMask) == MethodAttributes.Private; } }
public bool IsFamily { get { return(Attributes & MethodAttributes.MemberAccessMask) == MethodAttributes.Family; } }
public bool IsAssembly { get { return(Attributes & MethodAttributes.MemberAccessMask) == MethodAttributes.Assembly; } }
public bool IsFamilyAndAssembly { get { return(Attributes & MethodAttributes.MemberAccessMask) == MethodAttributes.FamANDAssem; } }
public bool IsFamilyOrAssembly { get {return(Attributes & MethodAttributes.MemberAccessMask) == MethodAttributes.FamORAssem; } }
public bool IsStatic { get { return(Attributes & MethodAttributes.Static) != 0; } }
public bool IsFinal { get { return(Attributes & MethodAttributes.Final) != 0; }
}
public bool IsVirtual { get { return(Attributes & MethodAttributes.Virtual) != 0; }
}
public bool IsHideBySig { get { return(Attributes & MethodAttributes.HideBySig) != 0; } }
public bool IsAbstract { get { return(Attributes & MethodAttributes.Abstract) != 0; } }
public bool IsSpecialName { get { return(Attributes & MethodAttributes.SpecialName) != 0; } }
[System.Runtime.InteropServices.ComVisible(true)]
public bool IsConstructor
{
get
{
return((Attributes & MethodAttributes.RTSpecialName) != 0) &&
Name.Equals(ConstructorInfo.ConstructorName);
}
}
[ReflectionPermissionAttribute(SecurityAction.Demand, Flags=ReflectionPermissionFlag.MemberAccess)]
public virtual MethodBody GetMethodBody()
{
throw new InvalidOperationException();
}
#endregion
#region Private Invocation Helpers
[MethodImplAttribute(MethodImplOptions.InternalCall)]
static extern internal uint GetSpecialSecurityFlags(RuntimeMethodHandle method);
[MethodImplAttribute(MethodImplOptions.InternalCall)]
static extern internal void PerformSecurityCheck(Object obj, RuntimeMethodHandle method, IntPtr parent, uint invocationFlags);
#endregion
#region Internal Methods
internal virtual Type[] GetParameterTypes()
{
ParameterInfo[] paramInfo = GetParametersNoCopy();
Type[] parameterTypes = null;
parameterTypes = new Type[paramInfo.Length];
for (int i = 0; i < paramInfo.Length; i++)
parameterTypes[i] = paramInfo[i].ParameterType;
return parameterTypes;
}
virtual internal uint GetOneTimeFlags()
{
RuntimeMethodHandle handle = MethodHandle;
uint invocationFlags = 0;
Type declaringType = DeclaringType;
//
// first take care of all the NO_INVOKE cases.
if (
(ContainsGenericParameters) ||
(declaringType != null && declaringType.ContainsGenericParameters) ||
((CallingConvention & CallingConventions.VarArgs) == CallingConventions.VarArgs) ||
((Attributes & MethodAttributes.RequireSecObject) == MethodAttributes.RequireSecObject)
)
{
invocationFlags |= INVOCATION_FLAGS_NO_INVOKE;
}
else
{
// Non reflection-emit modules may not have AssemblyBuilderData. In that case, the module
// should be executable, so we don't place the NoInvoke bit on it.
AssemblyBuilderData data = Module.Assembly.m_assemblyData;
if (data != null)
{
// In order to execute a reflection-emit module, it must have the .Run bit set.
// This excludes both .Save, and .ReflectionOnly.
if ((data.m_access & AssemblyBuilderAccess.Run) == 0)
{
invocationFlags |= INVOCATION_FLAGS_NO_INVOKE;
}
}
}
// If the invocationFlags are still 0, then
// this should be an invocable method, determine the other flags that participate in invocation
if (invocationFlags == 0)
{
invocationFlags |= MethodBase.GetSpecialSecurityFlags(handle);
if ((invocationFlags & INVOCATION_FLAGS_NEED_SECURITY) == 0)
{
// determine whether the method needs security
if (
((Attributes & MethodAttributes.MemberAccessMask) != MethodAttributes.Public) ||
(declaringType != null && !declaringType.IsVisible)
)
invocationFlags |= INVOCATION_FLAGS_NEED_SECURITY;
else if (IsGenericMethod)
{
Type[] genericArguments = GetGenericArguments();
for (int i = 0; i < genericArguments.Length; i++)
{
if (!genericArguments[i].IsVisible)
{
invocationFlags |= INVOCATION_FLAGS_NEED_SECURITY;
break;
}
}
}
}
}
invocationFlags |= GetOneTimeSpecificFlags();
invocationFlags |= INVOCATION_FLAGS_INITIALIZED;
return invocationFlags;
}
// only ctors have special flags for now
internal virtual uint GetOneTimeSpecificFlags()
{
return 0;
}
internal Object[] CheckArguments(Object[] parameters, Binder binder,
BindingFlags invokeAttr, CultureInfo culture, Signature sig)
{
int actualCount = (parameters != null) ? parameters.Length : 0;
// copy the arguments in a different array so we detach from any user changes
Object[] copyOfParameters = new Object[actualCount];
ParameterInfo[] p = null;
for (int i = 0; i < actualCount; i++)
{
Object arg = parameters[i];
RuntimeTypeHandle argRTH = sig.Arguments[i];
if (arg == Type.Missing)
{
if (p == null)
p = GetParametersNoCopy();
if (p[i].DefaultValue == System.DBNull.Value)
throw new ArgumentException(Environment.GetResourceString("Arg_VarMissNull"),"parameters");
arg = p[i].DefaultValue;
}
if (argRTH.IsInstanceOfType(arg))
copyOfParameters[i] = arg;
else
copyOfParameters[i] = argRTH.GetRuntimeType().CheckValue(arg, binder, culture, invokeAttr);
}
return copyOfParameters;
}
#endregion
void _MethodBase.GetTypeInfoCount(out uint pcTInfo)
{
throw new NotImplementedException();
}
void _MethodBase.GetTypeInfo(uint iTInfo, uint lcid, IntPtr ppTInfo)
{
throw new NotImplementedException();
}
void _MethodBase.GetIDsOfNames([In] ref Guid riid, IntPtr rgszNames, uint cNames, uint lcid, IntPtr rgDispId)
{
throw new NotImplementedException();
}
void _MethodBase.Invoke(uint dispIdMember, [In] ref Guid riid, uint lcid, short wFlags, IntPtr pDispParams, IntPtr pVarResult, IntPtr pExcepInfo, IntPtr puArgErr)
{
throw new NotImplementedException();
}
}
[Serializable()]
[ClassInterface(ClassInterfaceType.None)]
[ComDefaultInterface(typeof(_ConstructorInfo))]
[PermissionSetAttribute( SecurityAction.InheritanceDemand, Name="FullTrust" )]
[System.Runtime.InteropServices.ComVisible(true)]
public abstract class ConstructorInfo : MethodBase, _ConstructorInfo
{
#region Static Members
[System.Runtime.InteropServices.ComVisible(true)]
public readonly static String ConstructorName = ".ctor";
[System.Runtime.InteropServices.ComVisible(true)]
public readonly static String TypeConstructorName = ".cctor";
#endregion
#region Constructor
protected ConstructorInfo() { }
#endregion
#region MemberInfo Overrides
[System.Runtime.InteropServices.ComVisible(true)]
public override MemberTypes MemberType { get { return System.Reflection.MemberTypes.Constructor; } }
#endregion
#region Public Abstract\Virtual Members
public abstract Object Invoke(BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture);
#endregion
#region Public Members
internal override Type GetReturnType() { return DeclaringType; }
[DebuggerStepThroughAttribute]
[Diagnostics.DebuggerHidden]
public Object Invoke(Object[] parameters)
{
return Invoke(BindingFlags.Default, null, parameters, null);
}
#endregion
#region COM Interop Support
Type _ConstructorInfo.GetType()
{
return base.GetType();
}
Object _ConstructorInfo.Invoke_2(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
{
return Invoke(obj, invokeAttr, binder, parameters, culture);
}
Object _ConstructorInfo.Invoke_3(Object obj, Object[] parameters)
{
return Invoke(obj, parameters);
}
Object _ConstructorInfo.Invoke_4(BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
{
return Invoke(invokeAttr, binder, parameters, culture);
}
Object _ConstructorInfo.Invoke_5(Object[] parameters)
{
return Invoke(parameters);
}
void _ConstructorInfo.GetTypeInfoCount(out uint pcTInfo)
{
throw new NotImplementedException();
}
void _ConstructorInfo.GetTypeInfo(uint iTInfo, uint lcid, IntPtr ppTInfo)
{
throw new NotImplementedException();
}
void _ConstructorInfo.GetIDsOfNames([In] ref Guid riid, IntPtr rgszNames, uint cNames, uint lcid, IntPtr rgDispId)
{
throw new NotImplementedException();
}
void _ConstructorInfo.Invoke(uint dispIdMember, [In] ref Guid riid, uint lcid, short wFlags, IntPtr pDispParams, IntPtr pVarResult, IntPtr pExcepInfo, IntPtr puArgErr)
{
throw new NotImplementedException();
}
#endregion
}
[Serializable()]
[ClassInterface(ClassInterfaceType.None)]
[ComDefaultInterface(typeof(_MethodInfo))]
[PermissionSetAttribute( SecurityAction.InheritanceDemand, Name="FullTrust" )]
[System.Runtime.InteropServices.ComVisible(true)]
public abstract class MethodInfo : MethodBase, _MethodInfo
{
#region Constructor
protected MethodInfo() { }
#endregion
#region MemberInfo Overrides
public override MemberTypes MemberType { get { return System.Reflection.MemberTypes.Method; } }
#endregion
#region Internal Members
internal virtual MethodInfo GetParentDefinition() { return null; }
#endregion
#region Public Abstract\Virtual Members
public virtual Type ReturnType { get { return GetReturnType(); } }
internal override Type GetReturnType() { return ReturnType; }
public virtual ParameterInfo ReturnParameter { get { throw new NotImplementedException(); } }
public abstract ICustomAttributeProvider ReturnTypeCustomAttributes { get; }
public abstract MethodInfo GetBaseDefinition();
[System.Runtime.InteropServices.ComVisible(true)]
public override Type[] GetGenericArguments() { throw new NotSupportedException(Environment.GetResourceString("NotSupported_SubclassOverride")); }
[System.Runtime.InteropServices.ComVisible(true)]
public virtual MethodInfo GetGenericMethodDefinition() { throw new NotSupportedException(Environment.GetResourceString("NotSupported_SubclassOverride")); }
public override bool IsGenericMethodDefinition { get { return false; } }
public override bool ContainsGenericParameters { get { return false; } }
public virtual MethodInfo MakeGenericMethod(params Type[] typeArguments) { throw new NotSupportedException(Environment.GetResourceString("NotSupported_SubclassOverride")); }
public override bool IsGenericMethod { get { return false; } }
#endregion
Type _MethodInfo.GetType()
{
return base.GetType();
}
void _MethodInfo.GetTypeInfoCount(out uint pcTInfo)
{
throw new NotImplementedException();
}
void _MethodInfo.GetTypeInfo(uint iTInfo, uint lcid, IntPtr ppTInfo)
{
throw new NotImplementedException();
}
void _MethodInfo.GetIDsOfNames([In] ref Guid riid, IntPtr rgszNames, uint cNames, uint lcid, IntPtr rgDispId)
{
throw new NotImplementedException();
}
void _MethodInfo.Invoke(uint dispIdMember, [In] ref Guid riid, uint lcid, short wFlags, IntPtr pDispParams, IntPtr pVarResult, IntPtr pExcepInfo, IntPtr puArgErr)
{
throw new NotImplementedException();
}
}
[Serializable()]
[ClassInterface(ClassInterfaceType.None)]
[ComDefaultInterface(typeof(_FieldInfo))]
[PermissionSetAttribute( SecurityAction.InheritanceDemand, Name="FullTrust" )]
[System.Runtime.InteropServices.ComVisible(true)]
public abstract class FieldInfo : MemberInfo, _FieldInfo
{
#region Static Members
public static FieldInfo GetFieldFromHandle(RuntimeFieldHandle handle)
{
if (handle.IsNullHandle())
throw new ArgumentException(Environment.GetResourceString("Argument_InvalidHandle"));
FieldInfo f = RuntimeType.GetFieldInfo(handle);
if (f.DeclaringType != null && f.DeclaringType.IsGenericType)
throw new ArgumentException(String.Format(
CultureInfo.CurrentCulture, Environment.GetResourceString("Argument_FieldDeclaringTypeGeneric"),
f.Name, f.DeclaringType.GetGenericTypeDefinition()));
return f;
}
[System.Runtime.InteropServices.ComVisible(false)]
public static FieldInfo GetFieldFromHandle(RuntimeFieldHandle handle, RuntimeTypeHandle declaringType)
{
if (handle.IsNullHandle())
throw new ArgumentException(Environment.GetResourceString("Argument_InvalidHandle"));
return RuntimeType.GetFieldInfo(declaringType, handle);
}
#endregion
#region Constructor
protected FieldInfo() { }
#endregion
#region MemberInfo Overrides
public override MemberTypes MemberType { get { return System.Reflection.MemberTypes.Field; } }
#endregion
#region Public Abstract\Virtual Members
public virtual Type[] GetRequiredCustomModifiers()
{
throw new NotImplementedException();
}
public virtual Type[] GetOptionalCustomModifiers()
{
throw new NotImplementedException();
}
[CLSCompliant(false)]
public virtual void SetValueDirect(TypedReference obj, Object value)
{
throw new NotSupportedException(Environment.GetResourceString("NotSupported_AbstractNonCLS"));
}
[CLSCompliant(false)]
public virtual Object GetValueDirect(TypedReference obj)
{
throw new NotSupportedException(Environment.GetResourceString("NotSupported_AbstractNonCLS"));
}
public abstract RuntimeFieldHandle FieldHandle { get; }
public abstract Type FieldType { get; }
public abstract Object GetValue(Object obj);
public virtual Object GetRawConstantValue() { throw new NotSupportedException(Environment.GetResourceString("NotSupported_AbstractNonCLS")); }
public abstract void SetValue(Object obj, Object value, BindingFlags invokeAttr, Binder binder, CultureInfo culture);
public abstract FieldAttributes Attributes { get; }
#endregion
#region Public Members
[DebuggerStepThroughAttribute]
[Diagnostics.DebuggerHidden]
public void SetValue(Object obj, Object value)
{
SetValue(obj, value, BindingFlags.Default, Type.DefaultBinder, null);
}
public bool IsPublic { get { return(Attributes & FieldAttributes.FieldAccessMask) == FieldAttributes.Public; } }
public bool IsPrivate { get { return(Attributes & FieldAttributes.FieldAccessMask) == FieldAttributes.Private; } }
public bool IsFamily { get { return(Attributes & FieldAttributes.FieldAccessMask) == FieldAttributes.Family; } }
public bool IsAssembly { get { return(Attributes & FieldAttributes.FieldAccessMask) == FieldAttributes.Assembly; } }
public bool IsFamilyAndAssembly { get { return(Attributes & FieldAttributes.FieldAccessMask) == FieldAttributes.FamANDAssem; } }
public bool IsFamilyOrAssembly { get { return(Attributes & FieldAttributes.FieldAccessMask) == FieldAttributes.FamORAssem; } }
public bool IsStatic { get { return(Attributes & FieldAttributes.Static) != 0; } }
public bool IsInitOnly { get { return(Attributes & FieldAttributes.InitOnly) != 0; } }
public bool IsLiteral { get { return(Attributes & FieldAttributes.Literal) != 0; } }
public bool IsNotSerialized { get { return(Attributes & FieldAttributes.NotSerialized) != 0; } }
public bool IsSpecialName { get { return(Attributes & FieldAttributes.SpecialName) != 0; } }
public bool IsPinvokeImpl { get { return(Attributes & FieldAttributes.PinvokeImpl) != 0; } }
#endregion
Type _FieldInfo.GetType()
{
return base.GetType();
}
void _FieldInfo.GetTypeInfoCount(out uint pcTInfo)
{
throw new NotImplementedException();
}
void _FieldInfo.GetTypeInfo(uint iTInfo, uint lcid, IntPtr ppTInfo)
{
throw new NotImplementedException();
}
void _FieldInfo.GetIDsOfNames([In] ref Guid riid, IntPtr rgszNames, uint cNames, uint lcid, IntPtr rgDispId)
{
throw new NotImplementedException();
}
void _FieldInfo.Invoke(uint dispIdMember, [In] ref Guid riid, uint lcid, short wFlags, IntPtr pDispParams, IntPtr pVarResult, IntPtr pExcepInfo, IntPtr puArgErr)
{
throw new NotImplementedException();
}
}
[Serializable()]
[ClassInterface(ClassInterfaceType.None)]
[ComDefaultInterface(typeof(_EventInfo))]
[PermissionSetAttribute( SecurityAction.InheritanceDemand, Name="FullTrust" )]
[System.Runtime.InteropServices.ComVisible(true)]
public abstract class EventInfo : MemberInfo, _EventInfo
{
#region Constructor
protected EventInfo() { }
#endregion
#region MemberInfo Overrides
public override MemberTypes MemberType { get { return MemberTypes.Event; } }
#endregion
#region Public Abstract\Virtual Members
public virtual MethodInfo[] GetOtherMethods(bool nonPublic)
{
throw new NotImplementedException();
}
public abstract MethodInfo GetAddMethod(bool nonPublic);
public abstract MethodInfo GetRemoveMethod(bool nonPublic);
public abstract MethodInfo GetRaiseMethod(bool nonPublic);
public abstract EventAttributes Attributes { get; }
#endregion
#region Public Members
public MethodInfo[] GetOtherMethods() { return GetOtherMethods(false); }
public MethodInfo GetAddMethod() { return GetAddMethod(false); }
public MethodInfo GetRemoveMethod() { return GetRemoveMethod(false); }
public MethodInfo GetRaiseMethod() { return GetRaiseMethod(false); }
[DebuggerStepThroughAttribute]
[Diagnostics.DebuggerHidden]
public void AddEventHandler(Object target, Delegate handler)
{
MethodInfo addMethod = GetAddMethod();
if (addMethod == null)
throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_NoPublicAddMethod"));
addMethod.Invoke(target, new object[] { handler });
}
[DebuggerStepThroughAttribute]
[Diagnostics.DebuggerHidden]
public void RemoveEventHandler(Object target, Delegate handler)
{
MethodInfo removeMethod = GetRemoveMethod();
if (removeMethod == null)
throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_NoPublicRemoveMethod"));
removeMethod.Invoke(target, new object[] { handler });
}
public Type EventHandlerType
{
get
{
MethodInfo m = GetAddMethod(true);
ParameterInfo[] p = m.GetParametersNoCopy();
Type del = typeof(Delegate);
for(int i = 0; i < p.Length; i++)
{
Type c = p[i].ParameterType;
if (c.IsSubclassOf(del))
return c;
}
return null;
}
}
public bool IsSpecialName
{
get
{
return(Attributes & EventAttributes.SpecialName) != 0;
}
}
public bool IsMulticast
{
get
{
Type cl = EventHandlerType;
Type mc = typeof(MulticastDelegate);
return mc.IsAssignableFrom(cl);
}
}
#endregion
Type _EventInfo.GetType()
{
return base.GetType();
}
void _EventInfo.GetTypeInfoCount(out uint pcTInfo)
{
throw new NotImplementedException();
}
void _EventInfo.GetTypeInfo(uint iTInfo, uint lcid, IntPtr ppTInfo)
{
throw new NotImplementedException();
}
void _EventInfo.GetIDsOfNames([In] ref Guid riid, IntPtr rgszNames, uint cNames, uint lcid, IntPtr rgDispId)
{
throw new NotImplementedException();
}
void _EventInfo.Invoke(uint dispIdMember, [In] ref Guid riid, uint lcid, short wFlags, IntPtr pDispParams, IntPtr pVarResult, IntPtr pExcepInfo, IntPtr puArgErr)
{
throw new NotImplementedException();
}
}
[Serializable()]
[ClassInterface(ClassInterfaceType.None)]
[ComDefaultInterface(typeof(_PropertyInfo))]
[PermissionSetAttribute( SecurityAction.InheritanceDemand, Name="FullTrust" )]
[System.Runtime.InteropServices.ComVisible(true)]
public abstract class PropertyInfo : MemberInfo, _PropertyInfo
{
#region Constructor
protected PropertyInfo() {}
#endregion
#region MemberInfo Overrides
public override MemberTypes MemberType { get { return System.Reflection.MemberTypes.Property; } }
#endregion
#region Public Abstract\Virtual Members
public virtual object GetConstantValue()
{
throw new NotImplementedException();
}
public virtual object GetRawConstantValue()
{
throw new NotImplementedException();
}
public abstract Type PropertyType { get; }
public abstract void SetValue(Object obj, Object value, BindingFlags invokeAttr, Binder binder, Object[] index, CultureInfo culture);
public abstract MethodInfo[] GetAccessors(bool nonPublic);
public abstract MethodInfo GetGetMethod(bool nonPublic);
public abstract MethodInfo GetSetMethod(bool nonPublic);
public abstract ParameterInfo[] GetIndexParameters();
public abstract PropertyAttributes Attributes { get; }
public abstract bool CanRead { get; }
public abstract bool CanWrite { get; }
[DebuggerStepThroughAttribute]
[Diagnostics.DebuggerHidden]
public virtual Object GetValue(Object obj,Object[] index)
{
return GetValue(obj, BindingFlags.Default, null, index, null);
}
public abstract Object GetValue(Object obj, BindingFlags invokeAttr, Binder binder, Object[] index, CultureInfo culture);
[DebuggerStepThroughAttribute]
[Diagnostics.DebuggerHidden]
public virtual void SetValue(Object obj, Object value, Object[] index)
{
SetValue(obj, value, BindingFlags.Default, null, index, null);
}
#endregion
#region Public Members
public virtual Type[] GetRequiredCustomModifiers() { return new Type[0]; }
public virtual Type[] GetOptionalCustomModifiers() { return new Type[0]; }
public MethodInfo[] GetAccessors() { return GetAccessors(false); }
public MethodInfo GetGetMethod() { return GetGetMethod(false); }
public MethodInfo GetSetMethod() { return GetSetMethod(false); }
public bool IsSpecialName { get { return(Attributes & PropertyAttributes.SpecialName) != 0; } }
#endregion
Type _PropertyInfo.GetType()
{
return base.GetType();
}
void _PropertyInfo.GetTypeInfoCount(out uint pcTInfo)
{
throw new NotImplementedException();
}
void _PropertyInfo.GetTypeInfo(uint iTInfo, uint lcid, IntPtr ppTInfo)
{
throw new NotImplementedException();
}
void _PropertyInfo.GetIDsOfNames([In] ref Guid riid, IntPtr rgszNames, uint cNames, uint lcid, IntPtr rgDispId)
{
throw new NotImplementedException();
}
void _PropertyInfo.Invoke(uint dispIdMember, [In] ref Guid riid, uint lcid, short wFlags, IntPtr pDispParams, IntPtr pVarResult, IntPtr pExcepInfo, IntPtr puArgErr)
{
throw new NotImplementedException();
}
}
}
namespace System.Reflection
{
internal enum MemberListType
{
All,
CaseSensitive,
CaseInsensitive,
HandleToInfo
}
[Serializable()]
internal sealed class RuntimeMethodInfo : MethodInfo, ISerializable
{
#region Static Members
internal static string ConstructParameters(ParameterInfo[] parameters, CallingConventions callingConvention)
{
Type[] parameterTypes = new Type[parameters.Length];
for(int i = 0; i < parameters.Length; i++)
parameterTypes[i] = parameters[i].ParameterType;
return ConstructParameters(parameterTypes, callingConvention);
}
internal static string ConstructParameters(Type[] parameters, CallingConventions callingConvention)
{
string toString = "";
string comma = "";
for(int i = 0; i < parameters.Length; i++)
{
Type t = parameters[i];
toString += comma;
toString += t.SigToString();
if (t.IsByRef)
{
toString = toString.TrimEnd(new char[] { '&' });
toString += " ByRef";
}
comma = ", ";
}
if ((callingConvention & CallingConventions.VarArgs) == CallingConventions.VarArgs)
{
toString += comma;
toString += "...";
}
return toString;
}
internal static string ConstructName(MethodBase mi)
{
// Serialization uses ToString to resolve MethodInfo overloads.
string toString = null;
toString += mi.Name;
RuntimeMethodInfo rmi = mi as RuntimeMethodInfo;
if (rmi != null && rmi.IsGenericMethod)
toString += rmi.m_handle.ConstructInstantiation();
toString += "(" + ConstructParameters(mi.GetParametersNoCopy(), mi.CallingConvention) + ")";
return toString;
}
#endregion
#region Private Data Members
private RuntimeMethodHandle m_handle;
private RuntimeTypeCache m_reflectedTypeCache;
private string m_name;
private string m_toString;
private ParameterInfo[] m_parameters;
private ParameterInfo m_returnParameter;
private BindingFlags m_bindingFlags;
private MethodAttributes m_methodAttributes;
private Signature m_signature;
private RuntimeType m_declaringType;
private uint m_invocationFlags;
#endregion
#region Constructor
internal RuntimeMethodInfo()
{
// Used for dummy head node during population
}
internal RuntimeMethodInfo(
RuntimeMethodHandle handle, RuntimeTypeHandle declaringTypeHandle,
RuntimeTypeCache reflectedTypeCache, MethodAttributes methodAttributes, BindingFlags bindingFlags)
{
ASSERT.PRECONDITION(!handle.IsNullHandle());
ASSERT.PRECONDITION(methodAttributes == handle.GetAttributes());
m_toString = null;
m_bindingFlags = bindingFlags;
m_handle = handle;
m_reflectedTypeCache = reflectedTypeCache;
m_parameters = null; // Created lazily when GetParameters() is called.
m_methodAttributes = methodAttributes;
m_declaringType = declaringTypeHandle.GetRuntimeType();
ASSERT.POSTCONDITION(!m_handle.IsNullHandle());
}
#endregion
#region Private Methods
private RuntimeTypeHandle ReflectedTypeHandle
{
get
{
return m_reflectedTypeCache.RuntimeTypeHandle;
}
}
internal ParameterInfo[] FetchNonReturnParameters()
{
if (m_parameters == null)
m_parameters = ParameterInfo.GetParameters(this, this, Signature);
return m_parameters;
}
internal ParameterInfo FetchReturnParameter()
{
if (m_returnParameter == null)
m_returnParameter = ParameterInfo.GetReturnParameter(this, this, Signature);
return m_returnParameter;
}
#endregion
#region Internal Members
[ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]
internal override bool CacheEquals(object o)
{
RuntimeMethodInfo m = o as RuntimeMethodInfo;
if (m == null)
return false;
return m.m_handle.Equals(m_handle);
}
internal Signature Signature
{
get
{
if (m_signature == null)
m_signature = new Signature(m_handle, m_declaringType.GetTypeHandleInternal());
return m_signature;
}
}
internal BindingFlags BindingFlags { get { return m_bindingFlags; } }
internal override RuntimeMethodHandle GetMethodHandle()
{
return m_handle;
}
internal override MethodInfo GetParentDefinition()
{
if (!IsVirtual || m_declaringType.IsInterface)
return null;
Type parent = m_declaringType.BaseType;
if (parent == null)
return null;
int slot = m_handle.GetSlot();
if (parent.GetTypeHandleInternal().GetNumVirtuals() <= slot)
return null;
return(MethodInfo)RuntimeType.GetMethodBase(parent.GetTypeHandleInternal(), parent.GetTypeHandleInternal().GetMethodAt(slot));
}
internal override uint GetOneTimeFlags()
{
uint invocationFlags = 0;
if (ReturnType.IsByRef)
invocationFlags = INVOCATION_FLAGS_NO_INVOKE;
invocationFlags |= base.GetOneTimeFlags();
return invocationFlags;
}
#endregion
#region Object Overrides
public override String ToString()
{
if (m_toString == null)
m_toString = ReturnType.SigToString() + " " + ConstructName(this);
return m_toString;
}
public override int GetHashCode()
{
return GetMethodHandle().GetHashCode();
}
public override bool Equals(object obj)
{
if (!IsGenericMethod)
return obj == this;
RuntimeMethodInfo mi = obj as RuntimeMethodInfo;
RuntimeMethodHandle handle1 = GetMethodHandle().StripMethodInstantiation();
RuntimeMethodHandle handle2 = mi.GetMethodHandle().StripMethodInstantiation();
if (handle1 != handle2)
return false;
if (mi == null || !mi.IsGenericMethod)
return false;
Type[] lhs = GetGenericArguments();
Type[] rhs = mi.GetGenericArguments();
if (lhs.Length != rhs.Length)
return false;
for (int i = 0; i < lhs.Length; i++)
{
if (lhs[i] != rhs[i])
return false;
}
if (mi.IsGenericMethod)
{
if (DeclaringType != mi.DeclaringType)
return false;
if (ReflectedType != mi.ReflectedType)
return false;
}
return true;
}
#endregion
#region ICustomAttributeProvider
public override Object[] GetCustomAttributes(bool inherit)
{
return CustomAttribute.GetCustomAttributes(this, typeof(object) as RuntimeType as RuntimeType, inherit);
}
public override Object[] GetCustomAttributes(Type attributeType, bool inherit)
{
if (attributeType == null)
throw new ArgumentNullException("attributeType");
RuntimeType attributeRuntimeType = attributeType.UnderlyingSystemType as RuntimeType;
if (attributeRuntimeType == null)
throw new ArgumentException(Environment.GetResourceString("Arg_MustBeType"),"attributeType");
return CustomAttribute.GetCustomAttributes(this, attributeRuntimeType, inherit);
}
public override bool IsDefined(Type attributeType, bool inherit)
{
if (attributeType == null)
throw new ArgumentNullException("attributeType");
RuntimeType attributeRuntimeType = attributeType.UnderlyingSystemType as RuntimeType;
if (attributeRuntimeType == null)
throw new ArgumentException(Environment.GetResourceString("Arg_MustBeType"),"attributeType");
return CustomAttribute.IsDefined(this, attributeRuntimeType, inherit);
}
#endregion
#region MemberInfo Overrides
public override String Name
{
get
{
if (m_name == null)
m_name = m_handle.GetName();
return m_name;
}
}
public override Type DeclaringType
{
get
{
if (m_reflectedTypeCache.IsGlobal)
return null;
return m_declaringType;
}
}
public override Type ReflectedType
{
get
{
if (m_reflectedTypeCache.IsGlobal)
return null;
return m_reflectedTypeCache.RuntimeType;
}
}
public override MemberTypes MemberType { get { return MemberTypes.Method; } }
public override int MetadataToken { get { return m_handle.GetMethodDef(); } }
public override Module Module { get { return m_declaringType.Module; } }
#endregion
#region MethodBase Overrides
internal override ParameterInfo[] GetParametersNoCopy()
{
FetchNonReturnParameters();
return m_parameters;
}
public override ParameterInfo[] GetParameters()
{
FetchNonReturnParameters();
if (m_parameters.Length == 0)
return m_parameters;
ParameterInfo[] ret = new ParameterInfo[m_parameters.Length];
Array.Copy(m_parameters, ret, m_parameters.Length);
return ret;
}
public override MethodImplAttributes GetMethodImplementationFlags()
{
return m_handle.GetImplAttributes();
}
internal override bool IsOverloaded
{
get
{
return m_reflectedTypeCache.GetMethodList(MemberListType.CaseSensitive, Name).Count > 1;
}
}
public override RuntimeMethodHandle MethodHandle
{
get
{
Type declaringType = DeclaringType;
if ((declaringType == null && Module.Assembly.ReflectionOnly) || declaringType is ReflectionOnlyType)
throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_NotAllowedInReflectionOnly"));
return m_handle;
}
}
public override MethodAttributes Attributes { get { return m_methodAttributes; } }
public override CallingConventions CallingConvention { get { return Signature.CallingConvention; } }
[ReflectionPermissionAttribute(SecurityAction.Demand, Flags = ReflectionPermissionFlag.MemberAccess)]
public override MethodBody GetMethodBody()
{
MethodBody mb = m_handle.GetMethodBody(ReflectedTypeHandle);
if (mb != null)
mb.m_methodBase = this;
return mb;
}
#endregion
#region Invocation Logic(On MemberBase)
private void CheckConsistency(Object target)
{
// only test instance methods
if ((m_methodAttributes & MethodAttributes.Static) != MethodAttributes.Static)
{
if (!m_declaringType.IsInstanceOfType(target))
{
if (target == null)
throw new TargetException(Environment.GetResourceString("RFLCT.Targ_StatMethReqTarg"));
else
throw new TargetException(Environment.GetResourceString("RFLCT.Targ_ITargMismatch"));
}
}
}
private void ThrowNoInvokeException()
{
// method is ReflectionOnly
Type declaringType = DeclaringType;
if ((declaringType == null && Module.Assembly.ReflectionOnly) || declaringType is ReflectionOnlyType)
throw new InvalidOperationException(Environment.GetResourceString("Arg_ReflectionOnlyInvoke"));
// method is on a class that contains stack pointers
if (DeclaringType.GetRootElementType() == typeof(ArgIterator))
throw new NotSupportedException();
// method is vararg
else if ((CallingConvention & CallingConventions.VarArgs) == CallingConventions.VarArgs)
throw new NotSupportedException();
// method is generic or on a generic class
else if (DeclaringType.ContainsGenericParameters || ContainsGenericParameters)
throw new InvalidOperationException(Environment.GetResourceString ("Arg_UnboundGenParam"));
// method is abstract class
else if (IsAbstract)
throw new MemberAccessException();
// ByRef return are not allowed in reflection
else if (ReturnType.IsByRef)
throw new NotSupportedException(Environment.GetResourceString("NotSupported_ByRefReturn"));
throw new TargetException();
}
[DebuggerStepThroughAttribute]
[Diagnostics.DebuggerHidden]
public override Object Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
{
return Invoke(obj, invokeAttr, binder, parameters, culture, false);
}
[DebuggerStepThroughAttribute]
[Diagnostics.DebuggerHidden]
internal object Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, bool skipVisibilityChecks)
{
// get the signature
int formalCount = Signature.Arguments.Length;
int actualCount =(parameters != null) ? parameters.Length : 0;
// set one time info for invocation
if ((m_invocationFlags & INVOCATION_FLAGS_INITIALIZED) == 0)
m_invocationFlags = GetOneTimeFlags();
if ((m_invocationFlags & INVOCATION_FLAGS_NO_INVOKE) != 0)
ThrowNoInvokeException();
// check basic method consistency. This call will throw if there are problems in the target/method relationship
CheckConsistency(obj);
if (formalCount != actualCount)
throw new TargetParameterCountException(Environment.GetResourceString("Arg_ParmCnt"));
// Don't allow more than 65535 parameters.
if (actualCount > UInt16.MaxValue)
throw new TargetParameterCountException(Environment.GetResourceString("NotSupported_TooManyArgs"));
if (!skipVisibilityChecks && (m_invocationFlags &(INVOCATION_FLAGS_RISKY_METHOD | INVOCATION_FLAGS_NEED_SECURITY)) != 0)
{
if ((m_invocationFlags & INVOCATION_FLAGS_RISKY_METHOD) != 0)
CodeAccessPermission.DemandInternal(PermissionType.ReflectionMemberAccess);
if ((m_invocationFlags & INVOCATION_FLAGS_NEED_SECURITY) != 0)
PerformSecurityCheck(obj, m_handle, m_declaringType.TypeHandle.Value, m_invocationFlags);
}
// if we are here we passed all the previous checks. Time to look at the arguments
RuntimeTypeHandle declaringTypeHandle = RuntimeTypeHandle.EmptyHandle;
if (!m_reflectedTypeCache.IsGlobal)
declaringTypeHandle = m_declaringType.TypeHandle;
if (actualCount == 0)
return m_handle.InvokeMethodFast(obj, null, Signature, m_methodAttributes, declaringTypeHandle);
Object[] arguments = CheckArguments(parameters, binder, invokeAttr, culture, Signature);
Object retValue = m_handle.InvokeMethodFast(obj, arguments, Signature, m_methodAttributes, declaringTypeHandle);
// copy out. This should be made only if ByRef are present.
for(int index = 0; index < actualCount; index++)
parameters[index] = arguments[index];
return retValue;
}
#endregion
#region MethodInfo Overrides
public override Type ReturnType
{
get { return Signature.ReturnTypeHandle.GetRuntimeType(); }
}
public override ICustomAttributeProvider ReturnTypeCustomAttributes
{
get { return ReturnParameter; }
}
public override ParameterInfo ReturnParameter
{
get
{
FetchReturnParameter();
ASSERT.POSTCONDITION(m_returnParameter != null);
return m_returnParameter as ParameterInfo;
}
}
public override MethodInfo GetBaseDefinition()
{
if (!IsVirtual || IsStatic || m_declaringType == null || m_declaringType.IsInterface)
return this;
int slot = m_handle.GetSlot();
Type declaringType = DeclaringType;
Type baseDeclaringType = DeclaringType;
RuntimeMethodHandle baseMethodHandle = default(RuntimeMethodHandle);
do {
RuntimeTypeHandle declaringTypeHandle = declaringType.GetTypeHandleInternal();
int cVtblSlots = declaringTypeHandle.GetNumVirtuals();
if (cVtblSlots <= slot)
break;
baseMethodHandle = declaringTypeHandle.GetMethodAt(slot);
baseDeclaringType = declaringType;
declaringType = declaringType.BaseType;
} while (declaringType != null);
return(MethodInfo)RuntimeType.GetMethodBase(baseDeclaringType.GetTypeHandleInternal(), baseMethodHandle);
}
#endregion
#region Generics
public override MethodInfo MakeGenericMethod(params Type[] methodInstantiation)
{
if (methodInstantiation == null)
throw new ArgumentNullException("methodInstantiation");
Type[] methodInstantiationCopy = new Type[methodInstantiation.Length];
for (int i = 0; i < methodInstantiation.Length; i ++)
methodInstantiationCopy[i] = methodInstantiation[i];
methodInstantiation = methodInstantiationCopy;
if (!IsGenericMethodDefinition)
throw new InvalidOperationException(
String.Format(CultureInfo.CurrentCulture, Environment.GetResourceString("Arg_NotGenericMethodDefinition"), this));
for (int i = 0; i < methodInstantiation.Length; i++)
{
if (methodInstantiation[i] == null)
throw new ArgumentNullException();
if (!(methodInstantiation[i] is RuntimeType))
return MethodBuilderInstantiation.MakeGenericMethod(this, methodInstantiation);
}
Type[] genericParameters = GetGenericArguments();
RuntimeType.SanityCheckGenericArguments(methodInstantiation, genericParameters);
RuntimeTypeHandle[] typeHandles = new RuntimeTypeHandle[methodInstantiation.Length];
for(int i = 0; i < methodInstantiation.Length; i++)
typeHandles[i] = methodInstantiation[i].GetTypeHandleInternal();
MethodInfo ret = null;
try
{
ret = RuntimeType.GetMethodBase(m_reflectedTypeCache.RuntimeTypeHandle,
m_handle.GetInstantiatingStub(m_declaringType.GetTypeHandleInternal(), typeHandles)) as MethodInfo;
}
catch (VerificationException e)
{
RuntimeType.ValidateGenericArguments(this, methodInstantiation, e);
throw e;
}
return ret;
}
public override Type[] GetGenericArguments()
{
RuntimeType[] rtypes = null;
RuntimeTypeHandle[] types = m_handle.GetMethodInstantiation();
if (types != null)
{
rtypes = new RuntimeType[types.Length];
for(int i = 0; i < types.Length; i++)
rtypes[i] = types[i].GetRuntimeType();
}
else
{
rtypes = new RuntimeType[0];
}
return rtypes;
}
public override MethodInfo GetGenericMethodDefinition()
{
if (!IsGenericMethod)
throw new InvalidOperationException();
return RuntimeType.GetMethodBase(m_declaringType.GetTypeHandleInternal(), m_handle.StripMethodInstantiation()) as MethodInfo;
}
public override bool IsGenericMethod { get { return m_handle.HasMethodInstantiation(); } }
public override bool IsGenericMethodDefinition { get { return m_handle.IsGenericMethodDefinition(); } }
public override bool ContainsGenericParameters
{
get
{
if (DeclaringType != null && DeclaringType.ContainsGenericParameters)
return true;
if (!IsGenericMethod)
return false;
Type[] pis = GetGenericArguments();
for (int i = 0; i < pis.Length; i++)
{
if (pis[i].ContainsGenericParameters)
return true;
}
return false;
}
}
#endregion
#region ISerializable Implementation
public void GetObjectData(SerializationInfo info, StreamingContext context)
{
if (info == null)
throw new ArgumentNullException("info");
if (m_reflectedTypeCache.IsGlobal)
throw new NotSupportedException(Environment.GetResourceString("NotSupported_GlobalMethodSerialization"));
MemberInfoSerializationHolder.GetSerializationInfo(
info, Name, ReflectedTypeHandle.GetRuntimeType(), ToString(), MemberTypes.Method,
IsGenericMethod & !IsGenericMethodDefinition ? GetGenericArguments() : null);
}
#endregion
#region Legacy Internal
internal static MethodBase InternalGetCurrentMethod(ref StackCrawlMark stackMark)
{
RuntimeMethodHandle method = RuntimeMethodHandle.GetCurrentMethod(ref stackMark);
if (method.IsNullHandle())
return null;
// If C.m was called, GetCurrentMethod returns C