コード例 #1
0
        //
        // If throwIfMissingMetadata is false, returns null rather than throwing a MissingMetadataException.
        //
        internal sealed override IList <CustomAttributeNamedArgument> GetNamedArguments(bool throwIfMissingMetadata)
        {
            LowLevelListWithIList <CustomAttributeNamedArgument> customAttributeNamedArguments = new LowLevelListWithIList <CustomAttributeNamedArgument>();

            foreach (NamedArgumentHandle namedArgumentHandle in _customAttribute.NamedArguments)
            {
                NamedArgument namedArgument             = namedArgumentHandle.GetNamedArgument(_reader);
                String        memberName                = namedArgument.Name.GetString(_reader);
                bool          isField                   = (namedArgument.Flags == NamedArgumentMemberKind.Field);
                CustomAttributeTypedArgument typedValue =
                    ParseFixedArgument(
                        _reader,
                        namedArgument.Value,
                        throwIfMissingMetadata,
                        delegate()
                {
                    // We got here because the custom attribute blob did not inclue type information. For named arguments, this is considered illegal metadata
                    // (ECMA always includes type info for named arguments.)
                    throw new BadImageFormatException();
                }
                        );
                if (typedValue.ArgumentType == null)
                {
                    Debug.Assert(!throwIfMissingMetadata);
                    return(null);
                }
                customAttributeNamedArguments.Add(ReflectionAugments.CreateCustomAttributeNamedArgument(this.AttributeType, memberName, isField, typedValue));
            }
            return(customAttributeNamedArguments);
        }
コード例 #2
0
        //
        // One time initialization to supply the information needed to initialize the execution environment.
        //
        public static void InitializeExecutionDomain(ReflectionDomainSetup executionDomainSetup, ExecutionEnvironment executionEnvironment)
        {
            ExecutionDomain executionDomain = new ExecutionDomain(executionDomainSetup, executionEnvironment);

            //@todo: This check has a race window but since this is a private api targeted by the toolchain, perhaps this is not so critical.
            if (s_executionDomain != null)
            {
                throw new InvalidOperationException(); // Multiple Initializes not allowed.
            }
            s_executionDomain = executionDomain;

            ReflectionCoreCallbacks reflectionCallbacks = new ReflectionCoreCallbacksImplementation();

            ReflectionAugments.Initialize(reflectionCallbacks);
            return;
        }
コード例 #3
0
        // Equals/GetHashCode no need to override (they just implement reference equality but desktop never unified these things.)

        private void LoadArgumentInfo(bool throwIfMissingMetadata, out IList <CustomAttributeNamedArgument> namedArguments, out IList <CustomAttributeTypedArgument> fixedArguments, out bool metadataWasMissing)
        {
            LowLevelListWithIList <CustomAttributeNamedArgument> newNamedArguments = new LowLevelListWithIList <CustomAttributeNamedArgument>();
            LowLevelListWithIList <CustomAttributeTypedArgument> newFixedArguments = new LowLevelListWithIList <CustomAttributeTypedArgument>();
            ReflectionTypeProvider typeProvider = new ReflectionTypeProvider(throwIfMissingMetadata);

            CustomAttributeValue <RuntimeTypeInfo> customAttributeValue = _customAttribute.DecodeValue(typeProvider);

            foreach (CustomAttributeTypedArgument <RuntimeTypeInfo> fixedArgument in customAttributeValue.FixedArguments)
            {
                newFixedArguments.Add(WrapInCustomAttributeTypedArgument(fixedArgument.Value, fixedArgument.Type));
            }

            foreach (CustomAttributeNamedArgument <RuntimeTypeInfo> ecmaNamedArgument in customAttributeValue.NamedArguments)
            {
                bool isField = ecmaNamedArgument.Kind == CustomAttributeNamedArgumentKind.Field;
                CustomAttributeTypedArgument typedArgument = WrapInCustomAttributeTypedArgument(ecmaNamedArgument.Value, ecmaNamedArgument.Type);
                newNamedArguments.Add(ReflectionAugments.CreateCustomAttributeNamedArgument(this.AttributeType, ecmaNamedArgument.Name, isField, typedArgument));
            }

            if (newFixedArguments.Count == 0)
            {
                fixedArguments = Array.Empty <CustomAttributeTypedArgument>();
            }
            else
            {
                fixedArguments = newFixedArguments;
            }

            if (newNamedArguments.Count == 0)
            {
                namedArguments = Array.Empty <CustomAttributeNamedArgument>();
            }
            else
            {
                namedArguments = newNamedArguments;
            }

            metadataWasMissing = typeProvider.ExceptionOccurred;
        }
コード例 #4
0
ファイル: RuntimeTypeInfo.cs プロジェクト: svick/corert
 protected sealed override TypeCode GetTypeCodeImpl()
 {
     return(ReflectionAugments.GetRuntimeTypeCode(this));
 }
コード例 #5
0
        public static TypeLoadException CreateTypeLoadException(string typeName, string assemblyName)
        {
            string message = SR.Format(SR.TypeLoad_TypeNotFoundInAssembly, typeName, assemblyName);

            return(ReflectionAugments.CreateTypeLoadException(message, typeName));
        }
コード例 #6
0
        public sealed override Type MakeGenericType(params Type[] typeArguments)
        {
#if ENABLE_REFLECTION_TRACE
            if (ReflectionTrace.Enabled)
            {
                ReflectionTrace.TypeInfo_MakeGenericType(this, typeArguments);
            }
#endif

            if (typeArguments == null)
            {
                throw new ArgumentNullException(nameof(typeArguments));
            }

            if (!IsGenericTypeDefinition)
            {
                throw new InvalidOperationException(SR.Format(SR.Arg_NotGenericTypeDefinition, this));
            }

            // We intentionally don't validate the number of arguments or their suitability to the generic type's constraints.
            // In a pay-for-play world, this can cause needless MissingMetadataExceptions. There is no harm in creating
            // the Type object for an inconsistent generic type - no EEType will ever match it so any attempt to "invoke" it
            // will throw an exception.
            bool foundSignatureType = false;
            RuntimeTypeInfo[] runtimeTypeArguments = new RuntimeTypeInfo[typeArguments.Length];
            for (int i = 0; i < typeArguments.Length; i++)
            {
                RuntimeTypeInfo runtimeTypeArgument = runtimeTypeArguments[i] = typeArguments[i] as RuntimeTypeInfo;
                if (runtimeTypeArgument == null)
                {
                    if (typeArguments[i] == null)
                    {
                        throw new ArgumentNullException();
                    }

                    if (typeArguments[i].IsSignatureType)
                    {
                        foundSignatureType = true;
                    }
                    else
                    {
                        throw new PlatformNotSupportedException(SR.PlatformNotSupported_MakeGenericType); // "PlatformNotSupported" because on desktop, passing in a foreign type is allowed and creates a RefEmit.TypeBuilder
                    }
                }
            }

            if (foundSignatureType)
            {
                return(ReflectionAugments.MakeGenericSignatureType(this, typeArguments));
            }

            for (int i = 0; i < typeArguments.Length; i++)
            {
                RuntimeTypeInfo runtimeTypeArgument = runtimeTypeArguments[i];

                // Desktop compatibility: Treat generic type definitions as a constructed generic type using the generic parameters as type arguments.
                if (runtimeTypeArgument.IsGenericTypeDefinition)
                {
                    runtimeTypeArgument = runtimeTypeArguments[i] = runtimeTypeArgument.GetConstructedGenericType(runtimeTypeArgument.RuntimeGenericTypeParameters);
                }

                if (runtimeTypeArgument.IsByRefLike)
                {
                    throw new TypeLoadException(SR.CannotUseByRefLikeTypeInInstantiation);
                }
            }

            return(this.GetConstructedGenericType(runtimeTypeArguments));
        }
コード例 #7
0
ファイル: LibraryInitializer.cs プロジェクト: z77ma/runtime
 public static void InitializeLibrary()
 {
     RuntimeAugments.Initialize(new ReflectionExecutionDomainCallbacksImplementation());
     ReflectionAugments.Initialize(new ReflectionCoreCallbacksImplementation());
 }