本文整理汇总了C#中Mono.CSharp.Parameter类的典型用法代码示例。如果您正苦于以下问题:C# Parameter类的具体用法?C# Parameter怎么用?C# Parameter使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Parameter类属于Mono.CSharp命名空间,在下文中一共展示了Parameter类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Create
public static AnonymousTypeClass Create (CompilerContext ctx, TypeContainer parent, IList<AnonymousTypeParameter> parameters, Location loc)
{
string name = ClassNamePrefix + types_counter++;
SimpleName [] t_args = new SimpleName [parameters.Count];
TypeParameterName [] t_params = new TypeParameterName [parameters.Count];
Parameter [] ctor_params = new Parameter [parameters.Count];
for (int i = 0; i < parameters.Count; ++i) {
AnonymousTypeParameter p = (AnonymousTypeParameter) parameters [i];
t_args [i] = new SimpleName ("<" + p.Name + ">__T", p.Location);
t_params [i] = new TypeParameterName (t_args [i].Name, null, p.Location);
ctor_params [i] = new Parameter (t_args [i], p.Name, 0, null, p.Location);
}
//
// Create generic anonymous type host with generic arguments
// named upon properties names
//
AnonymousTypeClass a_type = new AnonymousTypeClass (parent.NamespaceEntry.SlaveDeclSpace,
new MemberName (name, new TypeArguments (t_params), loc), parameters, loc);
if (parameters.Count > 0)
a_type.SetParameterInfo (null);
Constructor c = new Constructor (a_type, name, Modifiers.PUBLIC | Modifiers.DEBUGGER_HIDDEN,
null, new AnonymousParameters (ctx, ctor_params), null, loc);
c.Block = new ToplevelBlock (ctx, c.ParameterInfo, loc);
//
// Create fields and contructor body with field initialization
//
bool error = false;
for (int i = 0; i < parameters.Count; ++i) {
AnonymousTypeParameter p = (AnonymousTypeParameter) parameters [i];
Field f = new Field (a_type, t_args [i], Modifiers.PRIVATE | Modifiers.READONLY,
new MemberName ("<" + p.Name + ">", p.Location), null);
if (!a_type.AddField (f)) {
error = true;
continue;
}
c.Block.AddStatement (new StatementExpression (
new SimpleAssign (new MemberAccess (new This (p.Location), f.Name),
c.Block.GetParameterReference (p.Name, p.Location))));
ToplevelBlock get_block = new ToplevelBlock (ctx, p.Location);
get_block.AddStatement (new Return (
new MemberAccess (new This (p.Location), f.Name), p.Location));
Property prop = new Property (a_type, t_args [i], Modifiers.PUBLIC,
new MemberName (p.Name, p.Location), null);
prop.Get = new Property.GetMethod (prop, 0, null, p.Location);
prop.Get.Block = get_block;
a_type.AddProperty (prop);
}
if (error)
return null;
a_type.AddConstructor (c);
return a_type;
}
示例2: CreateSiteType
TypeExpr CreateSiteType(CompilerContext ctx, Arguments arguments, int dyn_args_count, bool is_statement)
{
int default_args = is_statement ? 1 : 2;
bool has_ref_out_argument = false;
FullNamedExpression[] targs = new FullNamedExpression[dyn_args_count + default_args];
targs [0] = new TypeExpression (TypeManager.call_site_type, loc);
for (int i = 0; i < dyn_args_count; ++i) {
TypeSpec arg_type;
Argument a = arguments [i];
if (a.Type == TypeManager.null_type)
arg_type = TypeManager.object_type;
else
arg_type = a.Type;
if (a.ArgType == Argument.AType.Out || a.ArgType == Argument.AType.Ref)
has_ref_out_argument = true;
targs [i + 1] = new TypeExpression (arg_type, loc);
}
TypeExpr del_type = null;
if (!has_ref_out_argument) {
string d_name = is_statement ? "Action" : "Func";
TypeSpec t = TypeManager.CoreLookupType (ctx, "System", d_name, dyn_args_count + default_args, MemberKind.Delegate, false);
if (t != null) {
if (!is_statement)
targs [targs.Length - 1] = new TypeExpression (type, loc);
del_type = new GenericTypeExpr (t, new TypeArguments (targs), loc);
}
}
//
// Create custom delegate when no appropriate predefined one is found
//
if (del_type == null) {
TypeSpec rt = is_statement ? TypeManager.void_type : type;
Parameter[] p = new Parameter [dyn_args_count + 1];
p[0] = new Parameter (targs [0], "p0", Parameter.Modifier.NONE, null, loc);
for (int i = 1; i < dyn_args_count + 1; ++i)
p[i] = new Parameter (targs[i], "p" + i.ToString ("X"), arguments[i - 1].Modifier, null, loc);
TypeContainer parent = CreateSiteContainer ();
Delegate d = new Delegate (parent.NamespaceEntry, parent, new TypeExpression (rt, loc),
Modifiers.INTERNAL | Modifiers.COMPILER_GENERATED,
new MemberName ("Container" + container_counter++.ToString ("X")),
new ParametersCompiled (ctx, p), null);
d.CreateType ();
d.DefineType ();
d.Define ();
d.Emit ();
parent.AddDelegate (d);
del_type = new TypeExpression (d.Definition, loc);
}
TypeExpr site_type = new GenericTypeExpr (TypeManager.generic_call_site_type, new TypeArguments (del_type), loc);
return site_type;
}
示例3: ResolveParameters
protected virtual ParametersCompiled ResolveParameters (ResolveContext ec, TypeInferenceContext tic, TypeSpec delegate_type)
{
var delegate_parameters = Delegate.GetParameters (delegate_type);
if (Parameters == ParametersCompiled.Undefined) {
//
// We provide a set of inaccessible parameters
//
Parameter[] fixedpars = new Parameter[delegate_parameters.Count];
for (int i = 0; i < delegate_parameters.Count; i++) {
Parameter.Modifier i_mod = delegate_parameters.FixedParameters [i].ModFlags;
if ((i_mod & Parameter.Modifier.OUT) != 0) {
if (!ec.IsInProbingMode) {
ec.Report.Error (1688, loc,
"Cannot convert anonymous method block without a parameter list to delegate type `{0}' because it has one or more `out' parameters",
delegate_type.GetSignatureForError ());
}
return null;
}
fixedpars[i] = new Parameter (
new TypeExpression (delegate_parameters.Types [i], loc), null,
delegate_parameters.FixedParameters [i].ModFlags, null, loc);
}
return ParametersCompiled.CreateFullyResolved (fixedpars, delegate_parameters.Types);
}
if (!VerifyExplicitParameters (ec, delegate_type, delegate_parameters)) {
return null;
}
return Parameters;
}
示例4: Resolve
public void Resolve (ResolveContext rc, Parameter p)
{
var expr = Resolve (rc);
if (expr == null) {
this.expr = ErrorExpression.Instance;
return;
}
expr = Child;
if (!(expr is Constant || expr is DefaultValueExpression || (expr is New && ((New) expr).IsDefaultStruct))) {
rc.Report.Error (1736, Location,
"The expression being assigned to optional parameter `{0}' must be a constant or default value",
p.Name);
return;
}
var parameter_type = p.Type;
if (type == parameter_type)
return;
var res = Convert.ImplicitConversionStandard (rc, expr, parameter_type, Location);
if (res != null) {
if (parameter_type.IsNullableType && res is Nullable.Wrap) {
Nullable.Wrap wrap = (Nullable.Wrap) res;
res = wrap.Child;
if (!(res is Constant)) {
rc.Report.Error (1770, Location,
"The expression being assigned to nullable optional parameter `{0}' must be default value",
p.Name);
return;
}
}
if (!expr.IsNull && TypeSpec.IsReferenceType (parameter_type) && parameter_type.BuiltinType != BuiltinTypeSpec.Type.String) {
rc.Report.Error (1763, Location,
"Optional parameter `{0}' of type `{1}' can only be initialized with `null'",
p.Name, parameter_type.GetSignatureForError ());
return;
}
this.expr = res;
return;
}
rc.Report.Error (1750, Location,
"Optional parameter expression of type `{0}' cannot be converted to parameter type `{1}'",
type.GetSignatureForError (), parameter_type.GetSignatureForError ());
this.expr = ErrorExpression.Instance;
}
示例5: ParameterData
public ParameterData (string name, Parameter.Modifier modifiers, Expression defaultValue)
: this (name, modifiers)
{
this.default_value = defaultValue;
}
示例6: CreateFullyResolved
public static ParametersCompiled CreateFullyResolved (Parameter p, TypeSpec type)
{
return new ParametersCompiled (new Parameter [] { p }, new TypeSpec [] { type });
}
示例7: MergeGenerated
public static ParametersCompiled MergeGenerated (CompilerContext ctx, ParametersCompiled userParams, bool checkConflicts, Parameter compilerParams, TypeSpec compilerTypes)
{
return MergeGenerated (ctx, userParams, checkConflicts,
new Parameter [] { compilerParams },
new TypeSpec [] { compilerTypes });
}
示例8: case_178
void case_178()
#line 1580 "cs-parser.jay"
{
Error_SyntaxError (yyToken);
Location l = GetLocation (yyVals[0+yyTop]);
yyVal = new Parameter (null, null, Parameter.Modifier.NONE, (Attributes) yyVals[-1+yyTop], l);
}
示例9: case_179
void case_179()
#line 1589 "cs-parser.jay"
{
Error_SyntaxError (yyToken);
Location l = GetLocation (yyVals[0+yyTop]);
yyVal = new Parameter ((FullNamedExpression) yyVals[-1+yyTop], null, (Parameter.Modifier) yyVals[-2+yyTop], (Attributes) yyVals[-3+yyTop], l);
lbag.AddLocation (yyVal, parameterModifierLocation);
}
示例10: case_176
void case_176()
#line 1564 "cs-parser.jay"
{
var lt = (LocatedToken) yyVals[0+yyTop];
yyVal = new Parameter ((FullNamedExpression) yyVals[-1+yyTop], lt.Value, (Parameter.Modifier) yyVals[-2+yyTop], (Attributes) yyVals[-3+yyTop], lt.Location);
lbag.AddLocation (yyVal, parameterModifierLocation);
}
示例11: case_177
void case_177()
#line 1573 "cs-parser.jay"
{
var lt = (LocatedToken) yyVals[-2+yyTop];
report.Error (1552, lt.Location, "Array type specifier, [], must appear before parameter name");
yyVal = new Parameter ((FullNamedExpression) yyVals[-3+yyTop], lt.Value, (Parameter.Modifier) yyVals[-4+yyTop], (Attributes) yyVals[-5+yyTop], lt.Location);
lbag.AddLocation (yyVal, parameterModifierLocation);
}
示例12: Error_DuplicateParameterModifier
void Error_DuplicateParameterModifier (Location loc, Parameter.Modifier mod)
{
report.Error (1107, loc, "Duplicate parameter modifier `{0}'",
Parameter.GetModifierSignature (mod));
}
示例13: DocumentationParameter
public DocumentationParameter (Parameter.Modifier modifier, FullNamedExpression type)
: this (type)
{
this.Modifier = modifier;
}
示例14: DefineAsyncMethods
void DefineAsyncMethods (CallingConventions cc)
{
//
// BeginInvoke
//
ParametersCompiled async_parameters;
if (Parameters.Count == 0) {
async_parameters = ParametersCompiled.EmptyReadOnlyParameters;
} else {
var compiled = new Parameter[Parameters.Count];
for (int i = 0; i < compiled.Length; ++i)
compiled[i] = new Parameter (new TypeExpression (Parameters.Types[i], Location),
Parameters.FixedParameters[i].Name,
Parameters.FixedParameters[i].ModFlags & (Parameter.Modifier.REF | Parameter.Modifier.OUT),
null, Location);
async_parameters = new ParametersCompiled (compiled);
}
async_parameters = ParametersCompiled.MergeGenerated (Compiler, async_parameters, false,
new Parameter[] {
new Parameter (new TypeExpression (TypeManager.asynccallback_type, Location), "callback", Parameter.Modifier.NONE, null, Location),
new Parameter (new TypeExpression (TypeManager.object_type, Location), "object", Parameter.Modifier.NONE, null, Location)
},
new [] {
TypeManager.asynccallback_type,
TypeManager.object_type
}
);
BeginInvokeBuilder = new Method (this, null,
new TypeExpression (TypeManager.iasyncresult_type, Location), MethodModifiers,
new MemberName ("BeginInvoke"), async_parameters, null);
BeginInvokeBuilder.Define ();
//
// EndInvoke is a bit more interesting, all the parameters labeled as
// out or ref have to be duplicated here.
//
//
// Define parameters, and count out/ref parameters
//
ParametersCompiled end_parameters;
int out_params = 0;
foreach (Parameter p in Parameters.FixedParameters) {
if ((p.ModFlags & Parameter.Modifier.ISBYREF) != 0)
++out_params;
}
if (out_params > 0) {
var end_param_types = new TypeSpec [out_params];
Parameter[] end_params = new Parameter[out_params];
int param = 0;
for (int i = 0; i < Parameters.FixedParameters.Length; ++i) {
Parameter p = Parameters [i];
if ((p.ModFlags & Parameter.Modifier.ISBYREF) == 0)
continue;
end_param_types[param] = Parameters.Types[i];
end_params[param] = p;
++param;
}
end_parameters = ParametersCompiled.CreateFullyResolved (end_params, end_param_types);
} else {
end_parameters = ParametersCompiled.EmptyReadOnlyParameters;
}
end_parameters = ParametersCompiled.MergeGenerated (Compiler, end_parameters, false,
new Parameter (
new TypeExpression (TypeManager.iasyncresult_type, Location),
"result", Parameter.Modifier.NONE, null, Location),
TypeManager.iasyncresult_type);
//
// Create method, define parameters, register parameters with type system
//
EndInvokeBuilder = new Method (this, null, ReturnType, MethodModifiers, new MemberName ("EndInvoke"), end_parameters, null);
EndInvokeBuilder.Define ();
}
示例15: ParametersCompiled
private ParametersCompiled ()
{
parameters = new Parameter [0];
types = TypeSpec.EmptyTypes;
}