本文整理汇总了C#中System.RuntimeTypeHandle.GetRuntimeType方法的典型用法代码示例。如果您正苦于以下问题:C# RuntimeTypeHandle.GetRuntimeType方法的具体用法?C# RuntimeTypeHandle.GetRuntimeType怎么用?C# RuntimeTypeHandle.GetRuntimeType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.RuntimeTypeHandle
的用法示例。
在下文中一共展示了RuntimeTypeHandle.GetRuntimeType方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetNextArg
public TypedReference GetNextArg(RuntimeTypeHandle rth)
{
if (sigPtr != IntPtr.Zero)
{
// This is an ordinary ArgIterator capable of determining
// types from a signature. Just do a regular GetNextArg.
return GetNextArg();
}
else
{
// Prevent abuse of this API with a default ArgIterator (it
// doesn't require permission to create a zero-inited value
// type). Check that ArgPtr isn't zero or this API will allow a
// malicious caller to increment the pointer to an arbitrary
// location in memory and read the contents.
if (ArgPtr == IntPtr.Zero)
throw new ArgumentNullException();
TypedReference result = new TypedReference ();
// reference to TypedReference is banned, so have to pass result as pointer
unsafe
{
InternalGetNextArg(&result, rth.GetRuntimeType());
}
return result;
}
}
示例2: AssignAssociates
internal static RuntimeMethodInfo AssignAssociates(int tkMethod, RuntimeTypeHandle declaredTypeHandle, RuntimeTypeHandle reflectedTypeHandle)
{
if (MetadataToken.IsNullToken(tkMethod))
{
return null;
}
bool flag = !declaredTypeHandle.Equals(reflectedTypeHandle);
RuntimeMethodHandle methodHandle = declaredTypeHandle.GetModuleHandle().ResolveMethodHandle(tkMethod, declaredTypeHandle.GetInstantiation(), new RuntimeTypeHandle[0]);
MethodAttributes attributes = methodHandle.GetAttributes();
bool flag2 = (attributes & MethodAttributes.MemberAccessMask) == MethodAttributes.Private;
bool flag3 = (attributes & MethodAttributes.Virtual) != MethodAttributes.PrivateScope;
if (flag)
{
if (flag2)
{
return null;
}
if (flag3 && ((declaredTypeHandle.GetAttributes() & TypeAttributes.ClassSemanticsMask) == TypeAttributes.AnsiClass))
{
int slot = methodHandle.GetSlot();
methodHandle = reflectedTypeHandle.GetMethodAt(slot);
}
}
MethodAttributes attributes2 = attributes & MethodAttributes.MemberAccessMask;
RuntimeMethodInfo methodBase = RuntimeType.GetMethodBase(reflectedTypeHandle, methodHandle) as RuntimeMethodInfo;
if (methodBase == null)
{
methodBase = reflectedTypeHandle.GetRuntimeType().Module.ResolveMethod(tkMethod, null, null) as RuntimeMethodInfo;
}
return methodBase;
}
示例3: GetFieldFromHandle
public static FieldInfo GetFieldFromHandle(RuntimeFieldHandle handle, RuntimeTypeHandle declaringType)
{
if (handle.IsNullHandle())
throw new ArgumentException(Environment.GetResourceString("Argument_InvalidHandle"));
return RuntimeType.GetFieldInfo(declaringType.GetRuntimeType(), handle.GetRuntimeFieldInfo());
}
示例4: RuntimeConstructorInfo
internal RuntimeConstructorInfo(RuntimeMethodHandle handle, RuntimeTypeHandle declaringTypeHandle, RuntimeType.RuntimeTypeCache reflectedTypeCache, MethodAttributes methodAttributes, System.Reflection.BindingFlags bindingFlags)
{
this.m_bindingFlags = bindingFlags;
this.m_handle = handle;
this.m_reflectedTypeCache = reflectedTypeCache;
this.m_declaringType = declaringTypeHandle.GetRuntimeType();
this.m_parameters = null;
this.m_toString = null;
this.m_methodAttributes = methodAttributes;
}
示例5: GetNextArg
public unsafe TypedReference GetNextArg(RuntimeTypeHandle rth)
{
if (this.sigPtr != IntPtr.Zero)
{
return this.GetNextArg();
}
if (this.ArgPtr == IntPtr.Zero)
{
throw new ArgumentNullException();
}
TypedReference result = default(TypedReference);
this.InternalGetNextArg((void*)(&result), rth.GetRuntimeType());
return result;
}
示例6: GetTypeHelper
internal unsafe static IntPtr GetTypeHelper(IntPtr th, IntPtr pGenericArgs, int cGenericArgs, IntPtr pModifiers, int cModifiers)
{
RuntimeTypeHandle typeHandle = new RuntimeTypeHandle(th.ToPointer());
Type type = typeHandle.GetRuntimeType();
if (type == null)
return th;
if (cGenericArgs > 0)
{
Type[] genericArgs = new Type[cGenericArgs];
void** arGenericArgs = (void**)pGenericArgs.ToPointer();
for (int i = 0; i < genericArgs.Length; i++)
{
RuntimeTypeHandle genericArg = new RuntimeTypeHandle((void*)Marshal.ReadIntPtr((IntPtr)arGenericArgs, i * sizeof(void*)));
genericArgs[i] = Type.GetTypeFromHandle(genericArg);
if (genericArgs[i] == null)
return (IntPtr)0;
}
type = type.MakeGenericType(genericArgs);
}
if (cModifiers > 0)
{
int* arModifiers = (int*)pModifiers.ToPointer();
for(int i = 0; i < cModifiers; i++)
{
if ((CorElementType)Marshal.ReadInt32((IntPtr)arModifiers, i * sizeof(int)) == CorElementType.Ptr)
type = type.MakePointerType();
else if ((CorElementType)Marshal.ReadInt32((IntPtr)arModifiers, i * sizeof(int)) == CorElementType.ByRef)
type = type.MakeByRefType();
else if ((CorElementType)Marshal.ReadInt32((IntPtr)arModifiers, i * sizeof(int)) == CorElementType.SzArray)
type = type.MakeArrayType();
else
type = type.MakeArrayType(Marshal.ReadInt32((IntPtr)arModifiers, ++i * sizeof(int)));
}
}
return type.GetTypeHandleInternal().Value;
}
示例7: GetFieldFromHandle
public static FieldInfo GetFieldFromHandle(RuntimeFieldHandle handle, RuntimeTypeHandle declaringType)
{
if (handle.IsNullHandle())
throw new ArgumentException(Environment.GetResourceString("Argument_InvalidHandle"));
#if !FEATURE_CORECLR
if (FrameworkEventSource.IsInitialized && FrameworkEventSource.Log.IsEnabled(EventLevel.Informational, FrameworkEventSource.Keywords.DynamicTypeUsage))
{
FrameworkEventSource.Log.BeginGetFieldFromHandle();
}
#endif
FieldInfo f = RuntimeType.GetFieldInfo(declaringType.GetRuntimeType(), handle.GetRuntimeFieldInfo());
#if !FEATURE_CORECLR
if (FrameworkEventSource.IsInitialized && FrameworkEventSource.Log.IsEnabled(EventLevel.Informational, FrameworkEventSource.Keywords.DynamicTypeUsage) && declaringType != null && f != null)
{
FrameworkEventSource.Log.EndGetFieldFromHandle(declaringType.GetRuntimeType().GetFullNameForEtw(), f.GetFullNameForEtw());
}
#endif
return f;
}
示例8: GetMethodFromHandle
public static MethodBase GetMethodFromHandle(RuntimeMethodHandle handle, RuntimeTypeHandle declaringType)
{
if (handle.IsNullHandle())
throw new ArgumentException(Environment.GetResourceString("Argument_InvalidHandle"));
#if MONO
MethodBase m = GetMethodFromHandleInternalType (handle.Value, declaringType.Value);
if (m == null)
throw new ArgumentException ("The handle is invalid.");
return m;
#else
return RuntimeType.GetMethodBase(declaringType.GetRuntimeType(), handle.GetMethodInfo());
#endif
}
示例9: RunClassConstructor
public static void RunClassConstructor(RuntimeTypeHandle type)
{
_RunClassConstructor(type.GetRuntimeType());
}
示例10: MdFieldInfo
internal MdFieldInfo(
int tkField, FieldAttributes fieldAttributes, RuntimeTypeHandle declaringTypeHandle, RuntimeTypeCache reflectedTypeCache, BindingFlags bindingFlags)
: base(reflectedTypeCache, declaringTypeHandle.GetRuntimeType(), bindingFlags)
{
m_tkField = tkField;
m_name = null;
m_fieldAttributes = fieldAttributes;
}
示例11: AssignAssociates
internal static unsafe RuntimeMethodInfo AssignAssociates(
int tkMethod,
RuntimeTypeHandle declaredTypeHandle,
RuntimeTypeHandle reflectedTypeHandle)
{
if (MetadataToken.IsNullToken(tkMethod))
return null;
ASSERT.PRECONDITION(!declaredTypeHandle.IsNullHandle());
ASSERT.PRECONDITION(!reflectedTypeHandle.IsNullHandle());
bool isInherited = !declaredTypeHandle.Equals(reflectedTypeHandle);
RuntimeMethodHandle associateMethodHandle = declaredTypeHandle.GetModuleHandle().ResolveMethodHandle(tkMethod, declaredTypeHandle.GetInstantiation(), new RuntimeTypeHandle[0]);
//RuntimeMethodHandle associateMethodHandle = declaredTypeHandle.GetMethodFromToken(tkMethod);
ASSERT.CONSISTENCY_CHECK(!associateMethodHandle.IsNullHandle(), "Failed to resolve associateRecord methodDef token");
MethodAttributes methAttr = associateMethodHandle.GetAttributes();
bool isPrivate =(methAttr & MethodAttributes.MemberAccessMask) == MethodAttributes.Private;
bool isVirtual =(methAttr & MethodAttributes.Virtual) != 0;
if (isInherited)
{
// ECMA MethodSemantics: "All methods for a given Property or Event shall have the same accessibility
//(ie the MemberAccessMask subfield of their Flags row) and cannot be CompilerControlled [CLS]"
// Consequently, a property may be composed of public and private methods. If the declared type !=
// the reflected type, the private methods should not be exposed. Note that this implies that the
// identity of a property includes it's reflected type.
if (isPrivate)
return null;
// Note this is the first time the property was encountered walking from the most derived class
// towards the base class. It would seem to follow that any associated methods would not
// be overriden -- but this is not necessarily true. A more derived class may have overriden a
// virtual method associated with a property in a base class without associating the override with
// the same or any property in the derived class.
if (isVirtual)
{
bool declaringTypeIsClass =
(declaredTypeHandle.GetAttributes() & TypeAttributes.ClassSemanticsMask) == TypeAttributes.Class;
ASSERT.CONSISTENCY_CHECK(LOGIC.BIJECTION(declaringTypeIsClass,
(reflectedTypeHandle.GetAttributes() & TypeAttributes.ClassSemanticsMask) == TypeAttributes.Class));
// It makes no sense to search for a virtual override of a method declared on an interface.
if (declaringTypeIsClass)
{
int slot = associateMethodHandle.GetSlot();
// Find the override visible from the reflected type
associateMethodHandle = reflectedTypeHandle.GetMethodAt(slot);
}
}
}
MethodAttributes visibility = methAttr & MethodAttributes.MemberAccessMask;
bool isPublic = visibility == MethodAttributes.Public;
bool isNonProtectedInternal = visibility == MethodAttributes.Assembly;
bool isStatic =(methAttr & MethodAttributes.Static) != 0;
RuntimeMethodInfo associateMethod =
RuntimeType.GetMethodBase(reflectedTypeHandle, associateMethodHandle) as RuntimeMethodInfo;
// suppose a property was mapped to a method not in the derivation hierarchy of the reflectedTypeHandle
if (associateMethod == null)
associateMethod = reflectedTypeHandle.GetRuntimeType().Module.ResolveMethod(tkMethod, null, null) as RuntimeMethodInfo;
return associateMethod;
}
示例12: GetValue
[System.Security.SecurityCritical] // auto-generated
public static unsafe Object GetValue(MetadataImport scope, int token, RuntimeTypeHandle fieldTypeHandle, bool raw)
{
CorElementType corElementType = 0;
long buffer = 0;
int length;
String stringVal;
stringVal = scope.GetDefaultValue(token, out buffer, out length, out corElementType);
RuntimeType fieldType = fieldTypeHandle.GetRuntimeType();
if (fieldType.IsEnum && raw == false)
{
long defaultValue = 0;
switch (corElementType)
{
#region Switch
case CorElementType.Void:
return DBNull.Value;
case CorElementType.Char:
defaultValue = *(char*)&buffer;
break;
case CorElementType.I1:
defaultValue = *(sbyte*)&buffer;
break;
case CorElementType.U1:
defaultValue = *(byte*)&buffer;
break;
case CorElementType.I2:
defaultValue = *(short*)&buffer;
break;
case CorElementType.U2:
defaultValue = *(ushort*)&buffer;
break;
case CorElementType.I4:
defaultValue = *(int*)&buffer;
break;
case CorElementType.U4:
defaultValue = *(uint*)&buffer;
break;
case CorElementType.I8:
defaultValue = buffer;
break;
case CorElementType.U8:
defaultValue = buffer;
break;
default:
throw new FormatException(Environment.GetResourceString("Arg_BadLiteralFormat"));
#endregion
}
return RuntimeType.CreateEnum(fieldType, defaultValue);
}
else if (fieldType == typeof(DateTime))
{
long defaultValue = 0;
switch (corElementType)
{
#region Switch
case CorElementType.Void:
return DBNull.Value;
case CorElementType.I8:
defaultValue = buffer;
break;
case CorElementType.U8:
defaultValue = buffer;
break;
default:
throw new FormatException(Environment.GetResourceString("Arg_BadLiteralFormat"));
#endregion
}
return new DateTime(defaultValue);
}
else
{
switch (corElementType)
{
#region Switch
case CorElementType.Void:
return DBNull.Value;
//.........这里部分代码省略.........
示例13: GetValue
public static unsafe object GetValue(MetadataImport scope, int token, RuntimeTypeHandle fieldTypeHandle, bool raw)
{
int num2;
long num4;
CorElementType end = CorElementType.End;
long num = 0L;
string str = scope.GetDefaultValue(token, out num, out num2, out end);
RuntimeType runtimeType = fieldTypeHandle.GetRuntimeType();
if (!runtimeType.IsEnum || raw)
{
if (runtimeType == typeof(DateTime))
{
num4 = 0L;
switch (end)
{
case CorElementType.I8:
num4 = num;
goto Label_0129;
case CorElementType.U8:
num4 = num;
goto Label_0129;
case CorElementType.Void:
return DBNull.Value;
}
throw new FormatException(Environment.GetResourceString("Arg_BadLiteralFormat"));
}
switch (end)
{
case CorElementType.Void:
return DBNull.Value;
case CorElementType.Boolean:
return (*(((int*) &num)) != 0);
case CorElementType.Char:
return (char) *(((ushort*) &num));
case CorElementType.I1:
return *(((sbyte*) &num));
case CorElementType.U1:
return *(((byte*) &num));
case CorElementType.I2:
return *(((short*) &num));
case CorElementType.U2:
return *(((ushort*) &num));
case CorElementType.I4:
return *(((int*) &num));
case CorElementType.U4:
return *(((uint*) &num));
case CorElementType.I8:
return num;
case CorElementType.U8:
return (ulong) num;
case CorElementType.R4:
return *(((float*) &num));
case CorElementType.R8:
return *(((double*) &num));
case CorElementType.String:
if (str == null)
{
return string.Empty;
}
return str;
case CorElementType.Class:
return null;
}
throw new FormatException(Environment.GetResourceString("Arg_BadLiteralFormat"));
}
long num3 = 0L;
switch (end)
{
case CorElementType.Void:
return DBNull.Value;
case CorElementType.Char:
num3 = *((ushort*) &num);
break;
case CorElementType.I1:
num3 = *((sbyte*) &num);
break;
case CorElementType.U1:
num3 = *((byte*) &num);
break;
case CorElementType.I2:
//.........这里部分代码省略.........
示例14: GetMethodFromHandle
public static MethodBase GetMethodFromHandle(RuntimeMethodHandle handle, RuntimeTypeHandle declaringType)
{
if (handle.IsNullHandle())
{
throw new ArgumentException(Environment.GetResourceString("Argument_InvalidHandle"));
}
return RuntimeType.GetMethodBase(declaringType.GetRuntimeType(), handle.GetMethodInfo());
}
示例15: GetMethodFromHandle
public static MethodBase GetMethodFromHandle(RuntimeMethodHandle handle, RuntimeTypeHandle declaringType)
{
if (handle.IsNullHandle())
throw new ArgumentException(Environment.GetResourceString("Argument_InvalidHandle"));
#if !FEATURE_CORECLR && !MONO
if (FrameworkEventSource.IsInitialized && FrameworkEventSource.Log.IsEnabled(EventLevel.Informational, FrameworkEventSource.Keywords.DynamicTypeUsage))
{
FrameworkEventSource.Log.BeginGetMethodFromHandle();
}
#endif
#if MONO
MethodBase m = GetMethodFromHandleInternalType (handle.Value, declaringType.Value);
if (m == null)
throw new ArgumentException ("The handle is invalid.");
#else
MethodBase m = RuntimeType.GetMethodBase(declaringType.GetRuntimeType(), handle.GetMethodInfo());
#endif
#if !FEATURE_CORECLR && !MONO
if (FrameworkEventSource.IsInitialized && FrameworkEventSource.Log.IsEnabled(EventLevel.Informational, FrameworkEventSource.Keywords.DynamicTypeUsage) && declaringType != null && m != null)
{
FrameworkEventSource.Log.EndGetMethodFromHandle(declaringType.GetRuntimeType().GetFullNameForEtw(), m.GetFullNameForEtw());
}
#endif
return m;
}