private static bool AddDependenciesFromCustomAttributeArgument(DependencyList dependencies, NodeFactory factory, TypeDesc type, object value)
        {
            // If this is an initializer that refers to e.g. a blocked enum, we can't encode this attribute.
            if (factory.MetadataManager.IsReflectionBlocked(type))
            {
                return(false);
            }

            // Reflection will need to be able to allocate this type at runtime
            // (e.g. this could be an array that needs to be allocated, or an enum that needs to be boxed).
            dependencies.Add(factory.ConstructedTypeSymbol(type), "Custom attribute blob");

            if (type.UnderlyingType.IsPrimitive || type.IsString || value == null)
            {
                return(true);
            }

            if (type.IsSzArray)
            {
                TypeDesc elementType = ((ArrayType)type).ElementType;
                if (elementType.UnderlyingType.IsPrimitive || elementType.IsString)
                {
                    return(true);
                }

                foreach (CustomAttributeTypedArgument <TypeDesc> arrayElement in (ImmutableArray <CustomAttributeTypedArgument <TypeDesc> >)value)
                {
                    if (!AddDependenciesFromCustomAttributeArgument(dependencies, factory, arrayElement.Type, arrayElement.Value))
                    {
                        return(false);
                    }
                }

                return(true);
            }

            // typeof() should be the only remaining option.

            Debug.Assert(value is TypeDesc);

            TypeDesc typeofType = (TypeDesc)value;

            if (factory.MetadataManager.IsReflectionBlocked(typeofType))
            {
                return(false);
            }

            // Grab the metadata nodes that will be necessary to represent the typeof in the metadata blob
            TypeMetadataNode.GetMetadataDependencies(ref dependencies, factory, typeofType, "Custom attribute blob");
            return(true);
        }
        public override IEnumerable <DependencyListEntry> GetStaticDependencies(NodeFactory factory)
        {
            DependencyList dependencies = new DependencyList();

            dependencies.Add(factory.TypeMetadata((MetadataType)_method.OwningType), "Owning type metadata");

            CustomAttributeBasedDependencyAlgorithm.AddDependenciesDueToCustomAttributes(ref dependencies, factory, ((EcmaMethod)_method));

            MethodSignature sig    = _method.Signature;
            const string    reason = "Method signature metadata";

            TypeMetadataNode.GetMetadataDependencies(ref dependencies, factory, sig.ReturnType, reason);
            foreach (TypeDesc paramType in sig)
            {
                TypeMetadataNode.GetMetadataDependencies(ref dependencies, factory, paramType, reason);
            }

            return(dependencies);
        }
Esempio n. 3
0
        private static bool AddDependenciesFromCustomAttributeArgument(DependencyList dependencies, NodeFactory factory, TypeDesc type, object value)
        {
            if (type.UnderlyingType.IsPrimitive || type.IsString || value == null)
            {
                return(true);
            }

            if (type.IsSzArray)
            {
                TypeDesc elementType = ((ArrayType)type).ElementType;
                if (elementType.UnderlyingType.IsPrimitive || elementType.IsString)
                {
                    return(true);
                }

                foreach (CustomAttributeTypedArgument <TypeDesc> arrayElement in (ImmutableArray <CustomAttributeTypedArgument <TypeDesc> >)value)
                {
                    if (!AddDependenciesFromCustomAttributeArgument(dependencies, factory, arrayElement.Type, arrayElement.Value))
                    {
                        return(false);
                    }
                }

                return(true);
            }

            // typeof() should be the only remaining option.

            Debug.Assert(value is TypeDesc);

            TypeDesc typeofType = (TypeDesc)value;

            if (factory.MetadataManager.IsReflectionBlocked(typeofType))
            {
                return(false);
            }

            TypeMetadataNode.GetMetadataDependencies(ref dependencies, factory, typeofType, "Custom attribute blob");

            return(true);
        }