public virtual Constant CreateConstantReference(Location loc) { if (value == null) { return(null); } return(Constant.CreateConstant(value.Type, value.GetValue(), loc)); }
public Constant CreateConstantReference(Location loc) { return(Constant.CreateConstant(TypeManager.TypeToCoreType(fi.FieldType), value, loc)); }
// // 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)); }