public Attribute ResolveAssemblyAttribute(PredefinedAttribute a_type) { Attribute a = OptAttributes.Search("assembly", a_type); if (a != null) { a.Resolve(); } return(a); }
Attribute ResolveAttribute(PredefinedAttribute a_type) { Attribute a = OptAttributes.Search(a_type); if (a != null) { a.Resolve(); } return(a); }
public override void Emit(TypeContainer tc) { base.Emit(tc); if (has_extension_method) { PredefinedAttributes.Get.Extension.EmitAttribute(Builder); } // FIXME: Does this belong inside SRE.AssemblyBuilder instead? PredefinedAttribute pa = PredefinedAttributes.Get.RuntimeCompatibility; if (pa.IsDefined && (OptAttributes == null || !OptAttributes.Contains(pa))) { ConstructorInfo ci = TypeManager.GetPredefinedConstructor( pa.Type, Location.Null, Type.EmptyTypes); PropertyInfo [] pis = new PropertyInfo [1]; pis [0] = TypeManager.GetPredefinedProperty(pa.Type, "WrapNonExceptionThrows", Location.Null, TypeManager.bool_type); object [] pargs = new object [1]; pargs [0] = true; Builder.SetCustomAttribute(new CustomAttributeBuilder(ci, new object [0], pis, pargs)); } if (declarative_security != null) { MethodInfo add_permission = typeof(AssemblyBuilder).GetMethod("AddPermissionRequests", BindingFlags.Instance | BindingFlags.NonPublic); object builder_instance = Builder; try { // Microsoft runtime hacking if (add_permission == null) { Type assembly_builder = typeof(AssemblyBuilder).Assembly.GetType("System.Reflection.Emit.AssemblyBuilderData"); add_permission = assembly_builder.GetMethod("AddPermissionRequests", BindingFlags.Instance | BindingFlags.NonPublic); FieldInfo fi = typeof(AssemblyBuilder).GetField("m_assemblyData", BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.GetField); builder_instance = fi.GetValue(Builder); } object[] args = new object [] { declarative_security [SecurityAction.RequestMinimum], declarative_security [SecurityAction.RequestOptional], declarative_security [SecurityAction.RequestRefuse] }; add_permission.Invoke(builder_instance, args); } catch { Report.RuntimeMissingSupport(Location.Null, "assembly permission setting"); } } }
/// <summary> /// It is called very early therefore can resolve only predefined attributes /// </summary> void ResolveGlobalAttributes() { if (OptAttributes == null) { return; } if (!OptAttributes.CheckTargets()) { return; } // FIXME: Define is wrong as the type may not exist yet var DefaultCharSet_attr = new PredefinedAttribute(this, "System.Runtime.InteropServices", "DefaultCharSetAttribute"); DefaultCharSet_attr.Define(); Attribute a = ResolveModuleAttribute(DefaultCharSet_attr); if (a != null) { has_default_charset = true; DefaultCharSet = a.GetCharSetValue(); switch (DefaultCharSet) { case CharSet.Ansi: case CharSet.None: break; case CharSet.Auto: DefaultCharSetType = TypeAttributes.AutoClass; break; case CharSet.Unicode: DefaultCharSetType = TypeAttributes.UnicodeClass; break; default: Report.Error(1724, a.Location, "Value specified for the argument to `{0}' is not valid", DefaultCharSet_attr.GetSignatureForError()); break; } } }
public static CustomAttributeBuilder CreateDecimalConstantAttribute(Constant c) { PredefinedAttribute pa = PredefinedAttributes.Get.DecimalConstant; if (pa.Constructor == null && !pa.ResolveConstructor(c.Location, TypeManager.byte_type, TypeManager.byte_type, TypeManager.uint32_type, TypeManager.uint32_type, TypeManager.uint32_type)) { return(null); } Decimal d = (Decimal)c.GetValue(); int [] bits = Decimal.GetBits(d); object [] args = new object [] { (byte)(bits [3] >> 16), (byte)(bits [3] >> 31), (uint)bits [2], (uint)bits [1], (uint)bits [0] }; return(new CustomAttributeBuilder(pa.Constructor, args)); }
public AttributeUsageAttribute GetAttributeUsage (PredefinedAttribute pa) { Attribute a = null; if (OptAttributes != null) { a = OptAttributes.Search (pa); } if (a == null) return null; return a.GetAttributeUsageAttribute (); }
public virtual void Emit() { if (Compiler.Settings.Target == Target.Module) { module_target_attrs = new AssemblyAttributesPlaceholder(module, name); module_target_attrs.CreateContainer(); module_target_attrs.DefineContainer(); module_target_attrs.Define(); module.AddCompilerGeneratedClass(module_target_attrs); } else if (added_modules != null) { ReadModulesAssemblyAttributes(); } if (Compiler.Settings.GenerateDebugInfo) { symbol_writer = new MonoSymbolFile(); } module.EmitContainer(); if (module.HasExtensionMethod) { var pa = module.PredefinedAttributes.Extension; if (pa.IsDefined) { SetCustomAttribute(pa.Constructor, AttributeEncoder.Empty); } } if (!IsSatelliteAssembly) { if (!wrap_non_exception_throws_custom) { PredefinedAttribute pa = module.PredefinedAttributes.RuntimeCompatibility; if (pa.IsDefined && pa.ResolveBuilder()) { var prop = module.PredefinedMembers.RuntimeCompatibilityWrapNonExceptionThrows.Get(); if (prop != null) { AttributeEncoder encoder = new AttributeEncoder(); encoder.EncodeNamedPropertyArgument(prop, new BoolLiteral(Compiler.BuiltinTypes, true, Location.Null)); SetCustomAttribute(pa.Constructor, encoder.ToArray()); } } } if (declarative_security != null) { #if STATIC foreach (var entry in declarative_security) { Builder.__AddDeclarativeSecurity(entry); } #else throw new NotSupportedException("Assembly-level security"); #endif } } CheckReferencesPublicToken(); SetEntryPoint(); }
public virtual void Emit() { if (Compiler.Settings.Target == Target.Module) { module_target_attrs = new AssemblyAttributesPlaceholder(module, name); module_target_attrs.CreateType(); module_target_attrs.DefineType(); module_target_attrs.Define(); module.AddCompilerGeneratedClass(module_target_attrs); } else if (added_modules != null) { ReadModulesAssemblyAttributes(); } if (Compiler.Settings.GenerateDebugInfo) { symbol_writer = new MonoSymbolWriter(file_name); // Register all source files with symbol writer foreach (var source in Compiler.SourceFiles) { source.DefineSymbolInfo(symbol_writer); } // TODO: global variables SymbolWriter.symwriter = symbol_writer; } module.Emit(); if (module.HasExtensionMethod) { var pa = module.PredefinedAttributes.Extension; if (pa.IsDefined) { SetCustomAttribute(pa.Constructor, AttributeEncoder.Empty); } } if (!wrap_non_exception_throws_custom) { PredefinedAttribute pa = module.PredefinedAttributes.RuntimeCompatibility; if (pa.IsDefined && pa.ResolveBuilder()) { var prop = module.PredefinedMembers.RuntimeCompatibilityWrapNonExceptionThrows.Get(); if (prop != null) { AttributeEncoder encoder = new AttributeEncoder(); encoder.EncodeNamedPropertyArgument(prop, new BoolLiteral(Compiler.BuiltinTypes, true, Location.Null)); SetCustomAttribute(pa.Constructor, encoder.ToArray()); } } } if (declarative_security != null) { #if STATIC foreach (var entry in declarative_security) { Builder.__AddDeclarativeSecurity(entry); } #else var args = new PermissionSet[3]; declarative_security.TryGetValue(SecurityAction.RequestMinimum, out args[0]); declarative_security.TryGetValue(SecurityAction.RequestOptional, out args[1]); declarative_security.TryGetValue(SecurityAction.RequestRefuse, out args[2]); builder_extra.AddPermissionRequests(args); #endif } CheckReferencesPublicToken(); SetEntryPoint(); }
public AttributeUsageAttribute GetAttributeUsage (PredefinedAttribute pa) { throw new NotSupportedException (); }
public AttributeUsageAttribute GetAttributeUsage (PredefinedAttribute pa) { if (cattrs == null) ReadAttributes (); return cattrs.AttributeUsage; }
AttributeUsageAttribute ITypeDefinition.GetAttributeUsage(PredefinedAttribute pa) { return(null); }
// // Imports SRE parameters // public static AParametersCollection Create(ParameterInfo [] pi, MethodBase method) { int varargs = method != null && (method.CallingConvention & CallingConventions.VarArgs) != 0 ? 1 : 0; if (pi.Length == 0 && varargs == 0) { return(ParametersCompiled.EmptyReadOnlyParameters); } Type [] types = new Type [pi.Length + varargs]; IParameterData [] par = new IParameterData [pi.Length + varargs]; bool is_params = false; PredefinedAttribute extension_attr = PredefinedAttributes.Get.Extension; PredefinedAttribute param_attr = PredefinedAttributes.Get.ParamArray; for (int i = 0; i < pi.Length; i++) { types [i] = TypeManager.TypeToCoreType(pi [i].ParameterType); ParameterInfo p = pi [i]; Parameter.Modifier mod = 0; Expression default_value = null; if (types [i].IsByRef) { if ((p.Attributes & (ParameterAttributes.Out | ParameterAttributes.In)) == ParameterAttributes.Out) { mod = Parameter.Modifier.OUT; } else { mod = Parameter.Modifier.REF; } // // Strip reference wrapping // types [i] = TypeManager.GetElementType(types [i]); } else if (i == 0 && extension_attr.IsDefined && method != null && method.IsStatic && (method.DeclaringType.Attributes & Class.StaticClassAttribute) == Class.StaticClassAttribute && method.IsDefined(extension_attr.Type, false)) { mod = Parameter.Modifier.This; } else { if (i >= pi.Length - 2 && types[i].IsArray) { if (p.IsDefined(param_attr.Type, false)) { mod = Parameter.Modifier.PARAMS; is_params = true; } } if (!is_params && p.IsOptional) { object value = p.DefaultValue; if (value == Missing.Value) { default_value = EmptyExpression.Null; } else if (value == null) { default_value = new NullLiteral(Location.Null); } else { default_value = Constant.CreateConstant(value.GetType(), value, Location.Null); } } } par [i] = new ParameterData(p.Name, mod, default_value); } if (varargs != 0) { par [par.Length - 1] = new ArglistParameter(Location.Null); types [types.Length - 1] = InternalType.Arglist; } return(method != null ? new ParametersImported(par, types, varargs != 0, is_params) : new ParametersImported(par, types)); }
public Attribute ResolveAssemblyAttribute (PredefinedAttribute a_type) { Attribute a = OptAttributes.Search ("assembly", a_type); if (a != null) { a.Resolve (); } return a; }