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, "value");
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 ());
364 TypeManager.CheckTypeVariance (parameter_type,
365 (modFlags & Parameter.Modifier.ISBYREF) != 0 ? Variance.None : Variance.Contravariant,
368 if (texpr is TypeParameterExpr)
369 return parameter_type;
371 if ((parameter_type.Attributes & Class.StaticClassAttribute) == Class.StaticClassAttribute) {
372 Report.Error (721, Location, "`{0}': static types cannot be used as parameters",
373 texpr.GetSignatureForError ());
374 return parameter_type;
377 if ((modFlags & Modifier.This) != 0 && parameter_type.IsPointer) {
378 Report.Error (1103, Location, "The type of extension method cannot be `{0}'",
379 TypeManager.CSharpName (parameter_type));
382 return parameter_type;
385 public void ResolveVariable (int idx)
390 public bool HasExtensionMethodModifier {
391 get { return (modFlags & Modifier.This) != 0; }
394 public Modifier ModFlags {
395 get { return modFlags & ~Modifier.This; }
400 set { name = value; }
403 ParameterAttributes Attributes {
404 get { return ParametersCompiled.GetParameterAttribute (modFlags); }
407 public override AttributeTargets AttributeTargets {
409 return AttributeTargets.Parameter;
413 public virtual string GetSignatureForError ()
416 if (parameter_type != null)
417 type_name = TypeManager.CSharpName (parameter_type);
419 type_name = TypeName.GetSignatureForError ();
421 string mod = GetModifierSignature (modFlags);
423 return String.Concat (mod, " ", type_name);
428 public static string GetModifierSignature (Modifier mod)
433 case Modifier.PARAMS:
444 public void IsClsCompliant ()
446 if (AttributeTester.IsClsCompliant (parameter_type))
449 Report.Warning (3001, 1, Location, "Argument type `{0}' is not CLS-compliant", GetSignatureForError ());
452 public virtual void ApplyAttributes (MethodBuilder mb, ConstructorBuilder cb, int index)
455 builder = cb.DefineParameter (index, Attributes, Name);
457 builder = mb.DefineParameter (index, Attributes, Name);
459 if (OptAttributes != null)
460 OptAttributes.Emit ();
463 public override string[] ValidAttributeTargets {
465 return attribute_targets;
469 public Parameter Clone ()
471 Parameter p = (Parameter) MemberwiseClone ();
472 if (attributes != null) {
473 p.attributes = attributes.Clone ();
474 p.attributes.AttachTo (p);
480 public ExpressionStatement CreateExpressionTreeVariable (EmitContext ec)
483 // A parameter is not hoisted when used directly as ET
485 HoistedVariableReference = null;
487 if ((modFlags & Modifier.ISBYREF) != 0)
488 Report.Error (1951, Location, "An expression tree parameter cannot use `ref' or `out' modifier");
490 LocalInfo variable = ec.CurrentBlock.AddTemporaryVariable (
491 ResolveParameterExpressionType (ec, Location), Location);
492 variable.Resolve (ec);
494 expr_tree_variable = new LocalVariableReference (
495 ec.CurrentBlock, variable.Name, Location, variable, false);
497 ArrayList arguments = new ArrayList (2);
498 arguments.Add (new Argument (new TypeOf (
499 new TypeExpression (parameter_type, Location), Location)));
500 arguments.Add (new Argument (new StringConstant (Name, Location)));
501 return new SimpleAssign (ExpressionTreeVariableReference (),
502 Expression.CreateExpressionFactoryCall ("Parameter", null, arguments, Location));
505 public void Emit (EmitContext ec)
511 ParameterReference.EmitLdArg (ec.ig, arg_idx);
514 public void EmitAssign (EmitContext ec)
521 ec.ig.Emit (OpCodes.Starg_S, (byte) arg_idx);
523 ec.ig.Emit (OpCodes.Starg, arg_idx);
526 public void EmitAddressOf (EmitContext ec)
533 bool is_ref = (ModFlags & Modifier.ISBYREF) != 0;
535 ParameterReference.EmitLdArg (ec.ig, arg_idx);
538 ec.ig.Emit (OpCodes.Ldarga_S, (byte) arg_idx);
540 ec.ig.Emit (OpCodes.Ldarga, arg_idx);
544 public Expression ExpressionTreeVariableReference ()
546 return expr_tree_variable;
550 // System.Linq.Expressions.ParameterExpression type
552 public static TypeExpr ResolveParameterExpressionType (EmitContext ec, Location location)
554 if (parameter_expr_tree_type != null)
555 return parameter_expr_tree_type;
557 Type p_type = TypeManager.parameter_expression_type;
558 if (p_type == null) {
559 p_type = TypeManager.CoreLookupType ("System.Linq.Expressions", "ParameterExpression", Kind.Class, true);
560 TypeManager.parameter_expression_type = p_type;
563 parameter_expr_tree_type = new TypeExpression (p_type, location).
564 ResolveAsTypeTerminal (ec, false);
566 return parameter_expr_tree_type;
571 // Imported or resolved parameter information
573 public class ParameterData : IParameterData
575 readonly string name;
576 readonly Parameter.Modifier modifiers;
578 public ParameterData (string name, Parameter.Modifier modifiers)
581 this.modifiers = modifiers;
584 #region IParameterData Members
586 public bool HasExtensionMethodModifier {
587 get { return (modifiers & Parameter.Modifier.This) != 0; }
590 public Parameter.Modifier ModFlags {
591 get { return modifiers & ~Parameter.Modifier.This; }
601 public abstract class AParametersCollection
603 protected bool has_arglist;
604 protected bool has_params;
606 // Null object pattern
607 protected IParameterData [] parameters;
608 protected Type [] types;
611 get { return parameters.Length; }
614 public Type ExtensionMethodType {
619 return FixedParameters [0].HasExtensionMethodModifier ?
624 public IParameterData [] FixedParameters {
630 public static ParameterAttributes GetParameterAttribute (Parameter.Modifier modFlags)
632 return (modFlags & Parameter.Modifier.OUT) == Parameter.Modifier.OUT ?
633 ParameterAttributes.Out : ParameterAttributes.None;
636 public Type [] GetEmitTypes ()
638 Type [] types = null;
641 return Type.EmptyTypes;
643 types = new Type [Count - 1];
644 Array.Copy (Types, types, types.Length);
647 for (int i = 0; i < Count; ++i) {
648 if ((FixedParameters [i].ModFlags & Parameter.Modifier.ISBYREF) == 0)
652 types = (Type []) Types.Clone ();
654 types [i] = TypeManager.GetReferenceType (types [i]);
663 public string GetSignatureForError ()
665 StringBuilder sb = new StringBuilder ("(");
666 for (int i = 0; i < Count; ++i) {
669 sb.Append (ParameterDesc (i));
672 return sb.ToString ();
675 public bool HasArglist {
676 get { return has_arglist; }
679 public bool HasExtensionMethodType {
684 return FixedParameters [0].HasExtensionMethodModifier;
688 public bool HasParams {
689 get { return has_params; }
692 public bool IsEmpty {
693 get { return parameters.Length == 0; }
696 public string ParameterDesc (int pos)
698 if (types == null || types [pos] == null)
699 return ((Parameter)FixedParameters [pos]).GetSignatureForError ();
701 string type = TypeManager.CSharpName (types [pos]);
702 if (FixedParameters [pos].HasExtensionMethodModifier)
703 return "this " + type;
705 Parameter.Modifier mod = FixedParameters [pos].ModFlags & ~Parameter.Modifier.ARGLIST;
709 return Parameter.GetModifierSignature (mod) + " " + type;
712 public Type[] Types {
713 get { return types; }
714 set { types = value; }
718 public AParametersCollection InflateTypes (Type[] genArguments, Type[] argTypes)
720 AParametersCollection p = (AParametersCollection) MemberwiseClone (); // Clone ();
722 for (int i = 0; i < Count; ++i) {
723 if (types[i].IsGenericType) {
724 Type[] gen_arguments_open = new Type[types[i].GetGenericTypeDefinition ().GetGenericArguments ().Length];
725 Type[] gen_arguments = types[i].GetGenericArguments ();
726 for (int ii = 0; ii < gen_arguments_open.Length; ++ii) {
727 if (gen_arguments[ii].IsGenericParameter) {
728 Type t = argTypes[gen_arguments[ii].GenericParameterPosition];
729 gen_arguments_open[ii] = t;
731 gen_arguments_open[ii] = gen_arguments[ii];
734 p.types[i] = types[i].GetGenericTypeDefinition ().MakeGenericType (gen_arguments_open);
738 if (types[i].IsGenericParameter) {
739 Type gen_argument = argTypes[types[i].GenericParameterPosition];
740 p.types[i] = gen_argument;
751 // A collection of imported or resolved parameters
753 public class ParametersImported : AParametersCollection
755 ParametersImported (AParametersCollection param, Type[] types)
757 this.parameters = param.FixedParameters;
759 has_arglist = param.HasArglist;
760 has_params = param.HasParams;
763 ParametersImported (IParameterData [] parameters, Type [] types, MethodBase method, bool hasParams)
765 this.parameters = parameters;
767 has_arglist = (method.CallingConvention & CallingConventions.VarArgs) != 0;
769 this.parameters = new IParameterData [parameters.Length + 1];
770 parameters.CopyTo (this.parameters, 0);
771 this.parameters [parameters.Length] = new ArglistParameter (Location.Null);
772 this.types = new Type [types.Length + 1];
773 types.CopyTo (this.types, 0);
774 this.types [types.Length] = TypeManager.arg_iterator_type;
776 has_params = hasParams;
779 public ParametersImported (IParameterData [] param, Type[] types)
781 this.parameters = param;
785 public static AParametersCollection Create (MethodBase method)
787 return Create (method.GetParameters (), method);
791 // Generic method parameters importer, param is shared between all instances
793 public static AParametersCollection Create (AParametersCollection param, MethodBase method)
798 ParameterInfo [] pi = method.GetParameters ();
799 Type [] types = new Type [pi.Length];
800 for (int i = 0; i < types.Length; i++) {
801 Type t = pi [i].ParameterType;
803 t = TypeManager.GetElementType (t);
805 types [i] = TypeManager.TypeToCoreType (t);
808 return new ParametersImported (param, types);
812 // Imports SRE parameters
814 public static AParametersCollection Create (ParameterInfo [] pi, MethodBase method)
816 if (pi.Length == 0) {
817 if (method != null && (method.CallingConvention & CallingConventions.VarArgs) != 0)
818 return new ParametersImported (new IParameterData [0], Type.EmptyTypes, method, false);
820 return ParametersCompiled.EmptyReadOnlyParameters;
823 Type [] types = new Type [pi.Length];
824 IParameterData [] par = new IParameterData [pi.Length];
825 bool is_params = false;
826 PredefinedAttribute extension_attr = PredefinedAttributes.Get.Extension;
827 PredefinedAttribute param_attr = PredefinedAttributes.Get.ParamArray;
828 for (int i = 0; i < types.Length; i++) {
829 types [i] = TypeManager.TypeToCoreType (pi [i].ParameterType);
831 ParameterInfo p = pi [i];
832 Parameter.Modifier mod = 0;
833 if (types [i].IsByRef) {
834 if ((p.Attributes & (ParameterAttributes.Out | ParameterAttributes.In)) == ParameterAttributes.Out)
835 mod = Parameter.Modifier.OUT;
837 mod = Parameter.Modifier.REF;
840 // Strip reference wrapping
842 types [i] = TypeManager.GetElementType (types [i]);
843 } else if (i == 0 && extension_attr.IsDefined && method != null && method.IsStatic &&
844 (method.DeclaringType.Attributes & Class.StaticClassAttribute) == Class.StaticClassAttribute &&
845 method.IsDefined (extension_attr.Type, false)) {
846 mod = Parameter.Modifier.This;
847 } else if (i >= pi.Length - 2) {
848 if (types[i].IsArray) {
849 if (p.IsDefined (param_attr.Type, false)) {
850 mod = Parameter.Modifier.PARAMS;
853 } else if (types [i] == TypeManager.runtime_argument_handle_type) {
854 par [i] = new ArglistParameter (Location.Null);
859 par [i] = new ParameterData (p.Name, mod);
862 return method != null ?
863 new ParametersImported (par, types, method, is_params) :
864 new ParametersImported (par, types);
869 /// Represents the methods parameters
871 public class ParametersCompiled : AParametersCollection
873 public static readonly ParametersCompiled EmptyReadOnlyParameters = new ParametersCompiled ();
875 // Used by C# 2.0 delegates
876 public static readonly ParametersCompiled Undefined = new ParametersCompiled ();
878 private ParametersCompiled ()
880 parameters = new Parameter [0];
881 types = Type.EmptyTypes;
884 private ParametersCompiled (Parameter [] parameters, Type [] types)
886 this.parameters = parameters;
890 public ParametersCompiled (params Parameter[] parameters)
892 if (parameters == null)
893 throw new ArgumentException ("Use EmptyReadOnlyParameters");
895 this.parameters = parameters;
896 int count = parameters.Length;
902 has_params = (parameters [0].ModFlags & Parameter.Modifier.PARAMS) != 0;
906 for (int i = 0; i < count; i++){
907 string base_name = parameters [i].Name;
908 has_params |= (parameters [i].ModFlags & Parameter.Modifier.PARAMS) != 0;
910 for (int j = i + 1; j < count; j++){
911 if (base_name != parameters [j].Name)
914 ErrorDuplicateName (parameters [i]);
920 public ParametersCompiled (Parameter [] parameters, bool has_arglist) :
923 this.has_arglist = has_arglist;
926 public static ParametersCompiled CreateFullyResolved (Parameter p, Type type)
928 return new ParametersCompiled (new Parameter [] { p }, new Type [] { type });
931 public static ParametersCompiled CreateFullyResolved (Parameter[] parameters, Type[] types)
933 return new ParametersCompiled (parameters, types);
936 public static ParametersCompiled MergeGenerated (ParametersCompiled userParams, bool checkConflicts, Parameter compilerParams, Type compilerTypes)
938 return MergeGenerated (userParams, checkConflicts,
939 new Parameter [] { compilerParams },
940 new Type [] { compilerTypes });
944 // Use this method when you merge compiler generated parameters with user parameters
946 public static ParametersCompiled MergeGenerated (ParametersCompiled userParams, bool checkConflicts, Parameter[] compilerParams, Type[] compilerTypes)
948 Parameter[] all_params = new Parameter [userParams.Count + compilerParams.Length];
949 userParams.FixedParameters.CopyTo(all_params, 0);
952 if (userParams.types != null) {
953 all_types = new Type [all_params.Length];
954 userParams.Types.CopyTo (all_types, 0);
959 int last_filled = userParams.Count;
961 foreach (Parameter p in compilerParams) {
962 for (int i = 0; i < last_filled; ++i) {
963 while (p.Name == all_params [i].Name) {
964 if (checkConflicts && i < userParams.Count) {
965 Report.Error (316, userParams [i].Location,
966 "The parameter name `{0}' conflicts with a compiler generated name", p.Name);
968 p.Name = '_' + p.Name;
971 all_params [last_filled] = p;
972 if (all_types != null)
973 all_types [last_filled] = compilerTypes [index++];
977 ParametersCompiled parameters = new ParametersCompiled (all_params, all_types);
978 parameters.has_params = userParams.has_params;
982 protected virtual void ErrorDuplicateName (Parameter p)
984 Report.Error (100, p.Location, "The parameter name `{0}' is a duplicate", p.Name);
988 /// Returns the parameter information based on the name
990 public int GetParameterIndexByName (string name)
992 for (int idx = 0; idx < Count; ++idx) {
993 if (parameters [idx].Name == name)
1000 public bool Resolve (IResolveContext ec)
1005 types = new Type [Count];
1009 for (int i = 0; i < FixedParameters.Length; ++i) {
1011 Type t = p.Resolve (ec);
1023 public void ResolveVariable ()
1025 for (int i = 0; i < FixedParameters.Length; ++i) {
1026 this [i].ResolveVariable (i);
1030 public CallingConventions CallingConvention
1034 return CallingConventions.VarArgs;
1036 return CallingConventions.Standard;
1040 // Define each type attribute (in/out/ref) and
1041 // the argument names.
1042 public void ApplyAttributes (MethodBase builder)
1047 MethodBuilder mb = builder as MethodBuilder;
1048 ConstructorBuilder cb = builder as ConstructorBuilder;
1050 for (int i = 0; i < Count; i++) {
1051 this [i].ApplyAttributes (mb, cb, i + 1);
1055 public void VerifyClsCompliance ()
1057 foreach (Parameter p in FixedParameters)
1058 p.IsClsCompliant ();
1061 public Parameter this [int pos] {
1062 get { return (Parameter) parameters [pos]; }
1065 public Expression CreateExpressionTree (EmitContext ec, Location loc)
1067 ArrayList initializers = new ArrayList (Count);
1068 foreach (Parameter p in FixedParameters) {
1070 // Each parameter expression is stored to local variable
1071 // to save some memory when referenced later.
1073 StatementExpression se = new StatementExpression (p.CreateExpressionTreeVariable (ec));
1074 if (se.Resolve (ec))
1075 ec.CurrentBlock.AddScopeStatement (se);
1077 initializers.Add (p.ExpressionTreeVariableReference ());
1080 return new ArrayCreation (
1081 Parameter.ResolveParameterExpressionType (ec, loc),
1082 "[]", initializers, loc);
1085 public ParametersCompiled Clone ()
1087 ParametersCompiled p = (ParametersCompiled) MemberwiseClone ();
1089 p.parameters = new IParameterData [parameters.Length];
1090 for (int i = 0; i < Count; ++i)
1091 p.parameters [i] = this [i].Clone ();