public override void Emit() { if (member_type.BuiltinType == BuiltinTypeSpec.Type.Dynamic) { Module.PredefinedAttributes.Dynamic.EmitAttribute(FieldBuilder); } else if (!(Parent is CompilerGeneratedClass) && member_type.HasDynamicElement) { Module.PredefinedAttributes.Dynamic.EmitAttribute(FieldBuilder, member_type, Location); } if ((ModFlags & Modifiers.COMPILER_GENERATED) != 0 && !Parent.IsCompilerGenerated) { Module.PredefinedAttributes.CompilerGenerated.EmitAttribute(FieldBuilder); } if (OptAttributes != null) { OptAttributes.Emit(); } if (((status & Status.HAS_OFFSET) == 0) && (ModFlags & (Modifiers.STATIC | Modifiers.BACKING_FIELD)) == 0 && Parent.PartialContainer.HasExplicitLayout) { Report.Error(625, Location, "`{0}': Instance field types marked with StructLayout(LayoutKind.Explicit) must have a FieldOffset attribute", GetSignatureForError()); } base.Emit(); }
public override void EmitContainerJs(JsEmitContext jec) { if (OptAttributes != null) { OptAttributes.EmitJs(jec); } foreach (var tc in containers) { tc.PrepareEmit(); } base.EmitContainerJs(jec); if (Compiler.Report.Errors == 0 && !Compiler.Settings.WriteMetadataOnly) { VerifyMembers(); } if (anonymous_types != null) { foreach (var atypes in anonymous_types) { foreach (var at in atypes.Value) { at.EmitContainerJs(jec); } } } }
public override void Emit() { if (member_type.BuiltinType == BuiltinTypeSpec.Type.Dynamic) { Module.PredefinedAttributes.Dynamic.EmitAttribute(FieldBuilder); } else if (!Parent.IsCompilerGenerated && member_type.HasDynamicElement) { Module.PredefinedAttributes.Dynamic.EmitAttribute(FieldBuilder, member_type, Location); } if ((ModFlags & Modifiers.COMPILER_GENERATED) != 0 && !Parent.IsCompilerGenerated) { Module.PredefinedAttributes.CompilerGenerated.EmitAttribute(FieldBuilder); } if ((ModFlags & Modifiers.DEBUGGER_HIDDEN) != 0) { Module.PredefinedAttributes.DebuggerBrowsable.EmitAttribute(FieldBuilder, System.Diagnostics.DebuggerBrowsableState.Never); } if (OptAttributes != null) { OptAttributes.Emit(); } if (((status & Status.HAS_OFFSET) == 0) && (ModFlags & (Modifiers.STATIC | Modifiers.BACKING_FIELD)) == 0 && Parent.PartialContainer.HasExplicitLayout) { Report.Error(625, Location, "`{0}': Instance field types marked with StructLayout(LayoutKind.Explicit) must have a FieldOffset attribute", GetSignatureForError()); } ConstraintChecker.Check(this, member_type, type_expr.Location); base.Emit(); }
/// <summary> /// Returns instance of ObsoleteAttribute for this MemberCore /// </summary> public virtual ObsoleteAttribute GetAttributeObsolete() { if ((caching_flags & (Flags.Obsolete_Undetected | Flags.Obsolete)) == 0) { return(null); } caching_flags &= ~Flags.Obsolete_Undetected; if (OptAttributes == null) { return(null); } Attribute obsolete_attr = OptAttributes.Search(Module.PredefinedAttributes.Obsolete); if (obsolete_attr == null) { return(null); } caching_flags |= Flags.Obsolete; ObsoleteAttribute obsolete = obsolete_attr.GetObsoleteAttribute(); if (obsolete == null) { return(null); } return(obsolete); }
public virtual void Emit(TypeContainer tc) { if (OptAttributes == null) { return; } OptAttributes.Emit(); }
/// <summary> /// The main virtual method for CLS-Compliant verifications. /// The method returns true if member is CLS-Compliant and false if member is not /// CLS-Compliant which means that CLS-Compliant tests are not necessary. A descendants override it /// and add their extra verifications. /// </summary> protected virtual bool VerifyClsCompliance() { if (HasClsCompliantAttribute) { if (!Module.DeclaringAssembly.HasCLSCompliantAttribute) { Attribute a = OptAttributes.Search (Module.PredefinedAttributes.CLSCompliant); if ((caching_flags & Flags.ClsCompliantAttributeFalse) != 0) { Report.Warning (3021, 2, a.Location, "`{0}' does not need a CLSCompliant attribute because the assembly is not marked as CLS-compliant", GetSignatureForError ()); } else { Report.Warning (3014, 1, a.Location, "`{0}' cannot be marked as CLS-compliant because the assembly is not marked as CLS-compliant", GetSignatureForError ()); } return false; } if (!IsExposedFromAssembly ()) { Attribute a = OptAttributes.Search (Module.PredefinedAttributes.CLSCompliant); Report.Warning (3019, 2, a.Location, "CLS compliance checking will not be performed on `{0}' because it is not visible from outside this assembly", GetSignatureForError ()); return false; } if ((caching_flags & Flags.ClsCompliantAttributeFalse) != 0) { if (Parent is Interface && Parent.IsClsComplianceRequired ()) { Report.Warning (3010, 1, Location, "`{0}': CLS-compliant interfaces must have only CLS-compliant members", GetSignatureForError ()); } else if (Parent.Kind == MemberKind.Class && (ModFlags & Modifiers.ABSTRACT) != 0 && Parent.IsClsComplianceRequired ()) { Report.Warning (3011, 1, Location, "`{0}': only CLS-compliant members can be abstract", GetSignatureForError ()); } return false; } if (Parent.Kind != MemberKind.Namespace && Parent.Kind != 0 && !Parent.IsClsComplianceRequired ()) { Attribute a = OptAttributes.Search (Module.PredefinedAttributes.CLSCompliant); Report.Warning (3018, 1, a.Location, "`{0}' cannot be marked as CLS-compliant because it is a member of non CLS-compliant type `{1}'", GetSignatureForError (), Parent.GetSignatureForError ()); return false; } } else { if (!IsExposedFromAssembly ()) return false; if (!Parent.IsClsComplianceRequired ()) return false; } if (member_name.Name [0] == '_') { Warning_IdentifierNotCompliant (); } if (member_name.TypeParameters != null) member_name.TypeParameters.VerifyClsCompliance (); return true; }
Attribute ResolveModuleAttribute(PredefinedAttribute a_type) { Attribute a = OptAttributes.Search("module", a_type); if (a != null) { a.Resolve(); } return(a); }
protected Attribute ResolveAttribute(PredefinedAttribute a_type) { Attribute a = OptAttributes.Search(a_type); if (a != null) { a.Resolve(); } return(a); }
public Attribute ResolveAssemblyAttribute(PredefinedAttribute a_type) { Attribute a = OptAttributes.Search("assembly", a_type); if (a != null) { a.Resolve(); } return(a); }
public override void Emit() { if (OptAttributes != null) { OptAttributes.Emit(); } if (Compiler.Settings.Unsafe) { var pa = PredefinedAttributes.UnverifiableCode; if (pa.IsDefined) { pa.EmitAttribute(builder); } } foreach (var tc in types) { tc.DefineConstants(); } foreach (TypeContainer tc in types) { tc.EmitType(); } if (Compiler.Report.Errors > 0) { return; } foreach (TypeContainer tc in types) { tc.VerifyMembers(); } if (anonymous_types != null) { foreach (var atypes in anonymous_types) { foreach (var at in atypes.Value) { at.EmitType(); } } } if (compiler_generated != null) { foreach (var c in compiler_generated) { c.EmitType(); } } }
public override void EmitContainerCpp(CppEmitContext cec) { if (OptAttributes != null) { OptAttributes.EmitCpp(cec); } if (cec.Pass == CppPasses.PREDEF) { foreach (var tc in containers) { tc.PrepareEmit(); } } cec.PrevNamespace = null; cec.PrevNamespaceNames = null; base.EmitContainerCpp(cec); // Close last unclosed namespace.. if (cec.PrevNamespaceNames != null) { foreach (var n in cec.PrevNamespaceNames) { cec.Buf.Unindent(); cec.Buf.Write("\t}\n"); } } cec.PrevNamespace = null; cec.PrevNamespaceNames = null; if (cec.Pass == CppPasses.METHODS) { if (Compiler.Report.Errors == 0 && !Compiler.Settings.WriteMetadataOnly) { VerifyMembers(); } } if (anonymous_types != null) { foreach (var atypes in anonymous_types) { foreach (var at in atypes.Value) { at.EmitContainerCpp(cec); } } } }
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"); } } }
public bool?CheckAllowDynamic() { if (OptAttributes != null) { if (OptAttributes.Contains(Module.PredefinedAttributes.AsAllowDynamicAttribute)) { return(true); } else if (OptAttributes.Contains(Module.PredefinedAttributes.AsForbidDynamicAttribute)) { return(false); } } return(null); }
public virtual void ApplyAttributes(MethodBuilder mb, ConstructorBuilder cb, int index) { if (mb == null) { builder = cb.DefineParameter(index, Attributes, Name); } else { builder = mb.DefineParameter(index, Attributes, Name); } if (OptAttributes != null) { OptAttributes.Emit(); } }
public override void Emit() { Parameters.ApplyAttributes(InvokeBuilder); if (BeginInvokeBuilder != null) { Parameters p = (Parameters)TypeManager.GetParameterData(BeginInvokeBuilder); p.ApplyAttributes(BeginInvokeBuilder); } if (OptAttributes != null) { OptAttributes.Emit(); } base.Emit(); }
public override void Emit() { if (OptAttributes != null) { OptAttributes.Emit(); } if (RootContext.Unsafe) { var pa = PredefinedAttributes.UnverifiableCode; if (pa.IsDefined) { pa.EmitAttribute(builder); } } foreach (var tc in types) { tc.DefineConstants(); } HackCorlib(); foreach (TypeContainer tc in types) { tc.EmitType(); } if (Compiler.Report.Errors > 0) { return; } foreach (TypeContainer tc in types) { tc.VerifyMembers(); } if (compiler_generated != null) { foreach (var c in compiler_generated) { c.EmitType(); } } }
public override void ApplyAttributeBuilder(Attribute a, MethodSpec ctor, byte[] cdata, PredefinedAttributes pa) { if (a.Type == pa.In && ModFlags == Modifier.OUT) { a.Report.Error(36, a.Location, "An out parameter cannot have the `In' attribute"); return; } if (a.Type == pa.ParamArray) { a.Report.Error(674, a.Location, "Do not use `System.ParamArrayAttribute'. Use the `params' keyword instead"); return; } if (a.Type == pa.Out && (ModFlags & Modifier.REF) == Modifier.REF && !OptAttributes.Contains(pa.In)) { a.Report.Error(662, a.Location, "Cannot specify only `Out' attribute on a ref parameter. Use both `In' and `Out' attributes or neither"); return; } if (a.Type == pa.CLSCompliant) { a.Report.Warning(3022, 1, a.Location, "CLSCompliant attribute has no meaning when applied to parameters. Try putting it on the method instead"); } if (a.Type == pa.DefaultParameterValue || a.Type == pa.OptionalParameter) { if (HasOptionalExpression) { a.Report.Error(1745, a.Location, "Cannot specify `{0}' attribute on optional parameter `{1}'", TypeManager.CSharpName(a.Type).Replace("Attribute", ""), Name); } if (a.Type == pa.DefaultParameterValue) { return; } } base.ApplyAttributeBuilder(a, ctor, cdata, pa); }
/// <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 override void Emit() { if (OptAttributes != null) { OptAttributes.Emit(); } if (is_unsafe) { Type t = TypeManager.CoreLookupType(context, "System.Security", "UnverifiableCodeAttribute", Kind.Class, true); if (t != null) { ConstructorInfo unverifiable_code_ctor = TypeManager.GetPredefinedConstructor(t, Location.Null, Type.EmptyTypes); if (unverifiable_code_ctor != null) { Builder.SetCustomAttribute(new CustomAttributeBuilder(unverifiable_code_ctor, new object [0])); } } } }
public virtual void ApplyAttributes(MethodBuilder mb, ConstructorBuilder cb, int index) { if (mb == null) { builder = cb.DefineParameter(index, Attributes, Name); } else { builder = mb.DefineParameter(index, Attributes, Name); } if (OptAttributes != null) { OptAttributes.Emit(); } if (HasDefaultValue) { // // Emit constant values for true constants only, the other // constant-like expressions will rely on default value expression // Constant c = default_expr as Constant; if (c != null) { if (default_expr.Type == TypeManager.decimal_type) { builder.SetCustomAttribute(Const.CreateDecimalConstantAttribute(c)); } else { builder.SetConstant(c.GetValue()); } } } if (TypeManager.IsDynamicType(parameter_type)) { PredefinedAttributes.Get.Dynamic.EmitAttribute(builder, Location); } }
public override void EmitType() { if (ReturnType.Type != null) { if (ReturnType.Type.BuiltinType == BuiltinTypeSpec.Type.Dynamic) { return_attributes = new ReturnParameter(this, InvokeBuilder.MethodBuilder, Location); Module.PredefinedAttributes.Dynamic.EmitAttribute(return_attributes.Builder); } else if (ReturnType.Type.HasDynamicElement) { return_attributes = new ReturnParameter(this, InvokeBuilder.MethodBuilder, Location); Module.PredefinedAttributes.Dynamic.EmitAttribute(return_attributes.Builder, ReturnType.Type, Location); } ConstraintChecker.Check(this, ReturnType.Type, ReturnType.Location); } Constructor.ParameterInfo.ApplyAttributes(this, Constructor.ConstructorBuilder); Constructor.ConstructorBuilder.SetImplementationFlags(MethodImplAttributes.Runtime); parameters.CheckConstraints(this); parameters.ApplyAttributes(this, InvokeBuilder.MethodBuilder); InvokeBuilder.MethodBuilder.SetImplementationFlags(MethodImplAttributes.Runtime); if (BeginInvokeBuilder != null) { BeginInvokeBuilder.ParameterInfo.ApplyAttributes(this, BeginInvokeBuilder.MethodBuilder); EndInvokeBuilder.ParameterInfo.ApplyAttributes(this, EndInvokeBuilder.MethodBuilder); BeginInvokeBuilder.MethodBuilder.SetImplementationFlags(MethodImplAttributes.Runtime); EndInvokeBuilder.MethodBuilder.SetImplementationFlags(MethodImplAttributes.Runtime); } if (OptAttributes != null) { OptAttributes.Emit(); } base.Emit(); }
public override void EmitContainer() { if (OptAttributes != null) { OptAttributes.Emit(); } if (Compiler.Settings.Unsafe && !assembly.IsSatelliteAssembly) { var pa = PredefinedAttributes.UnverifiableCode; if (pa.IsDefined) { pa.EmitAttribute(builder); } } foreach (var tc in containers) { tc.PrepareEmit(); } base.EmitContainer(); if (Compiler.Report.Errors == 0 && !Compiler.Settings.WriteMetadataOnly) { VerifyMembers(); } if (anonymous_types != null) { foreach (var atypes in anonymous_types) { foreach (var at in atypes.Value) { at.EmitContainer(); } } } }
/// <summary> /// It is called very early therefore can resolve only predefined attributes /// </summary> public void Resolve() { if (OptAttributes == null) { return; } if (!OptAttributes.CheckTargets()) { return; } Attribute a = ResolveAttribute(PredefinedAttributes.Get.DefaultCharset); 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 'System.Runtime.InteropServices.DefaultCharSetAttribute' is not valid"); break; } } }
public override void Emit() { if (TypeManager.IsDynamicType(ret_type)) { return_attributes = new ReturnParameter(InvokeBuilder, Location); return_attributes.EmitPredefined(PredefinedAttributes.Get.Dynamic, Location); } Parameters.ApplyAttributes(InvokeBuilder); if (BeginInvokeBuilder != null) { ParametersCompiled p = (ParametersCompiled)TypeManager.GetParameterData(BeginInvokeBuilder); p.ApplyAttributes(BeginInvokeBuilder); } if (OptAttributes != null) { OptAttributes.Emit(); } base.Emit(); }
public virtual void ApplyAttributes(MethodBuilder mb, ConstructorBuilder cb, int index, PredefinedAttributes pa) { if (builder != null) { throw new InternalErrorException("builder already exists"); } var pattrs = ParametersCompiled.GetParameterAttribute(modFlags); if (HasOptionalExpression) { pattrs |= ParameterAttributes.Optional; } if (mb == null) { builder = cb.DefineParameter(index, pattrs, Name); } else { builder = mb.DefineParameter(index, pattrs, Name); } if (OptAttributes != null) { OptAttributes.Emit(); } if (HasDefaultValue) { // // Emit constant values for true constants only, the other // constant-like expressions will rely on default value expression // var def_value = DefaultValue; Constant c = def_value != null ? def_value.Child as Constant : default_expr as Constant; if (c != null) { if (c.Type.BuiltinType == BuiltinTypeSpec.Type.Decimal) { pa.DecimalConstant.EmitAttribute(builder, (decimal)c.GetValue(), c.Location); } else { builder.SetConstant(c.GetValue()); } } else if (default_expr.Type.IsStruct) { // // Handles special case where default expression is used with value-type // // void Foo (S s = default (S)) {} // builder.SetConstant(null); } } if (parameter_type != null) { if (parameter_type.BuiltinType == BuiltinTypeSpec.Type.Dynamic) { pa.Dynamic.EmitAttribute(builder); } else if (parameter_type.HasDynamicElement) { pa.Dynamic.EmitAttribute(builder, parameter_type, Location); } } }
public override void ApplyAttributeBuilder(Attribute a, CustomAttributeBuilder cb, PredefinedAttributes pa) { Report Report = RootContext.ToplevelTypes.Compiler.Report; if (a.Type == pa.In && ModFlags == Modifier.OUT) { Report.Error(36, a.Location, "An out parameter cannot have the `In' attribute"); return; } if (a.Type == pa.ParamArray) { Report.Error(674, a.Location, "Do not use `System.ParamArrayAttribute'. Use the `params' keyword instead"); return; } if (a.Type == PredefinedAttributes.Get.Out && (ModFlags & Modifier.REF) == Modifier.REF && !OptAttributes.Contains(pa.In)) { Report.Error(662, a.Location, "Cannot specify only `Out' attribute on a ref parameter. Use both `In' and `Out' attributes or neither"); return; } if (a.Type == pa.CLSCompliant) { Report.Warning(3022, 1, a.Location, "CLSCompliant attribute has no meaning when applied to parameters. Try putting it on the method instead"); } if (HasDefaultValue && (a.Type == pa.DefaultParameterValue || a.Type == pa.OptionalParameter)) { Report.Error(1745, a.Location, "Cannot specify `{0}' attribute on optional parameter `{1}'", TypeManager.CSharpName(a.Type).Replace("Attribute", ""), Name); return; } if (a.Type == pa.DefaultParameterValue) { object val = a.GetParameterDefaultValue(); if (val != null) { Type t = val.GetType(); if (t.IsArray || TypeManager.IsSubclassOf(t, TypeManager.type_type)) { if (parameter_type == TypeManager.object_type) { if (!t.IsArray) { t = TypeManager.type_type; } Report.Error(1910, a.Location, "Argument of type `{0}' is not applicable for the DefaultParameterValue attribute", TypeManager.CSharpName(t)); } else { Report.Error(1909, a.Location, "The DefaultParameterValue attribute is not applicable on parameters of type `{0}'", TypeManager.CSharpName(parameter_type));; } return; } } if (parameter_type == TypeManager.object_type || (val == null && !TypeManager.IsGenericParameter(parameter_type) && TypeManager.IsReferenceType(parameter_type)) || (val != null && TypeManager.TypeToCoreType(val.GetType()) == parameter_type)) { builder.SetConstant(val); } else { Report.Error(1908, a.Location, "The type of the default value should match the type of the parameter"); } return; } base.ApplyAttributeBuilder(a, cb, pa); }
public void Resolve() { if (RootContext.Unsafe) { // // Emits [assembly: SecurityPermissionAttribute (SecurityAction.RequestMinimum, SkipVerification = true)] // when -unsafe option was specified // Location loc = Location.Null; MemberAccess system_security_permissions = new MemberAccess(new MemberAccess( new QualifiedAliasMember(QualifiedAliasMember.GlobalAlias, "System", loc), "Security", loc), "Permissions", loc); Arguments pos = new Arguments(1); pos.Add(new Argument(new MemberAccess(new MemberAccess(system_security_permissions, "SecurityAction", loc), "RequestMinimum"))); Arguments named = new Arguments(1); named.Add(new NamedArgument(new LocatedToken(loc, "SkipVerification"), (new BoolLiteral(true, loc)))); GlobalAttribute g = new GlobalAttribute(new NamespaceEntry(null, null, null), "assembly", new MemberAccess(system_security_permissions, "SecurityPermissionAttribute"), new Arguments[] { pos, named }, loc, false); g.AttachTo(this, this); if (g.Resolve() != null) { declarative_security = new ListDictionary(); g.ExtractSecurityPermissionSet(declarative_security); } } if (OptAttributes == null) { return; } // Ensure that we only have GlobalAttributes, since the Search isn't safe with other types. if (!OptAttributes.CheckTargets()) { return; } ClsCompliantAttribute = ResolveAttribute(PredefinedAttributes.Get.CLSCompliant); if (ClsCompliantAttribute != null) { is_cls_compliant = ClsCompliantAttribute.GetClsCompliantAttributeValue(); } Attribute a = ResolveAttribute(PredefinedAttributes.Get.RuntimeCompatibility); if (a != null) { object val = a.GetPropertyValue("WrapNonExceptionThrows"); if (val != null) { wrap_non_exception_throws = (bool)val; } } }
public override void ApplyAttributeBuilder(Attribute a, CustomAttributeBuilder cb) { if (a.Type == TypeManager.in_attribute_type && ModFlags == Modifier.OUT) { Report.Error(36, a.Location, "An out parameter cannot have the `In' attribute"); return; } if (a.Type == TypeManager.param_array_type) { Report.Error(674, a.Location, "Do not use `System.ParamArrayAttribute'. Use the `params' keyword instead"); return; } if (a.Type == TypeManager.out_attribute_type && (ModFlags & Modifier.REF) == Modifier.REF && TypeManager.in_attribute_type != null && !OptAttributes.Contains(TypeManager.in_attribute_type)) { Report.Error(662, a.Location, "Cannot specify only `Out' attribute on a ref parameter. Use both `In' and `Out' attributes or neither"); return; } if (a.Type == TypeManager.cls_compliant_attribute_type) { Report.Warning(3022, 1, a.Location, "CLSCompliant attribute has no meaning when applied to parameters. Try putting it on the method instead"); } // TypeManager.default_parameter_value_attribute_type is null if !NET_2_0, or if System.dll is not referenced if (a.Type == TypeManager.default_parameter_value_attribute_type) { object val = a.GetParameterDefaultValue(); if (val != null) { Type t = val.GetType(); if (t.IsArray || TypeManager.IsSubclassOf(t, TypeManager.type_type)) { if (parameter_type == TypeManager.object_type) { if (!t.IsArray) { t = TypeManager.type_type; } Report.Error(1910, a.Location, "Argument of type `{0}' is not applicable for the DefaultValue attribute", TypeManager.CSharpName(t)); } else { Report.Error(1909, a.Location, "The DefaultValue attribute is not applicable on parameters of type `{0}'", TypeManager.CSharpName(parameter_type));; } return; } } if (parameter_type == TypeManager.object_type || (val == null && !TypeManager.IsValueType(parameter_type)) || (val != null && TypeManager.TypeToCoreType(val.GetType()) == parameter_type)) { builder.SetConstant(val); } else { Report.Error(1908, a.Location, "The type of the default value should match the type of the parameter"); } return; } base.ApplyAttributeBuilder(a, cb); }