// // TODO: This does not fit here, it should go to different version of AParametersCollection // as the underlying type is not Parameter and some methods will fail to cast // public static AParametersCollection CreateFullyResolved(params TypeSpec[] types) { var pd = new ParameterData [types.Length]; for (int i = 0; i < pd.Length; ++i) { pd[i] = new ParameterData(null, Parameter.Modifier.NONE, null); } return(new ParametersCompiled(pd, types)); }
// // TODO: This does not fit here, it should go to different version of AParametersCollection // as the underlying type is not Parameter and some methods will fail to cast // public static AParametersCollection CreateFullyResolved (params TypeSpec[] types) { var pd = new ParameterData [types.Length]; for (int i = 0; i < pd.Length; ++i) pd[i] = new ParameterData (null, Parameter.Modifier.NONE, null); return new ParametersCompiled (pd, types); }
// // Imports System.Reflection parameters // AParametersCollection CreateParameters (TypeSpec parent, ParameterInfo[] pi, MethodBase method) { int varargs = method != null && (method.CallingConvention & CallingConventions.VarArgs) != 0 ? 1 : 0; if (pi.Length == 0 && varargs == 0) return ParametersCompiled.EmptyReadOnlyParameters; TypeSpec[] types = new TypeSpec[pi.Length + varargs]; IParameterData[] par = new IParameterData[pi.Length + varargs]; bool is_params = false; for (int i = 0; i < pi.Length; i++) { ParameterInfo p = pi[i]; Parameter.Modifier mod = 0; Expression default_value = null; if (p.ParameterType.IsByRef) { if ((p.Attributes & (ParameterAttributes.Out | ParameterAttributes.In)) == ParameterAttributes.Out) mod = Parameter.Modifier.OUT; else mod = Parameter.Modifier.REF; // // Strip reference wrapping // var el = p.ParameterType.GetElementType (); types[i] = ImportType (el, new DynamicTypeReader (p)); // TODO: 1-based positio to be csc compatible } else if (i == 0 && method.IsStatic && parent.IsStatic && parent.MemberDefinition.DeclaringAssembly.HasExtensionMethod && HasAttribute (CustomAttributeData.GetCustomAttributes (method), "ExtensionAttribute", CompilerServicesNamespace)) { mod = Parameter.Modifier.This; types[i] = ImportType (p.ParameterType); } else { types[i] = ImportType (p.ParameterType, new DynamicTypeReader (p)); if (i >= pi.Length - 2 && types[i] is ArrayContainer) { if (HasAttribute (CustomAttributeData.GetCustomAttributes (p), "ParamArrayAttribute", "System")) { mod = Parameter.Modifier.PARAMS; is_params = true; } } if (!is_params && p.IsOptional) { object value = p.RawDefaultValue; var ptype = types[i]; if ((p.Attributes & ParameterAttributes.HasDefault) != 0 && ptype.Kind != MemberKind.TypeParameter && (value != null || TypeSpec.IsReferenceType (ptype))) { if (value == null) { default_value = Constant.CreateConstant (ptype, null, Location.Null); } else { default_value = ImportParameterConstant (value); if (ptype.IsEnum) { default_value = new EnumConstant ((Constant) default_value, ptype); } } } else if (value == Missing.Value) { default_value = EmptyExpression.MissingValue; } else if (value == null) { default_value = new DefaultValueExpression (new TypeExpression (ptype, Location.Null), Location.Null); } else if (ptype.BuiltinType == BuiltinTypeSpec.Type.Decimal) { default_value = ImportParameterConstant (value); } } } 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, is_params); }
// // Imports System.Reflection parameters // public static AParametersCollection Create (TypeSpec parent, ParameterInfo [] pi, MethodBase method) { int varargs = method != null && (method.CallingConvention & CallingConventions.VarArgs) != 0 ? 1 : 0; if (pi.Length == 0 && varargs == 0) return ParametersCompiled.EmptyReadOnlyParameters; TypeSpec [] types = new TypeSpec [pi.Length + varargs]; IParameterData [] par = new IParameterData [pi.Length + varargs]; bool is_params = false; for (int i = 0; i < pi.Length; i++) { ParameterInfo p = pi [i]; Parameter.Modifier mod = 0; Expression default_value = null; if (p.ParameterType.IsByRef) { if ((p.Attributes & (ParameterAttributes.Out | ParameterAttributes.In)) == ParameterAttributes.Out) mod = Parameter.Modifier.OUT; else mod = Parameter.Modifier.REF; // // Strip reference wrapping // types [i] = Import.ImportType (p.ParameterType.GetElementType ()); } else if (i == 0 && method.IsStatic && parent.IsStatic && // TODO: parent.Assembly.IsExtension && HasExtensionAttribute (method)) { mod = Parameter.Modifier.This; types[i] = Import.ImportType (p.ParameterType); } else { types[i] = Import.ImportType (p.ParameterType); if (i >= pi.Length - 2 && types[i] is ArrayContainer) { var cattrs = CustomAttributeData.GetCustomAttributes (p); if (cattrs != null && cattrs.Any (l => l.Constructor.DeclaringType == typeof (ParamArrayAttribute))) { 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 (null, Import.ImportType (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, is_params); }
// // Imports SRE parameters // public static AParametersCollection Create (ParameterInfo [] pi, MethodBase method) { if (pi.Length == 0) { if (method != null && (method.CallingConvention & CallingConventions.VarArgs) != 0) return new ParametersCollection (new IParameterData [0], Type.EmptyTypes, method, false); return Parameters.EmptyReadOnlyParameters; } Type [] types = new Type [pi.Length]; IParameterData [] par = new IParameterData [pi.Length]; bool is_params = false; for (int i = 0; i < types.Length; i++) { types [i] = TypeManager.TypeToCoreType (pi [i].ParameterType); ParameterInfo p = pi [i]; Parameter.Modifier mod = 0; 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 && TypeManager.extension_attribute_type != null && method != null && method.IsStatic && (method.DeclaringType.Attributes & Class.StaticClassAttribute) == Class.StaticClassAttribute && method.IsDefined (TypeManager.extension_attribute_type, false)) { mod = Parameter.Modifier.This; } else if (i >= pi.Length - 2 && types [i].IsArray) { if (p.IsDefined (TypeManager.param_array_type, false)) { mod = Parameter.Modifier.PARAMS; is_params = true; } } par [i] = new ParameterData (p.Name, mod); } return method != null ? new ParametersCollection (par, types, method, is_params) : new ParametersCollection (par, types); }
// // 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)); }
// // 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); }
// // Imports System.Reflection parameters // AParametersCollection CreateParameters (TypeSpec parent, ParameterInfo[] pi, MethodBase method) { int varargs = method != null && (method.CallingConvention & CallingConventions.VarArgs) != 0 ? 1 : 0; if (pi.Length == 0 && varargs == 0) return ParametersCompiled.EmptyReadOnlyParameters; TypeSpec[] types = new TypeSpec[pi.Length + varargs]; IParameterData[] par = new IParameterData[pi.Length + varargs]; bool is_params = false; for (int i = 0; i < pi.Length; i++) { ParameterInfo p = pi[i]; Parameter.Modifier mod = 0; Expression default_value = null; if (p.ParameterType.IsByRef) { if ((p.Attributes & (ParameterAttributes.Out | ParameterAttributes.In)) == ParameterAttributes.Out) mod = Parameter.Modifier.OUT; else mod = Parameter.Modifier.REF; // // Strip reference wrapping // var el = p.ParameterType.GetElementType (); types[i] = ImportType (el, p, 0); // TODO: 1 to be csc compatible } else if (i == 0 && method.IsStatic && parent.IsStatic && parent.MemberDefinition.DeclaringAssembly.HasExtensionMethod && HasExtensionAttribute (CustomAttributeData.GetCustomAttributes (method)) != null) { mod = Parameter.Modifier.This; types[i] = ImportType (p.ParameterType); } else { types[i] = ImportType (p.ParameterType, p, 0); if (i >= pi.Length - 2 && types[i] is ArrayContainer) { if (HasAttribute (CustomAttributeData.GetCustomAttributes (p), typeof (ParamArrayAttribute))) { mod = Parameter.Modifier.PARAMS; is_params = true; } } if (!is_params && p.IsOptional) { object value = p.RawDefaultValue; var ptype = types[i]; if (((p.Attributes & ParameterAttributes.HasDefault) != 0 && ptype.Kind != MemberKind.TypeParameter)) { // // Use value type as int constant can be used for object parameter type // var dtype = value == null ? ptype : ImportType (value.GetType ()); default_value = Constant.CreateConstant (null, dtype, value, Location.Null); } else if (value == Missing.Value) { default_value = EmptyExpression.MissingValue; } else { if (ptype == TypeManager.decimal_type) default_value = ReadDecimalConstant (CustomAttributeData.GetCustomAttributes (p)); if (default_value == null) default_value = new DefaultValueExpression (new TypeExpression (ptype, Location.Null), 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, is_params); }