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 (HasDefaultValue && (a.Type == pa.DefaultParameterValue || a.Type == pa.OptionalParameter)) {
a.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) {
TypeSpec arg_type;
var c = a.GetParameterDefaultValue (out arg_type);
if (c == null) {
if (parameter_type == TypeManager.object_type) {
a.Report.Error (1910, a.Location, "Argument of type `{0}' is not applicable for the DefaultParameterValue attribute",
arg_type.GetSignatureForError ());
} else {
a.Report.Error (1909, a.Location, "The DefaultParameterValue attribute is not applicable on parameters of type `{0}'",
parameter_type.GetSignatureForError ()); ;
}
return;
}
if (arg_type == parameter_type || parameter_type == TypeManager.object_type ||
(c.IsNull && TypeManager.IsReferenceType (parameter_type) && !TypeManager.IsGenericParameter (parameter_type)))
builder.SetConstant (c.GetValue ());
else
a.Report.Error (1908, a.Location, "The type of the default value should match the type of the parameter");
return;
}
base.ApplyAttributeBuilder (a, ctor, cdata, pa);
}