本文整理汇总了C#中System.Reflection.RuntimeMethodInfo类的典型用法代码示例。如果您正苦于以下问题:C# RuntimeMethodInfo类的具体用法?C# RuntimeMethodInfo怎么用?C# RuntimeMethodInfo使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
RuntimeMethodInfo类属于System.Reflection命名空间,在下文中一共展示了RuntimeMethodInfo类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetCustomAttribute
internal static Attribute GetCustomAttribute(RuntimeMethodInfo method)
{
string str;
if ((method.Attributes & MethodAttributes.PinvokeImpl) == MethodAttributes.PrivateScope)
{
return null;
}
MetadataImport metadataImport = ModuleHandle.GetMetadataImport(method.Module.ModuleHandle.GetRuntimeModule());
string importDll = null;
int metadataToken = method.MetadataToken;
PInvokeAttributes bestFitUseAssem = PInvokeAttributes.BestFitUseAssem;
metadataImport.GetPInvokeMap(metadataToken, out bestFitUseAssem, out str, out importDll);
System.Runtime.InteropServices.CharSet none = System.Runtime.InteropServices.CharSet.None;
switch ((bestFitUseAssem & PInvokeAttributes.CharSetAuto))
{
case PInvokeAttributes.BestFitUseAssem:
none = System.Runtime.InteropServices.CharSet.None;
break;
case PInvokeAttributes.CharSetAnsi:
none = System.Runtime.InteropServices.CharSet.Ansi;
break;
case PInvokeAttributes.CharSetUnicode:
none = System.Runtime.InteropServices.CharSet.Unicode;
break;
case PInvokeAttributes.CharSetAuto:
none = System.Runtime.InteropServices.CharSet.Auto;
break;
}
System.Runtime.InteropServices.CallingConvention cdecl = System.Runtime.InteropServices.CallingConvention.Cdecl;
switch ((bestFitUseAssem & PInvokeAttributes.CallConvMask))
{
case PInvokeAttributes.CallConvStdcall:
cdecl = System.Runtime.InteropServices.CallingConvention.StdCall;
break;
case PInvokeAttributes.CallConvThiscall:
cdecl = System.Runtime.InteropServices.CallingConvention.ThisCall;
break;
case PInvokeAttributes.CallConvFastcall:
cdecl = System.Runtime.InteropServices.CallingConvention.FastCall;
break;
case PInvokeAttributes.CallConvWinapi:
cdecl = System.Runtime.InteropServices.CallingConvention.Winapi;
break;
case PInvokeAttributes.CallConvCdecl:
cdecl = System.Runtime.InteropServices.CallingConvention.Cdecl;
break;
}
bool exactSpelling = (bestFitUseAssem & PInvokeAttributes.NoMangle) != PInvokeAttributes.BestFitUseAssem;
bool setLastError = (bestFitUseAssem & PInvokeAttributes.SupportsLastError) != PInvokeAttributes.BestFitUseAssem;
bool bestFitMapping = (bestFitUseAssem & PInvokeAttributes.BestFitMask) == PInvokeAttributes.BestFitEnabled;
bool throwOnUnmappableChar = (bestFitUseAssem & PInvokeAttributes.ThrowOnUnmappableCharMask) == PInvokeAttributes.ThrowOnUnmappableCharEnabled;
return new DllImportAttribute(importDll, str, none, exactSpelling, setLastError, (method.GetMethodImplementationFlags() & MethodImplAttributes.PreserveSig) != MethodImplAttributes.IL, cdecl, bestFitMapping, throwOnUnmappableChar);
}
示例2: RuntimePropertyInfo
public RuntimePropertyInfo(Property property, RuntimeType declaringType, RuntimeMethodInfo getMethod, RuntimeMethodInfo setMethod)
{
_property = property;
_declaringType = declaringType;
_getMethod = getMethod;
_setMethod = setMethod;
}
示例3: GetCustomAttribute
internal static Attribute GetCustomAttribute(RuntimeMethodInfo method)
{
if ((method.GetMethodImplementationFlags() & MethodImplAttributes.PreserveSig) == MethodImplAttributes.IL)
{
return null;
}
return new PreserveSigAttribute();
}
示例4: IsDefined
[System.Security.SecuritySafeCritical] // auto-generated
internal static bool IsDefined(RuntimeMethodInfo method, RuntimeType caType, bool inherit)
{
Contract.Requires(method != null);
Contract.Requires(caType != null);
if (PseudoCustomAttribute.IsDefined(method, caType))
return true;
if (IsCustomAttributeDefined(method.GetRuntimeModule(), method.MetadataToken, caType))
return true;
if (!inherit)
return false;
method = method.GetParentDefinition();
while (method != null)
{
if (IsCustomAttributeDefined(method.GetRuntimeModule(), method.MetadataToken, caType, 0, inherit))
return true;
method = method.GetParentDefinition();
}
return false;
}
示例5: GetCustomAttributesInternal
[System.Security.SecuritySafeCritical] // auto-generated
internal static IList<CustomAttributeData> GetCustomAttributesInternal(RuntimeMethodInfo target)
{
Contract.Assert(target != null);
IList<CustomAttributeData> cad = GetCustomAttributes(target.GetRuntimeModule(), target.MetadataToken);
int pcaCount = 0;
Attribute[] a = PseudoCustomAttribute.GetCustomAttributes((RuntimeMethodInfo)target, typeof(object) as RuntimeType, true, out pcaCount);
if (pcaCount == 0)
return cad;
CustomAttributeData[] pca = new CustomAttributeData[cad.Count + pcaCount];
cad.CopyTo(pca, pcaCount);
for (int i = 0; i < pcaCount; i++)
{
pca[i] = new CustomAttributeData(a[i]);
}
return Array.AsReadOnly(pca);
}
示例6: CreateDelegateInternal
internal static Delegate CreateDelegateInternal(RuntimeType rtType, RuntimeMethodInfo rtMethod, Object firstArgument, DelegateBindingFlags flags, ref StackCrawlMark stackMark)
{
Contract.Assert((flags & DelegateBindingFlags.SkipSecurityChecks) == 0);
#if FEATURE_APPX
bool nonW8PMethod = (rtMethod.InvocationFlags & INVOCATION_FLAGS.INVOCATION_FLAGS_NON_W8P_FX_API) != 0;
bool nonW8PType = (rtType.InvocationFlags & INVOCATION_FLAGS.INVOCATION_FLAGS_NON_W8P_FX_API) != 0;
if (nonW8PMethod || nonW8PType)
{
RuntimeAssembly caller = RuntimeAssembly.GetExecutingAssembly(ref stackMark);
if (caller != null && !caller.IsSafeForReflection())
throw new InvalidOperationException(
Environment.GetResourceString("InvalidOperation_APIInvalidForCurrentContext",
nonW8PMethod ? rtMethod.FullName : rtType.FullName));
}
#endif
return UnsafeCreateDelegate(rtType, rtMethod, firstArgument, flags);
}
示例7: RemotingMethodCachedData
internal RemotingMethodCachedData(RuntimeMethodInfo ri) : base(ri)
{
}
示例8: AssignAssociates
[System.Security.SecurityCritical] // auto-generated
internal static unsafe void AssignAssociates(
MetadataImport scope,
int mdPropEvent,
RuntimeType declaringType,
RuntimeType reflectedType,
out RuntimeMethodInfo addOn,
out RuntimeMethodInfo removeOn,
out RuntimeMethodInfo fireOn,
out RuntimeMethodInfo getter,
out RuntimeMethodInfo setter,
out MethodInfo[] other,
out bool composedOfAllPrivateMethods,
out BindingFlags bindingFlags)
{
addOn = removeOn = fireOn = getter = setter = null;
Attributes attributes =
Attributes.ComposedOfAllPrivateMethods |
Attributes.ComposedOfAllVirtualMethods |
Attributes.ComposedOfNoPublicMembers |
Attributes.ComposedOfNoStaticMembers;
while(RuntimeTypeHandle.IsGenericVariable(reflectedType))
reflectedType = (RuntimeType)reflectedType.BaseType;
bool isInherited = declaringType != reflectedType;
List<MethodInfo> otherList = null;
MetadataEnumResult associatesData;
scope.Enum(MetadataTokenType.MethodDef, mdPropEvent, out associatesData);
int cAssociates = associatesData.Length / 2;
for (int i = 0; i < cAssociates; i++)
{
int methodDefToken = associatesData[i * 2];
MethodSemanticsAttributes semantics = (MethodSemanticsAttributes)associatesData[i * 2 + 1];
#region Assign each associate
RuntimeMethodInfo associateMethod =
AssignAssociates(methodDefToken, declaringType, reflectedType);
if (associateMethod == null)
continue;
MethodAttributes methAttr = associateMethod.Attributes;
bool isPrivate =(methAttr & MethodAttributes.MemberAccessMask) == MethodAttributes.Private;
bool isVirtual =(methAttr & MethodAttributes.Virtual) != 0;
MethodAttributes visibility = methAttr & MethodAttributes.MemberAccessMask;
bool isPublic = visibility == MethodAttributes.Public;
bool isStatic =(methAttr & MethodAttributes.Static) != 0;
if (isPublic)
{
attributes &= ~Attributes.ComposedOfNoPublicMembers;
attributes &= ~Attributes.ComposedOfAllPrivateMethods;
}
else if (!isPrivate)
{
attributes &= ~Attributes.ComposedOfAllPrivateMethods;
}
if (isStatic)
attributes &= ~Attributes.ComposedOfNoStaticMembers;
if (!isVirtual)
attributes &= ~Attributes.ComposedOfAllVirtualMethods;
#endregion
if (semantics == MethodSemanticsAttributes.Setter)
setter = associateMethod;
else if (semantics == MethodSemanticsAttributes.Getter)
getter = associateMethod;
else if (semantics == MethodSemanticsAttributes.Fire)
fireOn = associateMethod;
else if (semantics == MethodSemanticsAttributes.AddOn)
addOn = associateMethod;
else if (semantics == MethodSemanticsAttributes.RemoveOn)
removeOn = associateMethod;
else
{
if (otherList == null)
otherList = new List<MethodInfo>(cAssociates);
otherList.Add(associateMethod);
}
}
bool isPseudoPublic = (attributes & Attributes.ComposedOfNoPublicMembers) == 0;
bool isPseudoStatic = (attributes & Attributes.ComposedOfNoStaticMembers) == 0;
bindingFlags = RuntimeType.FilterPreCalculate(isPseudoPublic, isInherited, isPseudoStatic);
composedOfAllPrivateMethods =(attributes & Attributes.ComposedOfAllPrivateMethods) != 0;
other = (otherList != null) ? otherList.ToArray() : null;
}
示例9: UnsafeCreateDelegate
internal static Delegate UnsafeCreateDelegate(RuntimeType rtType, RuntimeMethodInfo rtMethod, Object firstArgument, DelegateBindingFlags flags)
{
Delegate d = InternalAlloc(rtType);
if (d.BindToMethodInfo(firstArgument, rtMethod, rtMethod.GetDeclaringTypeInternal(), flags))
return d;
else
return null;
}
示例10: GetCustomAttributes
internal static object[] GetCustomAttributes(RuntimeMethodInfo method, RuntimeType caType, bool inherit)
{
if (method.IsGenericMethod && !method.IsGenericMethodDefinition)
{
method = method.GetGenericMethodDefinition() as RuntimeMethodInfo;
}
int count = 0;
Attribute[] sourceArray = PseudoCustomAttribute.GetCustomAttributes(method, caType, true, out count);
if (!inherit || (caType.IsSealed && !GetAttributeUsage(caType).Inherited))
{
object[] objArray = GetCustomAttributes(method.Module, method.MetadataToken, count, caType);
if (count > 0)
{
Array.Copy(sourceArray, 0, objArray, objArray.Length - count, count);
}
return objArray;
}
List<object> derivedAttributes = new List<object>();
bool mustBeInheritable = false;
Type elementType = (((caType == null) || caType.IsValueType) || caType.ContainsGenericParameters) ? typeof(object) : caType;
while (count > 0)
{
derivedAttributes.Add(sourceArray[--count]);
}
while (method != null)
{
object[] objArray2 = GetCustomAttributes(method.Module, method.MetadataToken, 0, caType, mustBeInheritable, derivedAttributes);
mustBeInheritable = true;
for (int i = 0; i < objArray2.Length; i++)
{
derivedAttributes.Add(objArray2[i]);
}
method = method.GetParentDefinition() as RuntimeMethodInfo;
}
object[] destinationArray = Array.CreateInstance(elementType, derivedAttributes.Count) as object[];
Array.Copy(derivedAttributes.ToArray(), 0, destinationArray, 0, derivedAttributes.Count);
return destinationArray;
}
示例11: IsDefined
internal static bool IsDefined(RuntimeMethodInfo method, RuntimeType caType, bool inherit)
{
if (PseudoCustomAttribute.IsDefined(method, caType))
{
return true;
}
if (IsCustomAttributeDefined(method.Module, method.MetadataToken, caType))
{
return true;
}
if (inherit)
{
method = method.GetParentDefinition() as RuntimeMethodInfo;
while (method != null)
{
if (IsCustomAttributeDefined(method.Module, method.MetadataToken, caType, inherit))
{
return true;
}
method = method.GetParentDefinition() as RuntimeMethodInfo;
}
}
return false;
}
示例12: AssignAssociates
[System.Security.SecurityCritical] // auto-generated
internal static unsafe void AssignAssociates(
AssociateRecord* associates,
int cAssociates,
RuntimeType declaringType,
RuntimeType reflectedType,
out RuntimeMethodInfo addOn,
out RuntimeMethodInfo removeOn,
out RuntimeMethodInfo fireOn,
out RuntimeMethodInfo getter,
out RuntimeMethodInfo setter,
out MethodInfo[] other,
out bool composedOfAllPrivateMethods,
out BindingFlags bindingFlags)
{
addOn = removeOn = fireOn = getter = setter = null;
other = null;
Attributes attributes =
Attributes.ComposedOfAllPrivateMethods |
Attributes.ComposedOfAllVirtualMethods |
Attributes.ComposedOfNoPublicMembers |
Attributes.ComposedOfNoStaticMembers;
while(RuntimeTypeHandle.IsGenericVariable(reflectedType))
reflectedType = (RuntimeType)reflectedType.BaseType;
bool isInherited = declaringType != reflectedType;
List<MethodInfo> otherList = new List<MethodInfo>(cAssociates);
for (int i = 0; i < cAssociates; i++)
{
#region Assign each associate
RuntimeMethodInfo associateMethod =
AssignAssociates(associates[i].MethodDefToken, declaringType, reflectedType);
if (associateMethod == null)
continue;
MethodAttributes methAttr = associateMethod.Attributes;
bool isPrivate =(methAttr & MethodAttributes.MemberAccessMask) == MethodAttributes.Private;
bool isVirtual =(methAttr & MethodAttributes.Virtual) != 0;
MethodAttributes visibility = methAttr & MethodAttributes.MemberAccessMask;
bool isPublic = visibility == MethodAttributes.Public;
bool isStatic =(methAttr & MethodAttributes.Static) != 0;
if (isPublic)
{
attributes &= ~Attributes.ComposedOfNoPublicMembers;
attributes &= ~Attributes.ComposedOfAllPrivateMethods;
}
else if (!isPrivate)
{
attributes &= ~Attributes.ComposedOfAllPrivateMethods;
}
if (isStatic)
attributes &= ~Attributes.ComposedOfNoStaticMembers;
if (!isVirtual)
attributes &= ~Attributes.ComposedOfAllVirtualMethods;
#endregion
if (associates[i].Semantics == MethodSemanticsAttributes.Setter)
setter = associateMethod;
else if (associates[i].Semantics == MethodSemanticsAttributes.Getter)
getter = associateMethod;
else if (associates[i].Semantics == MethodSemanticsAttributes.Fire)
fireOn = associateMethod;
else if (associates[i].Semantics == MethodSemanticsAttributes.AddOn)
addOn = associateMethod;
else if (associates[i].Semantics == MethodSemanticsAttributes.RemoveOn)
removeOn = associateMethod;
else
otherList.Add(associateMethod);
}
bool isPseudoPublic = (attributes & Attributes.ComposedOfNoPublicMembers) == 0;
bool isPseudoStatic = (attributes & Attributes.ComposedOfNoStaticMembers) == 0;
bindingFlags = RuntimeType.FilterPreCalculate(isPseudoPublic, isInherited, isPseudoStatic);
composedOfAllPrivateMethods =(attributes & Attributes.ComposedOfAllPrivateMethods) != 0;
other = otherList.ToArray();
}
示例13: RemotingMethodCachedData
private int[] _marshalResponseMap = null; // map of parameters that should be marshaled out
internal RemotingMethodCachedData(RuntimeMethodInfo ri)
{
RI = ri;
}
示例14: IsDefined
[System.Security.SecuritySafeCritical] // auto-generated
internal static bool IsDefined(RuntimeMethodInfo method, RuntimeType caType, bool inherit)
{
Contract.Requires(method != null);
Contract.Requires(caType != null);
#if !FEATURE_CORECLR
if (FrameworkEventSource.IsInitialized && FrameworkEventSource.Log.IsEnabled(EventLevel.Informational, FrameworkEventSource.Keywords.DynamicTypeUsage) && caType != null)
{
FrameworkEventSource.Log.QueryAttributeIsDefined(caType.GetFullNameForEtw());
}
#endif
if (PseudoCustomAttribute.IsDefined(method, caType))
return true;
if (IsCustomAttributeDefined(method.GetRuntimeModule(), method.MetadataToken, caType))
return true;
if (!inherit)
return false;
method = method.GetParentDefinition();
while (method != null)
{
if (IsCustomAttributeDefined(method.GetRuntimeModule(), method.MetadataToken, caType, 0, inherit))
return true;
method = method.GetParentDefinition();
}
return false;
}
示例15: GetCustomAttributes
[System.Security.SecurityCritical] // auto-generated
internal static Object[] GetCustomAttributes(RuntimeMethodInfo method, RuntimeType caType, bool inherit)
{
Contract.Requires(method != null);
Contract.Requires(caType != null);
if (method.IsGenericMethod && !method.IsGenericMethodDefinition)
method = method.GetGenericMethodDefinition() as RuntimeMethodInfo;
int pcaCount = 0;
Attribute[] pca = PseudoCustomAttribute.GetCustomAttributes(method, caType, true, out pcaCount);
// if we are asked to go up the hierarchy chain we have to do it now and regardless of the
// attribute usage for the specific attribute because a derived attribute may override the usage...
// ... however if the attribute is sealed we can rely on the attribute usage
if (!inherit || (caType.IsSealed && !CustomAttribute.GetAttributeUsage(caType).Inherited))
{
object[] attributes = GetCustomAttributes(method.GetRuntimeModule(), method.MetadataToken, pcaCount, caType, !AllowCriticalCustomAttributes(method));
if (pcaCount > 0) Array.Copy(pca, 0, attributes, attributes.Length - pcaCount, pcaCount);
return attributes;
}
List<object> result = new List<object>();
bool mustBeInheritable = false;
bool useObjectArray = (caType == null || caType.IsValueType || caType.ContainsGenericParameters);
Type arrayType = useObjectArray ? typeof(object) : caType;
while (pcaCount > 0)
result.Add(pca[--pcaCount]);
while (method != null)
{
object[] attributes = GetCustomAttributes(method.GetRuntimeModule(), method.MetadataToken, 0, caType, mustBeInheritable, result, !AllowCriticalCustomAttributes(method));
mustBeInheritable = true;
for (int i = 0; i < attributes.Length; i++)
result.Add(attributes[i]);
method = method.GetParentDefinition();
}
object[] typedResult = CreateAttributeArrayHelper(arrayType, result.Count);
Array.Copy(result.ToArray(), 0, typedResult, 0, result.Count);
return typedResult;
}