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;
        }
        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);
            }
        }
Beispiel #3
0
        public static RuntimeType GetTypeFromHandle(RuntimeTypeHandle handle)
        {
            // handle is really a vtable
            VTable vtable = var.Cast<RuntimeTypeHandle>(handle).Cast<VTable>();

            return GetTypeFromClass(vtable.Class);
        }
		public static void RunClassConstructor (RuntimeTypeHandle type)
		{
			if (type.Value == IntPtr.Zero)
				throw new ArgumentException ("Handle is not initialized.", "type");

			RunClassConstructor (type.Value);
		}
 public SyntheticMethodInvoker(RuntimeTypeHandle thisType, RuntimeTypeHandle[] parameterTypes, InvokerOptions options, Func<Object, Object[], Object> invoker)
 {
     _invoker = invoker;
     _options = options;
     _thisType = thisType;
     _parameterTypes = parameterTypes;
 }
 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);
 }
 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));
     }
 }
        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);
        }
 //
 // 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);
 }
        /// <summary>
        /// Initializes a new instance of ClrEnumType class with properties from the CLR type.
        /// </summary>
        /// <param name="clrType">The CLR type to construct from.</param>
        /// <param name="cspaceNamespaceName">CSpace namespace name.</param>
        /// <param name="cspaceTypeName">CSpace type name.</param>
        internal ClrEnumType(Type clrType, string cspaceNamespaceName, string cspaceTypeName)
            : base(clrType)
        {
            Debug.Assert(clrType != null, "clrType != null");
            Debug.Assert(clrType.IsEnum, "enum type expected");
            Debug.Assert(
                !String.IsNullOrEmpty(cspaceNamespaceName) && !String.IsNullOrEmpty(cspaceTypeName),
                "Mapping information must never be null");

            _type = clrType.TypeHandle;
            _cspaceTypeName = cspaceNamespaceName + "." + cspaceTypeName;
        }
        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;
                }
            }
        }
        /// <summary>
        /// Initializes a new instance of Complex Type with properties from the type.
        /// </summary>
        /// <param name="type">The CLR type to construct from</param>
        internal ClrEntityType(Type type, string cspaceNamespaceName, string cspaceTypeName)
            : base(EntityUtil.GenericCheckArgumentNull(type, "type").Name, type.Namespace ?? string.Empty,
                DataSpace.OSpace)
        {
            Debug.Assert(
                !String.IsNullOrEmpty(cspaceNamespaceName) &&
                !String.IsNullOrEmpty(cspaceTypeName), "Mapping information must never be null");

            _type = type.TypeHandle;
            _cspaceNamespaceName = cspaceNamespaceName;
            _cspaceTypeName = cspaceNamespaceName + "." + cspaceTypeName;
            Abstract = type.IsAbstract;
        }
 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);
     }
 }
Beispiel #14
0
        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);
            }
        }
        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;
        }
        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);
        }
 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);
     }
 }
        /// <summary>
        /// Initializes a new OSpace instance of the property class
        /// </summary>
        /// <param name="name">name of the property</param>
        /// <param name="typeUsage">TypeUsage object containing the property type and its facets</param>
        /// <param name="propertyInfo">for the property</param>
        /// <param name="entityDeclaringType">The declaring type of the entity containing the property</param>
        internal EdmProperty(string name, TypeUsage typeUsage, PropertyInfo propertyInfo, RuntimeTypeHandle entityDeclaringType)
            : this(name, typeUsage)
        {
            Debug.Assert(name == propertyInfo.Name, "different PropertyName");
            if (null != propertyInfo)
            {
                MethodInfo method;

                method = propertyInfo.GetGetMethod(true); // return public or non-public getter
                PropertyGetterHandle = ((null != method) ? method.MethodHandle : default(RuntimeMethodHandle));

                method = propertyInfo.GetSetMethod(true); // return public or non-public getter
                PropertySetterHandle = ((null != method) ? method.MethodHandle : default(RuntimeMethodHandle));

                EntityDeclaringType = entityDeclaringType;
            }
        }
        //
        // This overload of GetMethodHandle can handle all method handles.
        //
        public sealed override MethodBase GetMethodFromHandle(RuntimeMethodHandle runtimeMethodHandle, RuntimeTypeHandle declaringTypeHandle)
        {
            ExecutionEnvironment executionEnvironment = ReflectionCoreExecution.ExecutionEnvironment;
            MethodHandle methodHandle;
            RuntimeTypeHandle[] genericMethodTypeArgumentHandles;
            if (!executionEnvironment.TryGetMethodFromHandleAndType(runtimeMethodHandle, declaringTypeHandle, out methodHandle, out genericMethodTypeArgumentHandles))
            {
                // This may be a method declared on a non-generic type: this api accepts that too so try the other table.
                RuntimeTypeHandle actualDeclaringTypeHandle;
                if (!executionEnvironment.TryGetMethodFromHandle(runtimeMethodHandle, out actualDeclaringTypeHandle, out methodHandle, out genericMethodTypeArgumentHandles))
                    throw new ArgumentException(SR.Argument_InvalidHandle);
                if (!actualDeclaringTypeHandle.Equals(declaringTypeHandle))
                    throw new ArgumentException(SR.Format(SR.Argument_ResolveMethodHandle,
                        ReflectionCoreNonPortable.GetTypeForRuntimeTypeHandle(declaringTypeHandle),
                        ReflectionCoreNonPortable.GetTypeForRuntimeTypeHandle(actualDeclaringTypeHandle)));
            }

            MethodBase methodBase = ReflectionCoreExecution.ExecutionDomain.GetMethod(declaringTypeHandle, methodHandle, genericMethodTypeArgumentHandles);
            return methodBase;
        }
        // Get the diagnostic name string for a type. This attempts to reformat the string into something that is essentially human readable.
        //  Returns true if the function is successful.
        //  runtimeTypeHandle represents the type to get a name for
        //  diagnosticName is the name that is returned
        //
        // the genericParameterOffsets list is an optional parameter that contains the list of the locations of where generic parameters may be inserted
        // to make the string represent an instantiated generic.
        //
        // For example for Dictionary<K,V>, metadata names the type Dictionary`2, but this function will return Dictionary<,>
        // For consumers of this function that will be inserting generic arguments, the genericParameterOffsets list is used to find where to insert the generic parameter name.
        //
        // That isn't all that interesting for Dictionary, but it becomes substantially more interesting for nested generic types, or types which are compiler named as
        // those may contain embedded <> pairs and such.
        public static bool TryGetDiagnosticStringForNamedType(RuntimeTypeHandle runtimeTypeHandle, out String diagnosticName, List<int> genericParameterOffsets)
        {
            diagnosticName = null;
            ExecutionEnvironmentImplementation executionEnvironment = ReflectionExecution.ExecutionEnvironment;

            MetadataReader reader;
            TypeReferenceHandle typeReferenceHandle;
            if (executionEnvironment.TryGetTypeReferenceForNamedType(runtimeTypeHandle, out reader, out typeReferenceHandle))
            {
                diagnosticName = GetTypeFullNameFromTypeRef(typeReferenceHandle, reader, genericParameterOffsets);
                return true;
            }

            TypeDefinitionHandle typeDefinitionHandle;
            if (executionEnvironment.TryGetMetadataForNamedType(runtimeTypeHandle, out reader, out typeDefinitionHandle))
            {
                diagnosticName = GetTypeFullNameFromTypeDef(typeDefinitionHandle, reader, genericParameterOffsets);
                return true;
            }
            return false;
        }
Beispiel #21
0
    public static int Main(String[] args)
    {
        Type t = typeof(int);
        Type t2 = typeof(long);

        RuntimeTypeHandle th = t.TypeHandle;
        RuntimeTypeHandle th2 = t2.TypeHandle;

        Console.WriteLine(th.Equals(th2));
        Console.WriteLine(th.Equals(th));

        RuntimeTypeHandle[] arr = new RuntimeTypeHandle[2];
        arr[0] = t.TypeHandle;
        arr[1] = t2.TypeHandle;

        if (arr[0].Equals(arr[1]))
        {
            Console.WriteLine("ERR");
            return 0;
        }
        return 100;
    }
Beispiel #22
0
        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 Object supports ICastable interface and the declaringType is interface
            // try to call ICastable.IsInstanceOfInterface to determine whether object suppport declaringType interface
            if (RuntimeAugments.IsInterface(declaringTypeHandle))
            {
                ICastable castable = thisObject as ICastable;
                Exception castError;

                // ICastable.IsInstanceOfInterface isn't supposed to throw exception
                if (castable != null && castable.IsInstanceOfInterface(declaringTypeHandle, out castError))
                    return;
            }

            throw new TargetException(SR.RFLCT_Targ_ITargMismatch);
        }
Beispiel #23
0
 public override sealed Delegate CreateDelegate(RuntimeTypeHandle delegateType, Object target, bool isStatic, bool isVirtual, bool isOpen)
 {
     if (!isOpen)
     {
         // We're creating a delegate to a virtual override of this method, so resolve the virtual now.
         IntPtr resolvedVirtual = OpenMethodResolver.ResolveMethod(MethodInvokeInfo.VirtualResolveData, target);
         return RuntimeAugments.CreateDelegate(
                         delegateType,
                         resolvedVirtual,
                         target,
                         isStatic: false,
                         isOpen: isOpen);
     }
     else
     {
         // Create an open virtual method by providing the virtual resolver to the delegate type.
         return RuntimeAugments.CreateDelegate(
             delegateType,
             MethodInvokeInfo.VirtualResolveData,
             target,
             isStatic: false,
             isOpen: isOpen);
     }
 }
 public abstract IntPtr TryGetStaticClassConstructionContext(RuntimeTypeHandle runtimeTypeHandle);
 public abstract Type GetByRefTypeForHandle(RuntimeTypeHandle typeHandle);
Beispiel #26
0
 public abstract Delegate CreateDelegate(RuntimeTypeHandle delegateType, Object target, bool isStatic, bool isVirtual, bool isOpen);
Beispiel #27
0
 public virtual void InternalSerialize(XmlWriterDelegator xmlWriter, object obj, bool isDeclaredType, bool writeXsiType, int declaredTypeID, RuntimeTypeHandle declaredTypeHandle)
 {
     if (writeXsiType)
     {
         Type declaredType = Globals.TypeOfObject;
         SerializeWithXsiType(xmlWriter, obj, Type.GetTypeHandle(obj), null /*type*/, -1, declaredType.TypeHandle, declaredType);
     }
     else if (isDeclaredType)
     {
         DataContract contract = GetDataContract(declaredTypeID, declaredTypeHandle);
         SerializeWithoutXsiType(contract, xmlWriter, obj, declaredTypeHandle);
     }
     else
     {
         RuntimeTypeHandle objTypeHandle = Type.GetTypeHandle(obj);
         if (declaredTypeHandle.Equals(objTypeHandle))
         {
             DataContract dataContract = (declaredTypeID >= 0)
                 ? GetDataContract(declaredTypeID, declaredTypeHandle)
                 : GetDataContract(declaredTypeHandle, null /*type*/);
             SerializeWithoutXsiType(dataContract, xmlWriter, obj, declaredTypeHandle);
         }
         else
         {
             SerializeWithXsiType(xmlWriter, obj, objTypeHandle, null /*type*/, declaredTypeID, declaredTypeHandle, Type.GetTypeFromHandle(declaredTypeHandle));
         }
     }
 }
Beispiel #28
0
        internal virtual void SerializeWithXsiTypeAtTopLevel(DataContract dataContract, XmlWriterDelegator xmlWriter, object obj, RuntimeTypeHandle originalDeclaredTypeHandle, Type graphType)
        {
            bool verifyKnownType = false;
            Type declaredType    = rootTypeDataContract.OriginalUnderlyingType;

            if (declaredType.IsInterface && CollectionDataContract.IsCollectionInterface(declaredType))
            {
                if (DataContractResolver != null)
                {
                    WriteResolvedTypeInfo(xmlWriter, graphType, declaredType);
                }
            }
            else if (!declaredType.IsArray) //Array covariance is not supported in XSD. If declared type is array do not write xsi:type. Instead write xsi:type for each item
            {
                verifyKnownType = WriteTypeInfo(xmlWriter, dataContract, rootTypeDataContract);
            }
            SerializeAndVerifyType(dataContract, xmlWriter, obj, verifyKnownType, originalDeclaredTypeHandle, declaredType);
        }
 public abstract string GetBetterDiagnosticInfoIfAvailable(RuntimeTypeHandle runtimeTypeHandle);
Beispiel #30
0
 public PhpValue Evaluate(Context ctx, PhpArray locals, object @this, RuntimeTypeHandle self)
 {
     return(_entryPoint(ctx, locals, @this, self));
 }
 public abstract Type GetArrayTypeForHandle(RuntimeTypeHandle typeHandle);
 internal static MissingMetadataException Create(RuntimeTypeHandle pertainant)
 {
     return CreateFromMetadataObject(SR.Reflection_InsufficientMetadata_EdbNeeded, pertainant);
 }
Beispiel #33
0
 /// <summary>
 /// Gets a <see cref="T:System.Reflection.MethodBase"/> object for the constructor or method represented by the specified handle, for the specified generic type.
 /// </summary>
 /// 
 /// <returns>
 /// A <see cref="T:System.Reflection.MethodBase"/> object representing the method or constructor specified by <paramref name="handle"/>, in the generic type specified by <paramref name="declaringType"/>.
 /// </returns>
 /// <param name="handle">A handle to the internal metadata representation of a constructor or method.</param><param name="declaringType">A handle to the generic type that defines the constructor or method.</param><exception cref="T:System.ArgumentException"><paramref name="handle"/> is invalid.</exception>
 public static MethodBase GetMethodFromHandle(RuntimeMethodHandle handle, RuntimeTypeHandle declaringType)
 {
     throw new NotImplementedException();
 }
 public ReferenceTypeFieldAccessorForThreadStaticFields(IntPtr cctorContext, RuntimeTypeHandle declaringTypeHandle, IntPtr cookie, RuntimeTypeHandle fieldTypeHandle)
     : base(cctorContext, fieldTypeHandle)
 {
     _cookie = cookie;
     _declaringTypeHandle = declaringTypeHandle;
 }
 public abstract Type GetMdArrayTypeForHandle(RuntimeTypeHandle typeHandle, int rank);
 /// <summary>
 /// Retrieves the default value for a parameter of a method.
 /// </summary>
 /// <param name="defaultParametersContext">The default parameters context used to invoke the method,
 /// this should identify the method in question. This is passed to the RuntimeAugments.CallDynamicInvokeMethod.</param>
 /// <param name="thType">The type of the parameter to retrieve.</param>
 /// <param name="argIndex">The index of the parameter on the method to retrieve.</param>
 /// <param name="defaultValue">The default value of the parameter if available.</param>
 /// <returns>true if the default parameter value is available, otherwise false.</returns>
 public abstract bool TryGetDefaultParameterValue(object defaultParametersContext, RuntimeTypeHandle thType, int argIndex, out object defaultValue);
 public abstract Assembly GetAssemblyForHandle(RuntimeTypeHandle typeHandle);
Beispiel #38
0
        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);

                case CorElementType.Char:
                    return(*(char *)&buffer);

                case CorElementType.I1:
                    return(*(sbyte *)&buffer);

                case CorElementType.U1:
                    return(*(byte *)&buffer);

                case CorElementType.I2:
                    return(*(short *)&buffer);

                case CorElementType.U2:
                    return(*(ushort *)&buffer);

                case CorElementType.I4:
                    return(*(int *)&buffer);

                case CorElementType.U4:
                    return(*(uint *)&buffer);

                case CorElementType.I8:
                    return(buffer);

                case CorElementType.U8:
                    return((ulong)buffer);

                case CorElementType.Boolean:
                    // The boolean value returned from the metadata engine is stored as a
                    // BOOL, which actually maps to an int. We need to read it out as an int
                    // to avoid problems on big-endian machines.
                    return(*(int *)&buffer != 0);

                case CorElementType.R4:
                    return(*(float *)&buffer);

                case CorElementType.R8:
                    return(*(double *)&buffer);

                case CorElementType.String:
                    // A string constant can be empty but never null.
                    // A nullref constant can only be type CorElementType.Class.
                    return(stringVal == null ? String.Empty : stringVal);

                case CorElementType.Class:
                    return(null);

                default:
                    throw new FormatException(Environment.GetResourceString("Arg_BadLiteralFormat"));
                    #endregion
                }
            }
        }
Beispiel #39
0
 static Type \u206F‎‏​‬‎‏‫‬‌‫​‍‮‪‪‌‎‌‎‮​‏‮([In] RuntimeTypeHandle obj0)
 {
     // ISSUE: unable to decompile the method.
 }
Beispiel #40
0
 protected virtual void WriteDataContractValue(DataContract dataContract, XmlWriterDelegator xmlWriter, object obj, RuntimeTypeHandle declaredTypeHandle)
 {
     dataContract.WriteXmlValue(xmlWriter, obj, this);
 }
        //
        // This overload of GetMethodHandle can handle all method handles.
        //
        public sealed override MethodBase GetMethodFromHandle(RuntimeMethodHandle runtimeMethodHandle, RuntimeTypeHandle declaringTypeHandle)
        {
            ExecutionEnvironment executionEnvironment = ReflectionCoreExecution.ExecutionEnvironment;
            QMethodDefinition    methodHandle;

            RuntimeTypeHandle[] genericMethodTypeArgumentHandles;
            if (!executionEnvironment.TryGetMethodFromHandleAndType(runtimeMethodHandle, declaringTypeHandle, out methodHandle, out genericMethodTypeArgumentHandles))
            {
                // This may be a method declared on a non-generic type: this api accepts that too so try the other table.
                RuntimeTypeHandle actualDeclaringTypeHandle;
                if (!executionEnvironment.TryGetMethodFromHandle(runtimeMethodHandle, out actualDeclaringTypeHandle, out methodHandle, out genericMethodTypeArgumentHandles))
                {
                    throw new ArgumentException(SR.Argument_InvalidHandle);
                }
                if (!actualDeclaringTypeHandle.Equals(declaringTypeHandle))
                {
                    throw new ArgumentException(SR.Format(SR.Argument_ResolveMethodHandle,
                                                          declaringTypeHandle.GetTypeForRuntimeTypeHandle(),
                                                          actualDeclaringTypeHandle.GetTypeForRuntimeTypeHandle()));
                }
            }

            MethodBase methodBase = ReflectionCoreExecution.ExecutionDomain.GetMethod(declaringTypeHandle, methodHandle, genericMethodTypeArgumentHandles);

            return(methodBase);
        }
 public abstract Type GetConstructedGenericTypeForHandle(RuntimeTypeHandle typeHandle);
Beispiel #43
0
        protected void SerializeAndVerifyType(DataContract dataContract, XmlWriterDelegator xmlWriter, object obj, bool verifyKnownType, RuntimeTypeHandle declaredTypeHandle, Type declaredType)
        {
            bool knownTypesAddedInCurrentScope = false;

            if (dataContract.KnownDataContracts != null)
            {
                scopedKnownTypes.Push(dataContract.KnownDataContracts);
                knownTypesAddedInCurrentScope = true;
            }

            if (verifyKnownType)
            {
                if (!IsKnownType(dataContract, declaredType))
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlObjectSerializer.CreateSerializationException(SR.GetString(SR.DcTypeNotFoundOnSerialize, DataContract.GetClrTypeFullName(dataContract.UnderlyingType), dataContract.StableName.Name, dataContract.StableName.Namespace)));
                }
            }
            WriteDataContractValue(dataContract, xmlWriter, obj, declaredTypeHandle);

            if (knownTypesAddedInCurrentScope)
            {
                scopedKnownTypes.Pop();
            }
        }
Beispiel #44
0
 public abstract MethodBase GetMethodFromHandle(RuntimeMethodHandle runtimeMethodHandle, RuntimeTypeHandle declaringTypeHandle);
Beispiel #45
0
        protected virtual void SerializeWithXsiType(XmlWriterDelegator xmlWriter, object obj, RuntimeTypeHandle objectTypeHandle, Type objectType, int declaredTypeID, RuntimeTypeHandle declaredTypeHandle, Type declaredType)
        {
            DataContract dataContract;
            bool         verifyKnownType = false;

            if (declaredType.IsInterface && CollectionDataContract.IsCollectionInterface(declaredType))
            {
                dataContract = GetDataContractSkipValidation(DataContract.GetId(objectTypeHandle), objectTypeHandle, objectType);
                if (OnHandleIsReference(xmlWriter, dataContract, obj))
                {
                    return;
                }
                if (this.Mode == SerializationMode.SharedType && dataContract.IsValidContract(this.Mode))
                {
                    dataContract = dataContract.GetValidContract(this.Mode);
                }
                else
                {
                    dataContract = GetDataContract(declaredTypeHandle, declaredType);
                }
                if (!WriteClrTypeInfo(xmlWriter, dataContract) && DataContractResolver != null)
                {
                    if (objectType == null)
                    {
                        objectType = Type.GetTypeFromHandle(objectTypeHandle);
                    }
                    WriteResolvedTypeInfo(xmlWriter, objectType, declaredType);
                }
            }
            else if (declaredType.IsArray)//Array covariance is not supported in XSD. If declared type is array do not write xsi:type. Instead write xsi:type for each item
            {
                // A call to OnHandleIsReference is not necessary here -- arrays cannot be IsReference
                dataContract = GetDataContract(objectTypeHandle, objectType);
                WriteClrTypeInfo(xmlWriter, dataContract);
                dataContract = GetDataContract(declaredTypeHandle, declaredType);
            }
            else
            {
                dataContract = GetDataContract(objectTypeHandle, objectType);
                if (OnHandleIsReference(xmlWriter, dataContract, obj))
                {
                    return;
                }
                if (!WriteClrTypeInfo(xmlWriter, dataContract))
                {
                    DataContract declaredTypeContract = (declaredTypeID >= 0)
                        ? GetDataContract(declaredTypeID, declaredTypeHandle)
                        : GetDataContract(declaredTypeHandle, declaredType);
                    verifyKnownType = WriteTypeInfo(xmlWriter, dataContract, declaredTypeContract);
                }
            }

            SerializeAndVerifyType(dataContract, xmlWriter, obj, verifyKnownType, declaredTypeHandle, declaredType);
        }
Beispiel #46
0
 public abstract FieldInfo GetFieldFromHandle(RuntimeFieldHandle runtimeFieldHandle, RuntimeTypeHandle declaringTypeHandle);
Beispiel #47
0
 internal void SerializeWithoutXsiType(DataContract dataContract, XmlWriterDelegator xmlWriter, object obj, RuntimeTypeHandle declaredTypeHandle)
 {
     if (OnHandleIsReference(xmlWriter, dataContract, obj))
     {
         return;
     }
     if (dataContract.KnownDataContracts != null)
     {
         scopedKnownTypes.Push(dataContract.KnownDataContracts);
         WriteDataContractValue(dataContract, xmlWriter, obj, declaredTypeHandle);
         scopedKnownTypes.Pop();
     }
     else
     {
         WriteDataContractValue(dataContract, xmlWriter, obj, declaredTypeHandle);
     }
 }
 //=======================================================================================
 // This group of methods jointly service the Type.GetTypeFromHandle() path. The caller
 // is responsible for analyzing the RuntimeTypeHandle to figure out which flavor to call.
 //=======================================================================================
 public abstract Type GetNamedTypeForHandle(RuntimeTypeHandle typeHandle, bool isGenericTypeDefinition);
Beispiel #49
0
 public void InternalSerializeReference(XmlWriterDelegator xmlWriter, object obj, bool isDeclaredType, bool writeXsiType, int declaredTypeID, RuntimeTypeHandle declaredTypeHandle)
 {
     if (!OnHandleReference(xmlWriter, obj, true /*canContainCyclicReference*/))
     {
         InternalSerialize(xmlWriter, obj, isDeclaredType, writeXsiType, declaredTypeID, declaredTypeHandle);
     }
     OnEndHandleReference(xmlWriter, obj, true /*canContainCyclicReference*/);
 }
 public abstract bool IsReflectionBlocked(RuntimeTypeHandle typeHandle);
 static Type \u200D​​​‮‫‮‌‮‍‏‬‌‏​‮‌‎‭‬‬‮‏‮([In] RuntimeTypeHandle obj0)
 {
     // ISSUE: unable to decompile the method.
 }
 public abstract Type GetPointerTypeForHandle(RuntimeTypeHandle typeHandle);
Beispiel #53
0
 public void WriteJsonValue(XmlWriterDelegator jsonWriter, object obj, XmlObjectSerializerWriteContextComplexJson context, RuntimeTypeHandle declaredTypeHandle)
 {
     PushKnownDataContracts(context);
     WriteJsonValueCore(jsonWriter, obj, context, declaredTypeHandle);
     PopKnownDataContracts(context);
 }
Beispiel #54
0
 [System.Security.SecuritySafeCritical]  // auto-generated
 internal override RuntimeModule GetRuntimeModule()
 {
     return(RuntimeTypeHandle.GetModule(RuntimeFieldHandle.GetApproxDeclaringType(this)));
 }
Beispiel #55
0
		public static MethodBase GetMethodFromHandle (RuntimeMethodHandle handle, RuntimeTypeHandle declaringType)
		{
			return GetMethodFromIntPtr (handle.Value, declaringType.Value);
		}
Beispiel #56
0
 internal RuntimeModule GetRuntimeModule()
 {
     return(RuntimeTypeHandle.GetModule((RuntimeType)DeclaringType));
 }
 public ValueTypeFieldAccessorForStaticFields(IntPtr cctorContext, IntPtr fieldAddress, RuntimeTypeHandle fieldTypeHandle)
     : base(cctorContext, fieldTypeHandle)
 {
     _fieldAddress = fieldAddress;
 }
        //
        // This overload of GetFieldHandle can handle all field handles.
        //
        public sealed override FieldInfo GetFieldFromHandle(RuntimeFieldHandle runtimeFieldHandle, RuntimeTypeHandle declaringTypeHandle)
        {
            ExecutionEnvironment executionEnvironment = ReflectionCoreExecution.ExecutionEnvironment;
            FieldHandle          fieldHandle;

            if (!executionEnvironment.TryGetFieldFromHandleAndType(runtimeFieldHandle, declaringTypeHandle, out fieldHandle))
            {
                // This may be a field declared on a non-generic type: this api accepts that too so try the other table.
                RuntimeTypeHandle actualDeclaringTypeHandle;
                if (!executionEnvironment.TryGetFieldFromHandle(runtimeFieldHandle, out actualDeclaringTypeHandle, out fieldHandle))
                {
                    throw new ArgumentException(SR.Argument_InvalidHandle);
                }
                if (!actualDeclaringTypeHandle.Equals(declaringTypeHandle))
                {
                    throw new ArgumentException(SR.Format(SR.Argument_ResolveFieldHandle,
                                                          declaringTypeHandle.GetTypeForRuntimeTypeHandle(),
                                                          actualDeclaringTypeHandle.GetTypeForRuntimeTypeHandle()));
                }
            }

            FieldInfo fieldInfo = GetFieldInfo(declaringTypeHandle, fieldHandle);

            return(fieldInfo);
        }
 public override void WriteJsonValueCore(XmlWriterDelegator jsonWriter, object obj, XmlObjectSerializerWriteContextComplexJson context, RuntimeTypeHandle declaredTypeHandle)
 {
     jsonWriter.WriteAttributeString(null, JsonGlobals.typeString, null, JsonGlobals.objectString);
     JsonFormatWriterDelegate(jsonWriter, obj, context, TraditionalClassDataContract, MemberNames);
 }
        public sealed override IntPtr GetFunctionPointer(RuntimeMethodHandle runtimeMethodHandle, RuntimeTypeHandle declaringTypeHandle)
        {
            MethodBase method = GetMethodFromHandle(runtimeMethodHandle, declaringTypeHandle);

            switch (method)
            {
            case RuntimeMethodInfo methodInfo:
                return(methodInfo.LdFtnResult);

            case RuntimeConstructorInfo constructorInfo:
                return(constructorInfo.LdFtnResult);

            default:
                throw new PlatformNotSupportedException();
            }
        }