Пример #1
0
        public bool IsBlocked(MetadataType typeDef)
        {
            if (typeDef.Name == "ICastable")
                return true;

            if (typeDef.HasCustomAttribute("System.Runtime.CompilerServices", "__BlockReflectionAttribute"))
                return true;

            return false;
        }
        private Cts.ModuleDesc OverrideModuleOfTypeViaExplicitScope(Cts.MetadataType typeDef)
        {
            if (typeDef.HasCustomAttribute("Internal.Reflection", "ExplicitScopeAttribute"))
            {
                // There is no current cross type system way to represent custom attributes
                Cts.Ecma.EcmaType ecmaType = (Cts.Ecma.EcmaType)typeDef;

                var customAttributeValue = Internal.TypeSystem.Ecma.MetadataExtensions.GetDecodedCustomAttribute(
                    ecmaType, "Internal.Reflection", "ExplicitScopeAttribute");

                if (!customAttributeValue.HasValue)
                {
                    return(null);
                }

                if (customAttributeValue.Value.FixedArguments.Length != 1)
                {
                    return(null);
                }

                if (customAttributeValue.Value.FixedArguments[0].Type != typeDef.Context.GetWellKnownType(Cts.WellKnownType.String))
                {
                    return(null);
                }

                string       assemblyNameString = (string)customAttributeValue.Value.FixedArguments[0].Value;
                AssemblyName assemblyName       = new AssemblyName(assemblyNameString);
                Debug.Assert(typeDef.Context.ResolveAssembly(assemblyName, false) == null, "ExplicitScopeAttribute must not refer to an assembly which is actually present in the type system.");
                lock (_dynamicallyGeneratedExplicitScopes)
                {
                    ExplicitScopeAssembly explicitScopeAssembly;

                    if (_dynamicallyGeneratedExplicitScopes.TryGetValue(assemblyName, out explicitScopeAssembly))
                    {
                        return(explicitScopeAssembly);
                    }
                    explicitScopeAssembly = new ExplicitScopeAssembly(typeDef.Context, assemblyName);
                    _dynamicallyGeneratedExplicitScopes.Add(assemblyName, explicitScopeAssembly);
                    return(explicitScopeAssembly);
                }
            }

            return(null);
        }
Пример #3
0
 public override bool HasCustomAttribute(string attributeNamespace, string attributeName)
 {
     return(_typeDef.HasCustomAttribute(attributeNamespace, attributeName));
 }