本文整理汇总了C#中RuntimeTypeHandle类的典型用法代码示例。如果您正苦于以下问题:C# RuntimeTypeHandle类的具体用法?C# RuntimeTypeHandle怎么用?C# RuntimeTypeHandle使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
RuntimeTypeHandle类属于命名空间,在下文中一共展示了RuntimeTypeHandle类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: RunClassConstructor
public static void RunClassConstructor (RuntimeTypeHandle type)
{
if (type.Value == IntPtr.Zero)
throw new ArgumentException ("Handle is not initialized.", "type");
RunClassConstructor (type.Value);
}
示例2: TryGetGenericVirtualTargetForTypeAndSlot
public unsafe override sealed bool TryGetGenericVirtualTargetForTypeAndSlot(RuntimeTypeHandle targetHandle, ref RuntimeTypeHandle declaringType, RuntimeTypeHandle[] genericArguments, ref string methodName, ref IntPtr methodSignature, out IntPtr methodPointer, out IntPtr dictionaryPointer, out bool slotUpdated)
{
MethodNameAndSignature methodNameAndSignature = new MethodNameAndSignature(methodName, methodSignature);
#if REFLECTION_EXECUTION_TRACE
ReflectionExecutionLogger.WriteLine("GVM resolution starting for " + GetTypeNameDebug(declaringType) + "." + methodNameAndSignature.Name + "(...) on a target of type " + GetTypeNameDebug(targetHandle) + " ...");
#endif
if (RuntimeAugments.IsInterface(declaringType))
{
methodPointer = IntPtr.Zero;
dictionaryPointer = IntPtr.Zero;
slotUpdated = ResolveInterfaceGenericVirtualMethodSlot(targetHandle, ref declaringType, ref methodNameAndSignature);
methodName = methodNameAndSignature.Name;
methodSignature = methodNameAndSignature.Signature;
return slotUpdated;
}
else
{
slotUpdated = false;
return ResolveGenericVirtualMethodTarget(targetHandle, declaringType, genericArguments, methodNameAndSignature, out methodPointer, out dictionaryPointer);
}
}
示例3: FindMatchingInterfaceSlot
private bool FindMatchingInterfaceSlot(IntPtr moduleHandle, NativeReader nativeLayoutReader, ref NativeParser entryParser, ref ExternalReferencesTable extRefs, ref RuntimeTypeHandle declaringType, ref MethodNameAndSignature methodNameAndSignature, RuntimeTypeHandle openTargetTypeHandle, RuntimeTypeHandle[] targetTypeInstantiation, bool variantDispatch)
{
uint numTargetImplementations = entryParser.GetUnsigned();
for (uint j = 0; j < numTargetImplementations; j++)
{
uint nameAndSigToken = extRefs.GetRvaFromIndex(entryParser.GetUnsigned());
MethodNameAndSignature targetMethodNameAndSignature = GetMethodNameAndSignatureFromNativeReader(nativeLayoutReader, nameAndSigToken);
RuntimeTypeHandle targetTypeHandle = extRefs.GetRuntimeTypeHandleFromIndex(entryParser.GetUnsigned());
#if REFLECTION_EXECUTION_TRACE
ReflectionExecutionLogger.WriteLine(" Searching for GVM implementation on targe type = " + GetTypeNameDebug(targetTypeHandle));
#endif
uint numIfaceImpls = entryParser.GetUnsigned();
for (uint k = 0; k < numIfaceImpls; k++)
{
RuntimeTypeHandle implementingTypeHandle = extRefs.GetRuntimeTypeHandleFromIndex(entryParser.GetUnsigned());
uint numIfaceSigs = entryParser.GetUnsigned();
if (!openTargetTypeHandle.Equals(implementingTypeHandle))
{
// Skip over signatures data
for (uint l = 0; l < numIfaceSigs; l++)
entryParser.GetUnsigned();
continue;
}
for (uint l = 0; l < numIfaceSigs; l++)
{
RuntimeTypeHandle currentIfaceTypeHandle = default(RuntimeTypeHandle);
NativeParser ifaceSigParser = new NativeParser(nativeLayoutReader, extRefs.GetRvaFromIndex(entryParser.GetUnsigned()));
IntPtr currentIfaceSigPtr = ifaceSigParser.Reader.OffsetToAddress(ifaceSigParser.Offset);
if (TypeLoaderEnvironment.Instance.GetTypeFromSignatureAndContext(currentIfaceSigPtr, targetTypeInstantiation, null, out currentIfaceTypeHandle, out currentIfaceSigPtr))
{
Debug.Assert(!currentIfaceTypeHandle.IsNull());
if ((!variantDispatch && declaringType.Equals(currentIfaceTypeHandle)) ||
(variantDispatch && RuntimeAugments.IsAssignableFrom(declaringType, currentIfaceTypeHandle)))
{
#if REFLECTION_EXECUTION_TRACE
ReflectionExecutionLogger.WriteLine(" " + (declaringType.Equals(currentIfaceTypeHandle) ? "Exact" : "Variant-compatible") + " match found on this target type!");
#endif
// We found the GVM slot target for the input interface GVM call, so let's update the interface GVM slot and return success to the caller
declaringType = targetTypeHandle;
methodNameAndSignature = targetMethodNameAndSignature;
return true;
}
}
}
}
}
return false;
}
示例4: GetTypeFromHandle
public static RuntimeType GetTypeFromHandle(RuntimeTypeHandle handle)
{
// handle is really a vtable
VTable vtable = var.Cast<RuntimeTypeHandle>(handle).Cast<VTable>();
return GetTypeFromClass(vtable.Class);
}
示例5: SyntheticMethodInvoker
public SyntheticMethodInvoker(RuntimeTypeHandle thisType, RuntimeTypeHandle[] parameterTypes, InvokerOptions options, Func<Object, Object[], Object> invoker)
{
_invoker = invoker;
_options = options;
_thisType = thisType;
_parameterTypes = parameterTypes;
}
示例6: CreateDelegate
public override Delegate CreateDelegate(RuntimeTypeHandle delegateType, Object target, bool isStatic, bool isVirtual, bool isOpen)
{
return RuntimeAugments.CreateDelegate(
delegateType,
MethodInvokeInfo.LdFtnResult,
target,
isStatic: isStatic,
isOpen: isOpen);
}
示例7: WriteJsonValueCore
public override void WriteJsonValueCore(XmlWriterDelegator jsonWriter, object obj, XmlObjectSerializerWriteContextComplexJson context, RuntimeTypeHandle declaredTypeHandle)
{
DataContractSerializer dataContractSerializer = new DataContractSerializer(Type.GetTypeFromHandle(declaredTypeHandle),
GetKnownTypesFromContext(context, (context == null) ? null : context.SerializerKnownTypeList), 1, false, false); // maxItemsInObjectGraph // ignoreExtensionDataObject // preserveObjectReferences
MemoryStream memoryStream = new MemoryStream();
dataContractSerializer.WriteObject(memoryStream, obj);
memoryStream.Position = 0;
string serialized = new StreamReader(memoryStream).ReadToEnd();
jsonWriter.WriteString(serialized);
}
示例8: WriteJsonValueCore
public override void WriteJsonValueCore(XmlWriterDelegator jsonWriter, object obj, XmlObjectSerializerWriteContextComplexJson context, RuntimeTypeHandle declaredTypeHandle)
{
if (IsULong)
{
jsonWriter.WriteUnsignedLong(((IConvertible)obj).ToUInt64(null));
}
else
{
jsonWriter.WriteLong(((IConvertible)obj).ToInt64(null));
}
}
示例9: CreateMethodInvoker
//
// Creates the appropriate flavor of Invoker depending on the calling convention "shape" (static, instance or virtual.)
//
internal static MethodInvoker CreateMethodInvoker(MetadataReader reader, RuntimeTypeHandle declaringTypeHandle, MethodHandle methodHandle, MethodInvokeInfo methodInvokeInfo)
{
Method method = methodHandle.GetMethod(reader);
MethodAttributes methodAttributes = method.Flags;
if (0 != (methodAttributes & MethodAttributes.Static))
return new StaticMethodInvoker(methodInvokeInfo);
else if (methodInvokeInfo.VirtualResolveData != IntPtr.Zero)
return new VirtualMethodInvoker(methodInvokeInfo, declaringTypeHandle);
else
return new InstanceMethodInvoker(methodInvokeInfo, declaringTypeHandle);
}
示例10: NullableInstanceMethodInvoker
public NullableInstanceMethodInvoker(MetadataReader reader, MethodHandle methodHandle, RuntimeTypeHandle nullableTypeHandle, MethodInvokeInfo methodInvokeInfo)
{
_id = NullableMethodId.None;
_nullableTypeHandle = nullableTypeHandle;
Method method = methodHandle.GetMethod(reader);
if (MethodAttributes.Public == (method.Flags & MethodAttributes.MemberAccessMask))
{
// Note: Since we control the definition of Nullable<>, we're not checking signatures here.
String name = method.Name.GetConstantStringValue(reader).Value;
switch (name)
{
case "GetType":
_id = NullableMethodId.GetType;
break;
case "ToString":
_id = NullableMethodId.ToString;
break;
case "Equals":
_id = NullableMethodId.Equals;
break;
case "GetHashCode":
_id = NullableMethodId.GetHashCode;
break;
case ".ctor":
_id = NullableMethodId.Ctor;
break;
case "get_HasValue":
_id = NullableMethodId.get_HasValue;
break;
case "get_Value":
_id = NullableMethodId.get_Value;
break;
case "GetValueOrDefault":
IEnumerator<ParameterTypeSignatureHandle> parameters = method.Signature.GetMethodSignature(reader).Parameters.GetEnumerator();
if (parameters.MoveNext())
_id = NullableMethodId.GetValueOrDefault_1;
else
_id = NullableMethodId.GetValueOrDefault_0;
break;
default:
break;
}
}
}
示例11: RunClassConstructor
public static void RunClassConstructor(RuntimeTypeHandle type)
{
if (type.IsNull)
throw new ArgumentException(SR.InvalidOperation_HandleIsNotInitialized);
IntPtr pStaticClassConstructionContext = RuntimeAugments.Callbacks.TryGetStaticClassConstructionContext(type);
if (pStaticClassConstructionContext == IntPtr.Zero)
return;
unsafe
{
ClassConstructorRunner.EnsureClassConstructorRun((StaticClassConstructionContext*)pStaticClassConstructionContext);
}
}
示例12: InternalDeserialize
internal override object InternalDeserialize(XmlReaderDelegator xmlReader, int declaredTypeID, RuntimeTypeHandle declaredTypeHandle, string name, string ns)
{
if (_mode == SerializationMode.SharedContract)
{
if (_serializationSurrogateProvider == null)
return base.InternalDeserialize(xmlReader, declaredTypeID, declaredTypeHandle, name, ns);
else
return InternalDeserializeWithSurrogate(xmlReader, Type.GetTypeFromHandle(declaredTypeHandle), null /*surrogateDataContract*/, name, ns);
}
else
{
return InternalDeserializeInSharedTypeMode(xmlReader, declaredTypeID, Type.GetTypeFromHandle(declaredTypeHandle), name, ns);
}
}
示例13: TryGetConstructedGenericTypeComponents
public static bool TryGetConstructedGenericTypeComponents(RuntimeTypeHandle runtimeTypeHandle, out RuntimeTypeHandle genericTypeDefinitionHandle, out RuntimeTypeHandle[] genericTypeArgumentHandles)
{
genericTypeDefinitionHandle = default(RuntimeTypeHandle);
genericTypeArgumentHandles = null;
// Check the regular tables first.
if (ReflectionExecution.ExecutionEnvironment.TryGetConstructedGenericTypeComponents(runtimeTypeHandle, out genericTypeDefinitionHandle, out genericTypeArgumentHandles))
return true;
// Now check the diagnostic tables.
if (ReflectionExecution.ExecutionEnvironment.TryGetConstructedGenericTypeComponentsDiag(runtimeTypeHandle, out genericTypeDefinitionHandle, out genericTypeArgumentHandles))
return true;
return false;
}
示例14: CreateDelegate
public override sealed Delegate CreateDelegate(RuntimeTypeHandle delegateType, Object target, bool isStatic, bool isVirtual, bool isOpen)
{
if (isOpen)
{
return RuntimeAugments.CreateDelegate(
delegateType,
new OpenMethodResolver(_declaringTypeHandle, MethodInvokeInfo.LdFtnResult, 0).ToIntPtr(),
target,
isStatic: isStatic,
isOpen: isOpen);
}
else
{
return base.CreateDelegate(delegateType, target, isStatic, isVirtual, isOpen);
}
}
示例15: ValidateThis
public static void ValidateThis(Object thisObject, RuntimeTypeHandle declaringTypeHandle)
{
if (thisObject == null)
throw new TargetException(SR.RFLCT_Targ_StatMethReqTarg);
RuntimeTypeHandle srcTypeHandle = thisObject.GetType().TypeHandle;
if (RuntimeAugments.IsAssignableFrom(declaringTypeHandle, srcTypeHandle))
return;
if (RuntimeAugments.IsInterface(declaringTypeHandle))
{
if (RuntimeAugments.IsInstanceOfInterface(thisObject, declaringTypeHandle))
return;
}
throw new TargetException(SR.RFLCT_Targ_ITargMismatch);
}