2 // parameter.cs: Parameter definition.
4 // Author: Miguel de Icaza (miguel@gnu.org)
5 // Marek Safar (marek.safar@seznam.cz)
7 // Dual licensed under the terms of the MIT X11 or GNU GPL
9 // Copyright 2001-2003 Ximian, Inc (http://www.ximian.com)
10 // Copyright 2003-2008 Novell, Inc.
14 using System.Reflection;
15 using System.Reflection.Emit;
16 using System.Collections;
19 namespace Mono.CSharp {
22 /// Abstract Base class for parameters of a method.
24 public abstract class ParameterBase : Attributable {
26 protected ParameterBuilder builder;
28 protected ParameterBase (Attributes attrs)
33 public override void ApplyAttributeBuilder (Attribute a, CustomAttributeBuilder cb, PredefinedAttributes pa)
36 if (a.Type == pa.MarshalAs) {
37 UnmanagedMarshal marshal = a.GetMarshal (this);
38 if (marshal != null) {
39 builder.SetMarshal (marshal);
44 if (a.HasSecurityAttribute) {
45 a.Error_InvalidSecurityParent ();
49 builder.SetCustomAttribute (cb);
52 public override bool IsClsComplianceRequired()
59 /// Class for applying custom attributes on the return type
61 public class ReturnParameter : ParameterBase {
62 public ReturnParameter (MethodBuilder mb, Location location):
66 builder = mb.DefineParameter (0, ParameterAttributes.None, "");
68 catch (ArgumentOutOfRangeException) {
69 Report.RuntimeMissingSupport (location, "custom attributes on the return type");
73 public override void ApplyAttributeBuilder (Attribute a, CustomAttributeBuilder cb, PredefinedAttributes pa)
75 if (a.Type == pa.CLSCompliant) {
76 Report.Warning (3023, 1, a.Location, "CLSCompliant attribute has no meaning when applied to return types. Try putting it on the method instead");
79 // This occurs after Warning -28
83 base.ApplyAttributeBuilder (a, cb, pa);
86 public override AttributeTargets AttributeTargets {
88 return AttributeTargets.ReturnValue;
92 public override IResolveContext ResolveContext {
94 throw new NotSupportedException ();
101 public override string[] ValidAttributeTargets {
109 /// Class for applying custom attributes on the implicit parameter type
110 /// of the 'set' method in properties, and the 'add' and 'remove' methods in events.
113 // TODO: should use more code from Parameter.ApplyAttributeBuilder
114 public class ImplicitParameter : ParameterBase {
115 public ImplicitParameter (MethodBuilder mb):
118 builder = mb.DefineParameter (1, ParameterAttributes.None, "");
121 public override AttributeTargets AttributeTargets {
123 return AttributeTargets.Parameter;
127 public override IResolveContext ResolveContext {
129 throw new NotSupportedException ();
136 public override string[] ValidAttributeTargets {
143 public class ImplicitLambdaParameter : Parameter
145 public ImplicitLambdaParameter (string name, Location loc)
146 : base (null, name, Modifier.NONE, null, loc)
150 public override Type Resolve (IResolveContext ec)
152 if (parameter_type == null)
153 throw new InternalErrorException ("A type of implicit lambda parameter `{0}' is not set",
156 return parameter_type;
160 set { parameter_type = value; }
164 public class ParamsParameter : Parameter {
165 public ParamsParameter (FullNamedExpression type, string name, Attributes attrs, Location loc):
166 base (type, name, Parameter.Modifier.PARAMS, attrs, loc)
170 public override Type Resolve (IResolveContext ec)
172 if (base.Resolve (ec) == null)
175 if (!parameter_type.IsArray || parameter_type.GetArrayRank () != 1) {
176 Report.Error (225, Location, "The params parameter must be a single dimensional array");
180 return parameter_type;
183 public override void ApplyAttributes (MethodBuilder mb, ConstructorBuilder cb, int index)
185 base.ApplyAttributes (mb, cb, index);
186 PredefinedAttributes.Get.ParamArray.EmitAttribute (builder, Location);
190 public class ArglistParameter : Parameter {
191 // Doesn't have proper type because it's never chosen for better conversion
192 public ArglistParameter (Location loc) :
193 base (null, String.Empty, Parameter.Modifier.ARGLIST, null, loc)
197 public override void ApplyAttributes (MethodBuilder mb, ConstructorBuilder cb, int index)
202 public override bool CheckAccessibility (InterfaceMemberBase member)
207 public override Type Resolve (IResolveContext ec)
209 return typeof (ArglistParameter);
212 public override string GetSignatureForError ()
218 public interface IParameterData
220 bool HasExtensionMethodModifier { get; }
221 Parameter.Modifier ModFlags { get; }
226 // Parameter information created by parser
228 public class Parameter : ParameterBase, IParameterData, ILocalVariable {
230 public enum Modifier : byte {
232 REF = REFMASK | ISBYREF,
233 OUT = OUTMASK | ISBYREF,
235 // This is a flag which says that it's either REF or OUT.
243 static string[] attribute_targets = new string [] { "param" };
245 protected FullNamedExpression TypeName;
246 readonly Modifier modFlags;
248 protected Type parameter_type;
249 public readonly Location Location;
251 public bool HasAddressTaken;
253 IResolveContext resolve_context;
254 LocalVariableReference expr_tree_variable;
255 static TypeExpr parameter_expr_tree_type;
257 public HoistedVariable HoistedVariableReference;
259 public Parameter (FullNamedExpression type, string name, Modifier mod, Attributes attrs, Location loc)
262 if (type == TypeManager.system_void_expr)
263 Report.Error (1536, loc, "Invalid parameter type `void'");
271 public override void ApplyAttributeBuilder (Attribute a, CustomAttributeBuilder cb, PredefinedAttributes pa)
273 if (a.Type == pa.In && ModFlags == Modifier.OUT) {
274 Report.Error (36, a.Location, "An out parameter cannot have the `In' attribute");
278 if (a.Type == pa.ParamArray) {
279 Report.Error (674, a.Location, "Do not use `System.ParamArrayAttribute'. Use the `params' keyword instead");
283 if (a.Type == PredefinedAttributes.Get.Out && (ModFlags & Modifier.REF) == Modifier.REF &&
284 !OptAttributes.Contains (pa.In)) {
285 Report.Error (662, a.Location,
286 "Cannot specify only `Out' attribute on a ref parameter. Use both `In' and `Out' attributes or neither");
290 if (a.Type == pa.CLSCompliant) {
291 Report.Warning (3022, 1, a.Location, "CLSCompliant attribute has no meaning when applied to parameters. Try putting it on the method instead");
294 // TypeManager.default_parameter_value_attribute_type is null if !NET_2_0, or if System.dll is not referenced
295 if (a.Type == pa.DefaultParameterValue) {
296 object val = a.GetParameterDefaultValue ();
298 Type t = val.GetType ();
299 if (t.IsArray || TypeManager.IsSubclassOf (t, TypeManager.type_type)) {
300 if (parameter_type == TypeManager.object_type) {
302 t = TypeManager.type_type;
304 Report.Error (1910, a.Location, "Argument of type `{0}' is not applicable for the DefaultValue attribute",
305 TypeManager.CSharpName (t));
307 Report.Error (1909, a.Location, "The DefaultValue attribute is not applicable on parameters of type `{0}'",
308 TypeManager.CSharpName (parameter_type)); ;
314 if (parameter_type == TypeManager.object_type ||
315 (val == null && !TypeManager.IsGenericParameter (parameter_type) && TypeManager.IsReferenceType (parameter_type)) ||
316 (val != null && TypeManager.TypeToCoreType (val.GetType ()) == parameter_type))
317 builder.SetConstant (val);
319 Report.Error (1908, a.Location, "The type of the default value should match the type of the parameter");
323 base.ApplyAttributeBuilder (a, cb, pa);
326 public virtual bool CheckAccessibility (InterfaceMemberBase member)
328 if (parameter_type == null || TypeManager.IsGenericParameter (parameter_type))
331 return member.IsAccessibleAs (parameter_type);
334 public override IResolveContext ResolveContext {
336 return resolve_context;
341 // Resolve is used in method definitions
343 public virtual Type Resolve (IResolveContext ec)
345 // HACK: to resolve attributes correctly
346 this.resolve_context = ec;
348 if (parameter_type != null)
349 return parameter_type;
351 TypeExpr texpr = TypeName.ResolveAsTypeTerminal (ec, false);
355 parameter_type = texpr.Type;
357 if ((modFlags & Parameter.Modifier.ISBYREF) != 0 &&
358 TypeManager.IsSpecialType (parameter_type)) {
359 Report.Error (1601, Location, "Method or delegate parameter cannot be of type `{0}'",
360 GetSignatureForError ());
365 if (parameter_type.IsGenericParameter) {
366 AbstractPropertyEventMethod accessor = ec as AbstractPropertyEventMethod;
367 if (accessor == null || !accessor.IsDummy) {
368 if ((parameter_type.GenericParameterAttributes & GenericParameterAttributes.Covariant) != 0) {
369 Report.Error (-38, Location, "Covariant type parameters cannot be used as method parameters");
371 } else if ((ModFlags & Modifier.ISBYREF) != 0 &&
372 (parameter_type.GenericParameterAttributes & GenericParameterAttributes.Contravariant) != 0) {
373 Report.Error (-37, Location, "Contravariant type parameters cannot be used in output positions");
377 return parameter_type;
381 if ((parameter_type.Attributes & Class.StaticClassAttribute) == Class.StaticClassAttribute) {
382 Report.Error (721, Location, "`{0}': static types cannot be used as parameters",
383 texpr.GetSignatureForError ());
384 return parameter_type;
387 if ((modFlags & Modifier.This) != 0 && parameter_type.IsPointer) {
388 Report.Error (1103, Location, "The type of extension method cannot be `{0}'",
389 TypeManager.CSharpName (parameter_type));
392 return parameter_type;
395 public void ResolveVariable (int idx)
400 public bool HasExtensionMethodModifier {
401 get { return (modFlags & Modifier.This) != 0; }
404 public Modifier ModFlags {
405 get { return modFlags & ~Modifier.This; }
410 set { name = value; }
413 ParameterAttributes Attributes {
414 get { return ParametersCompiled.GetParameterAttribute (modFlags); }
417 public override AttributeTargets AttributeTargets {
419 return AttributeTargets.Parameter;
423 public virtual string GetSignatureForError ()
426 if (parameter_type != null)
427 type_name = TypeManager.CSharpName (parameter_type);
429 type_name = TypeName.GetSignatureForError ();
431 string mod = GetModifierSignature (modFlags);
433 return String.Concat (mod, " ", type_name);
438 public static string GetModifierSignature (Modifier mod)
443 case Modifier.PARAMS:
454 public void IsClsCompliant ()
456 if (AttributeTester.IsClsCompliant (parameter_type))
459 Report.Warning (3001, 1, Location, "Argument type `{0}' is not CLS-compliant", GetSignatureForError ());
462 public virtual void ApplyAttributes (MethodBuilder mb, ConstructorBuilder cb, int index)
465 builder = cb.DefineParameter (index, Attributes, Name);
467 builder = mb.DefineParameter (index, Attributes, Name);
469 if (OptAttributes != null)
470 OptAttributes.Emit ();
473 public override string[] ValidAttributeTargets {
475 return attribute_targets;
479 public Parameter Clone ()
481 Parameter p = (Parameter) MemberwiseClone ();
482 if (attributes != null) {
483 p.attributes = attributes.Clone ();
484 p.attributes.AttachTo (p);
490 public ExpressionStatement CreateExpressionTreeVariable (EmitContext ec)
493 // A parameter is not hoisted when used directly as ET
495 HoistedVariableReference = null;
497 if ((modFlags & Modifier.ISBYREF) != 0)
498 Report.Error (1951, Location, "An expression tree parameter cannot use `ref' or `out' modifier");
500 LocalInfo variable = ec.CurrentBlock.AddTemporaryVariable (
501 ResolveParameterExpressionType (ec, Location), Location);
502 variable.Resolve (ec);
504 expr_tree_variable = new LocalVariableReference (
505 ec.CurrentBlock, variable.Name, Location, variable, false);
507 ArrayList arguments = new ArrayList (2);
508 arguments.Add (new Argument (new TypeOf (
509 new TypeExpression (parameter_type, Location), Location)));
510 arguments.Add (new Argument (new StringConstant (Name, Location)));
511 return new SimpleAssign (ExpressionTreeVariableReference (),
512 Expression.CreateExpressionFactoryCall ("Parameter", null, arguments, Location));
515 public void Emit (EmitContext ec)
521 ParameterReference.EmitLdArg (ec.ig, arg_idx);
524 public void EmitAssign (EmitContext ec)
531 ec.ig.Emit (OpCodes.Starg_S, (byte) arg_idx);
533 ec.ig.Emit (OpCodes.Starg, arg_idx);
536 public void EmitAddressOf (EmitContext ec)
543 bool is_ref = (ModFlags & Modifier.ISBYREF) != 0;
545 ParameterReference.EmitLdArg (ec.ig, arg_idx);
548 ec.ig.Emit (OpCodes.Ldarga_S, (byte) arg_idx);
550 ec.ig.Emit (OpCodes.Ldarga, arg_idx);
554 public Expression ExpressionTreeVariableReference ()
556 return expr_tree_variable;
560 // System.Linq.Expressions.ParameterExpression type
562 public static TypeExpr ResolveParameterExpressionType (EmitContext ec, Location location)
564 if (parameter_expr_tree_type != null)
565 return parameter_expr_tree_type;
567 Type p_type = TypeManager.parameter_expression_type;
568 if (p_type == null) {
569 p_type = TypeManager.CoreLookupType ("System.Linq.Expressions", "ParameterExpression", Kind.Class, true);
570 TypeManager.parameter_expression_type = p_type;
573 parameter_expr_tree_type = new TypeExpression (p_type, location).
574 ResolveAsTypeTerminal (ec, false);
576 return parameter_expr_tree_type;
581 // Imported or resolved parameter information
583 public class ParameterData : IParameterData
585 readonly string name;
586 readonly Parameter.Modifier modifiers;
588 public ParameterData (string name, Parameter.Modifier modifiers)
591 this.modifiers = modifiers;
594 #region IParameterData Members
596 public bool HasExtensionMethodModifier {
597 get { return (modifiers & Parameter.Modifier.This) != 0; }
600 public Parameter.Modifier ModFlags {
601 get { return modifiers & ~Parameter.Modifier.This; }
611 public abstract class AParametersCollection
613 protected bool has_arglist;
614 protected bool has_params;
616 // Null object pattern
617 protected IParameterData [] parameters;
618 protected Type [] types;
621 get { return parameters.Length; }
624 public Type ExtensionMethodType {
629 return FixedParameters [0].HasExtensionMethodModifier ?
634 public IParameterData [] FixedParameters {
640 public static ParameterAttributes GetParameterAttribute (Parameter.Modifier modFlags)
642 return (modFlags & Parameter.Modifier.OUT) == Parameter.Modifier.OUT ?
643 ParameterAttributes.Out : ParameterAttributes.None;
646 public Type [] GetEmitTypes ()
648 Type [] types = null;
651 return Type.EmptyTypes;
653 types = new Type [Count - 1];
654 Array.Copy (Types, types, types.Length);
657 for (int i = 0; i < Count; ++i) {
658 if ((FixedParameters [i].ModFlags & Parameter.Modifier.ISBYREF) == 0)
662 types = (Type []) Types.Clone ();
664 types [i] = TypeManager.GetReferenceType (types [i]);
673 public string GetSignatureForError ()
675 StringBuilder sb = new StringBuilder ("(");
676 for (int i = 0; i < Count; ++i) {
679 sb.Append (ParameterDesc (i));
682 return sb.ToString ();
685 public bool HasArglist {
686 get { return has_arglist; }
689 public bool HasExtensionMethodType {
694 return FixedParameters [0].HasExtensionMethodModifier;
698 public bool HasParams {
699 get { return has_params; }
702 public bool IsEmpty {
703 get { return parameters.Length == 0; }
706 public string ParameterDesc (int pos)
708 if (types == null || types [pos] == null)
709 return ((Parameter)FixedParameters [pos]).GetSignatureForError ();
711 string type = TypeManager.CSharpName (types [pos]);
712 if (FixedParameters [pos].HasExtensionMethodModifier)
713 return "this " + type;
715 Parameter.Modifier mod = FixedParameters [pos].ModFlags & ~Parameter.Modifier.ARGLIST;
719 return Parameter.GetModifierSignature (mod) + " " + type;
722 public Type[] Types {
723 get { return types; }
724 set { types = value; }
728 public AParametersCollection InflateTypes (Type[] genArguments, Type[] argTypes)
730 AParametersCollection p = (AParametersCollection) MemberwiseClone (); // Clone ();
732 for (int i = 0; i < Count; ++i) {
733 if (types[i].IsGenericType) {
734 Type[] gen_arguments_open = new Type[types[i].GetGenericTypeDefinition ().GetGenericArguments ().Length];
735 Type[] gen_arguments = types[i].GetGenericArguments ();
736 for (int ii = 0; ii < gen_arguments_open.Length; ++ii) {
737 if (gen_arguments[ii].IsGenericParameter) {
738 Type t = argTypes[gen_arguments[ii].GenericParameterPosition];
739 gen_arguments_open[ii] = t;
741 gen_arguments_open[ii] = gen_arguments[ii];
744 p.types[i] = types[i].GetGenericTypeDefinition ().MakeGenericType (gen_arguments_open);
748 if (types[i].IsGenericParameter) {
749 Type gen_argument = argTypes[types[i].GenericParameterPosition];
750 p.types[i] = gen_argument;
761 // A collection of imported or resolved parameters
763 public class ParametersImported : AParametersCollection
765 ParametersImported (AParametersCollection param, Type[] types)
767 this.parameters = param.FixedParameters;
769 has_arglist = param.HasArglist;
770 has_params = param.HasParams;
773 ParametersImported (IParameterData [] parameters, Type [] types, MethodBase method, bool hasParams)
775 this.parameters = parameters;
777 has_arglist = (method.CallingConvention & CallingConventions.VarArgs) != 0;
779 this.parameters = new IParameterData [parameters.Length + 1];
780 parameters.CopyTo (this.parameters, 0);
781 this.parameters [parameters.Length] = new ArglistParameter (Location.Null);
782 this.types = new Type [types.Length + 1];
783 types.CopyTo (this.types, 0);
784 this.types [types.Length] = TypeManager.arg_iterator_type;
786 has_params = hasParams;
789 public ParametersImported (IParameterData [] param, Type[] types)
791 this.parameters = param;
795 public static AParametersCollection Create (MethodBase method)
797 return Create (method.GetParameters (), method);
801 // Generic method parameters importer, param is shared between all instances
803 public static AParametersCollection Create (AParametersCollection param, MethodBase method)
808 ParameterInfo [] pi = method.GetParameters ();
809 Type [] types = new Type [pi.Length];
810 for (int i = 0; i < types.Length; i++) {
811 Type t = pi [i].ParameterType;
813 t = TypeManager.GetElementType (t);
815 types [i] = TypeManager.TypeToCoreType (t);
818 return new ParametersImported (param, types);
822 // Imports SRE parameters
824 public static AParametersCollection Create (ParameterInfo [] pi, MethodBase method)
826 if (pi.Length == 0) {
827 if (method != null && (method.CallingConvention & CallingConventions.VarArgs) != 0)
828 return new ParametersImported (new IParameterData [0], Type.EmptyTypes, method, false);
830 return ParametersCompiled.EmptyReadOnlyParameters;
833 Type [] types = new Type [pi.Length];
834 IParameterData [] par = new IParameterData [pi.Length];
835 bool is_params = false;
836 PredefinedAttribute extension_attr = PredefinedAttributes.Get.Extension;
837 PredefinedAttribute param_attr = PredefinedAttributes.Get.ParamArray;
838 for (int i = 0; i < types.Length; i++) {
839 types [i] = TypeManager.TypeToCoreType (pi [i].ParameterType);
841 ParameterInfo p = pi [i];
842 Parameter.Modifier mod = 0;
843 if (types [i].IsByRef) {
844 if ((p.Attributes & (ParameterAttributes.Out | ParameterAttributes.In)) == ParameterAttributes.Out)
845 mod = Parameter.Modifier.OUT;
847 mod = Parameter.Modifier.REF;
850 // Strip reference wrapping
852 types [i] = TypeManager.GetElementType (types [i]);
853 } else if (i == 0 && extension_attr.IsDefined && method != null && method.IsStatic &&
854 (method.DeclaringType.Attributes & Class.StaticClassAttribute) == Class.StaticClassAttribute &&
855 method.IsDefined (extension_attr.Type, false)) {
856 mod = Parameter.Modifier.This;
857 } else if (i >= pi.Length - 2 && types [i].IsArray) {
858 if (p.IsDefined (param_attr.Type, false)) {
859 mod = Parameter.Modifier.PARAMS;
864 par [i] = new ParameterData (p.Name, mod);
867 return method != null ?
868 new ParametersImported (par, types, method, is_params) :
869 new ParametersImported (par, types);
874 /// Represents the methods parameters
876 public class ParametersCompiled : AParametersCollection
878 public static readonly ParametersCompiled EmptyReadOnlyParameters = new ParametersCompiled ();
880 // Used by C# 2.0 delegates
881 public static readonly ParametersCompiled Undefined = new ParametersCompiled ();
883 private ParametersCompiled ()
885 parameters = new Parameter [0];
886 types = Type.EmptyTypes;
889 private ParametersCompiled (Parameter [] parameters, Type [] types)
891 this.parameters = parameters;
895 public ParametersCompiled (params Parameter[] parameters)
897 if (parameters == null)
898 throw new ArgumentException ("Use EmptyReadOnlyParameters");
900 this.parameters = parameters;
901 int count = parameters.Length;
907 has_params = (parameters [0].ModFlags & Parameter.Modifier.PARAMS) != 0;
911 for (int i = 0; i < count; i++){
912 string base_name = parameters [i].Name;
913 has_params |= (parameters [i].ModFlags & Parameter.Modifier.PARAMS) != 0;
915 for (int j = i + 1; j < count; j++){
916 if (base_name != parameters [j].Name)
919 ErrorDuplicateName (parameters [i]);
925 public ParametersCompiled (Parameter [] parameters, bool has_arglist) :
928 this.has_arglist = has_arglist;
931 public static ParametersCompiled CreateFullyResolved (Parameter p, Type type)
933 return new ParametersCompiled (new Parameter [] { p }, new Type [] { type });
936 public static ParametersCompiled CreateFullyResolved (Parameter[] parameters, Type[] types)
938 return new ParametersCompiled (parameters, types);
941 public static ParametersCompiled MergeGenerated (ParametersCompiled userParams, bool checkConflicts, Parameter compilerParams, Type compilerTypes)
943 return MergeGenerated (userParams, checkConflicts,
944 new Parameter [] { compilerParams },
945 new Type [] { compilerTypes });
949 // Use this method when you merge compiler generated parameters with user parameters
951 public static ParametersCompiled MergeGenerated (ParametersCompiled userParams, bool checkConflicts, Parameter[] compilerParams, Type[] compilerTypes)
953 Parameter[] all_params = new Parameter [userParams.Count + compilerParams.Length];
954 userParams.FixedParameters.CopyTo(all_params, 0);
957 if (userParams.types != null) {
958 all_types = new Type [all_params.Length];
959 userParams.Types.CopyTo (all_types, 0);
964 int last_filled = userParams.Count;
966 foreach (Parameter p in compilerParams) {
967 for (int i = 0; i < last_filled; ++i) {
968 while (p.Name == all_params [i].Name) {
969 if (checkConflicts && i < userParams.Count) {
970 Report.Error (316, userParams [i].Location,
971 "The parameter name `{0}' conflicts with a compiler generated name", p.Name);
973 p.Name = '_' + p.Name;
976 all_params [last_filled] = p;
977 if (all_types != null)
978 all_types [last_filled] = compilerTypes [index++];
982 ParametersCompiled parameters = new ParametersCompiled (all_params, all_types);
983 parameters.has_params = userParams.has_params;
987 protected virtual void ErrorDuplicateName (Parameter p)
989 Report.Error (100, p.Location, "The parameter name `{0}' is a duplicate", p.Name);
993 /// Returns the parameter information based on the name
995 public int GetParameterIndexByName (string name)
997 for (int idx = 0; idx < Count; ++idx) {
998 if (parameters [idx].Name == name)
1005 public bool Resolve (IResolveContext ec)
1010 types = new Type [Count];
1014 for (int i = 0; i < FixedParameters.Length; ++i) {
1016 Type t = p.Resolve (ec);
1028 public void ResolveVariable ()
1030 for (int i = 0; i < FixedParameters.Length; ++i) {
1031 this [i].ResolveVariable (i);
1035 public CallingConventions CallingConvention
1039 return CallingConventions.VarArgs;
1041 return CallingConventions.Standard;
1045 // Define each type attribute (in/out/ref) and
1046 // the argument names.
1047 public void ApplyAttributes (MethodBase builder)
1052 MethodBuilder mb = builder as MethodBuilder;
1053 ConstructorBuilder cb = builder as ConstructorBuilder;
1055 for (int i = 0; i < Count; i++) {
1056 this [i].ApplyAttributes (mb, cb, i + 1);
1060 public void VerifyClsCompliance ()
1062 foreach (Parameter p in FixedParameters)
1063 p.IsClsCompliant ();
1066 public Parameter this [int pos] {
1067 get { return (Parameter) parameters [pos]; }
1070 public Expression CreateExpressionTree (EmitContext ec, Location loc)
1072 ArrayList initializers = new ArrayList (Count);
1073 foreach (Parameter p in FixedParameters) {
1075 // Each parameter expression is stored to local variable
1076 // to save some memory when referenced later.
1078 StatementExpression se = new StatementExpression (p.CreateExpressionTreeVariable (ec));
1079 if (se.Resolve (ec))
1080 ec.CurrentBlock.AddScopeStatement (se);
1082 initializers.Add (p.ExpressionTreeVariableReference ());
1085 return new ArrayCreation (
1086 Parameter.ResolveParameterExpressionType (ec, loc),
1087 "[]", initializers, loc);
1090 public ParametersCompiled Clone ()
1092 ParametersCompiled p = (ParametersCompiled) MemberwiseClone ();
1094 p.parameters = new IParameterData [parameters.Length];
1095 for (int i = 0; i < Count; ++i)
1096 p.parameters [i] = this [i].Clone ();