本文整理汇总了C#中ArrayInitializer类的典型用法代码示例。如果您正苦于以下问题:C# ArrayInitializer类的具体用法?C# ArrayInitializer怎么用?C# ArrayInitializer使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ArrayInitializer类属于命名空间,在下文中一共展示了ArrayInitializer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: case_525
void case_525()
#line 3796 "cs-parser.jay"
{
var ai = new ArrayInitializer (0, GetLocation (yyVals[-1+yyTop]));
ai.VariableDeclaration = current_variable;
lbag.AddLocation (ai, GetLocation (yyVals[0+yyTop]));
yyVal = ai;
}
示例2: Visit
public virtual object Visit (ArrayInitializer arrayInitializer)
{
return null;
}
示例3: CreateDynamicBinderArguments
public ArrayInitializer CreateDynamicBinderArguments (ResolveContext rc)
{
Location loc = Location.Null;
var all = new ArrayInitializer (args.Count, loc);
MemberAccess binder = DynamicExpressionStatement.GetBinderNamespace (rc, loc);
foreach (Argument a in args) {
Arguments dargs = new Arguments (2);
// CSharpArgumentInfoFlags.None = 0
const string info_flags_enum = "CSharpArgumentInfoFlags";
Expression info_flags = new IntLiteral (rc.BuiltinTypes, 0, loc);
if (a.Expr is Constant) {
info_flags = new Binary (Binary.Operator.BitwiseOr, info_flags,
new MemberAccess (new MemberAccess (binder, info_flags_enum, loc), "Constant", loc));
} else if (a.ArgType == Argument.AType.Ref) {
info_flags = new Binary (Binary.Operator.BitwiseOr, info_flags,
new MemberAccess (new MemberAccess (binder, info_flags_enum, loc), "IsRef", loc));
info_flags = new Binary (Binary.Operator.BitwiseOr, info_flags,
new MemberAccess (new MemberAccess (binder, info_flags_enum, loc), "UseCompileTimeType", loc));
} else if (a.ArgType == Argument.AType.Out) {
info_flags = new Binary (Binary.Operator.BitwiseOr, info_flags,
new MemberAccess (new MemberAccess (binder, info_flags_enum, loc), "IsOut", loc));
info_flags = new Binary (Binary.Operator.BitwiseOr, info_flags,
new MemberAccess (new MemberAccess (binder, info_flags_enum, loc), "UseCompileTimeType", loc));
} else if (a.ArgType == Argument.AType.DynamicTypeName) {
info_flags = new Binary (Binary.Operator.BitwiseOr, info_flags,
new MemberAccess (new MemberAccess (binder, info_flags_enum, loc), "IsStaticType", loc));
}
TypeSpec arg_type;
if (rc.FileType == SourceFileType.PlayScript &&
a.Expr is ArrayInitializer || a.Expr is AsObjectInitializer) {
if (a.Expr is ArrayInitializer) {
arg_type = rc.Module.PredefinedTypes.AsArray.Resolve();
} else {
arg_type = rc.Module.PredefinedTypes.AsObject.Resolve();
}
} else {
arg_type = a.Expr.Type;
}
if (arg_type.BuiltinType != BuiltinTypeSpec.Type.Dynamic && arg_type != InternalType.NullLiteral) {
MethodGroupExpr mg = a.Expr as MethodGroupExpr;
bool wasConverted = false;
// In PlayScript, we try to implicity convert to dynamic, which handles conversions of method groups to delegates, and
// anon methods to delegates.
if (rc.FileType == SourceFileType.PlayScript && (mg != null || arg_type == InternalType.AnonymousMethod)) {
var expr = Convert.ImplicitConversion (rc, a.Expr, rc.BuiltinTypes.Dynamic, loc);
if (expr != null) {
a.Expr = expr;
arg_type = rc.BuiltinTypes.Dynamic;
wasConverted = true;
}
}
// Failed.. check the C# error
if (!wasConverted) {
if (mg != null) {
rc.Report.Error (1976, a.Expr.Location,
"The method group `{0}' cannot be used as an argument of dynamic operation. Consider using parentheses to invoke the method",
mg.Name);
} else if (arg_type == InternalType.AnonymousMethod) {
rc.Report.Error (1977, a.Expr.Location,
"An anonymous method or lambda expression cannot be used as an argument of dynamic operation. Consider using a cast");
} else if (arg_type.Kind == MemberKind.Void || arg_type == InternalType.Arglist || arg_type.IsPointer) {
rc.Report.Error (1978, a.Expr.Location,
"An expression of type `{0}' cannot be used as an argument of dynamic operation",
arg_type.GetSignatureForError ());
}
}
info_flags = new Binary (Binary.Operator.BitwiseOr, info_flags,
new MemberAccess (new MemberAccess (binder, info_flags_enum, loc), "UseCompileTimeType", loc));
}
string named_value;
NamedArgument na = a as NamedArgument;
if (na != null) {
info_flags = new Binary (Binary.Operator.BitwiseOr, info_flags,
new MemberAccess (new MemberAccess (binder, info_flags_enum, loc), "NamedArgument", loc));
named_value = na.Name;
} else {
named_value = null;
}
dargs.Add (new Argument (info_flags));
dargs.Add (new Argument (new StringLiteral (rc.BuiltinTypes, named_value, loc)));
all.Add (new Invocation (new MemberAccess (new MemberAccess (binder, "CSharpArgumentInfo", loc), "Create", loc), dargs));
}
return all;
}
示例4: case_524
void case_524()
#line 3574 "C:\Projects\Junk\mono\mcs\class\Mono.CSharp\..\..\mcs\cs-parser.jay"
{
var ai = new ArrayInitializer ((List<Expression>) yyVals[-2+yyTop], GetLocation (yyVals[-3+yyTop]));
ai.VariableDeclaration = current_variable;
if (yyVals[-1+yyTop] != null) {
lbag.AddLocation (ai, GetLocation (yyVals[-1+yyTop]), GetLocation (yyVals[0+yyTop]));
} else {
lbag.AddLocation (ai, GetLocation (yyVals[0+yyTop]));
}
yyVal = ai;
}
示例5: Visit
public void Visit(ArrayInitializer x)
{
}
示例6: CreateDynamicBinderArguments
public ArrayInitializer CreateDynamicBinderArguments (ResolveContext rc)
{
Location loc = Location.Null;
var all = new ArrayInitializer (args.Count, loc);
MemberAccess binder = DynamicExpressionStatement.GetBinderNamespace (loc);
foreach (Argument a in args) {
Arguments dargs = new Arguments (2);
// CSharpArgumentInfoFlags.None = 0
const string info_flags_enum = "CSharpArgumentInfoFlags";
Expression info_flags = new IntLiteral (0, loc);
var constant = a.Expr as Constant;
if (constant != null && constant.IsLiteral) {
info_flags = new Binary (Binary.Operator.BitwiseOr, info_flags,
new MemberAccess (new MemberAccess (binder, info_flags_enum, loc), "Constant", loc), loc);
} else if (a.ArgType == Argument.AType.Ref) {
info_flags = new Binary (Binary.Operator.BitwiseOr, info_flags,
new MemberAccess (new MemberAccess (binder, info_flags_enum, loc), "IsRef", loc), loc);
} else if (a.ArgType == Argument.AType.Out) {
info_flags = new Binary (Binary.Operator.BitwiseOr, info_flags,
new MemberAccess (new MemberAccess (binder, info_flags_enum, loc), "IsOut", loc), loc);
} else if (a.ArgType == Argument.AType.DynamicTypeName) {
info_flags = new Binary (Binary.Operator.BitwiseOr, info_flags,
new MemberAccess (new MemberAccess (binder, info_flags_enum, loc), "IsStaticType", loc), loc);
}
var arg_type = a.Expr.Type;
if (arg_type != InternalType.Dynamic) {
MethodGroupExpr mg = a.Expr as MethodGroupExpr;
if (mg != null) {
rc.Report.Error (1976, a.Expr.Location,
"The method group `{0}' cannot be used as an argument of dynamic operation. Consider using parentheses to invoke the method",
mg.Name);
} else if (arg_type == InternalType.AnonymousMethod) {
rc.Report.Error (1977, a.Expr.Location,
"An anonymous method or lambda expression cannot be used as an argument of dynamic operation. Consider using a cast");
} else if (arg_type == TypeManager.void_type || arg_type == InternalType.Arglist || arg_type.IsPointer) {
rc.Report.Error (1978, a.Expr.Location,
"An expression of type `{0}' cannot be used as an argument of dynamic operation",
TypeManager.CSharpName (arg_type));
}
info_flags = new Binary (Binary.Operator.BitwiseOr, info_flags,
new MemberAccess (new MemberAccess (binder, info_flags_enum, loc), "UseCompileTimeType", loc), loc);
}
string named_value;
NamedArgument na = a as NamedArgument;
if (na != null) {
info_flags = new Binary (Binary.Operator.BitwiseOr, info_flags,
new MemberAccess (new MemberAccess (binder, info_flags_enum, loc), "NamedArgument", loc), loc);
named_value = na.Name;
} else {
named_value = null;
}
dargs.Add (new Argument (info_flags));
dargs.Add (new Argument (new StringLiteral (named_value, loc)));
all.Add (new Invocation (new MemberAccess (new MemberAccess (binder, "CSharpArgumentInfo", loc), "Create", loc), dargs));
}
return all;
}
示例7: CreateCallSiteBinder
public Expression CreateCallSiteBinder(ResolveContext ec, Arguments args)
{
Arguments binder_args = new Arguments (member != null ? 5 : 3);
bool is_member_access = member is MemberAccess;
CSharpBinderFlags call_flags;
if (!is_member_access && member is SimpleName) {
call_flags = CSharpBinderFlags.InvokeSimpleName;
is_member_access = true;
} else {
call_flags = 0;
}
binder_args.Add (new Argument (new BinderFlags (call_flags, this)));
if (is_member_access)
binder_args.Add (new Argument (new StringLiteral (member.Name, member.Location)));
if (member != null && member.HasTypeArguments) {
TypeArguments ta = member.TypeArguments;
if (ta.Resolve (ec)) {
var targs = new ArrayInitializer (ta.Count, loc);
foreach (TypeSpec t in ta.Arguments)
targs.Add (new TypeOf (new TypeExpression (t, loc), loc));
binder_args.Add (new Argument (new ImplicitlyTypedArrayCreation ("[]", targs, loc)));
}
} else if (is_member_access) {
binder_args.Add (new Argument (new NullLiteral (loc)));
}
binder_args.Add (new Argument (new TypeOf (new TypeExpression (ec.CurrentType, loc), loc)));
Expression real_args;
if (args == null) {
// Cannot be null because .NET trips over
real_args = new ArrayCreation (
new MemberAccess (GetBinderNamespace (loc), "CSharpArgumentInfo", loc), "[]",
new ArrayInitializer (0, loc), loc);
} else {
real_args = new ImplicitlyTypedArrayCreation ("[]", args.CreateDynamicBinderArguments (ec), loc);
}
binder_args.Add (new Argument (real_args));
return new Invocation (GetBinder (is_member_access ? "InvokeMember" : "Invoke", loc), binder_args);
}
示例8: Visit
public override object Visit (ArrayInitializer arrayInitializer)
{
var result = new ArrayInitializerExpression ();
var location = LocationsBag.GetLocations (arrayInitializer);
var commaLocations = LocationsBag.GetLocations (arrayInitializer.Elements);
for (int i = 0; i < arrayInitializer.Count; i++) {
result.AddChild((Expression)arrayInitializer[i].Accept(this), ArrayInitializerExpression.Roles.Expression);
}
return result;
}
示例9: VisitArrayInitializer
public void VisitArrayInitializer(ArrayInitializer initializer)
{
Formatter.StartNode(initializer);
Formatter.OpenBrace(Parameters.ArrayInitializerBraceStyle);
WriteCommaSeparatedNodes(initializer.Elements, true);
Formatter.CloseBrace(Parameters.ArrayInitializerBraceStyle);
Formatter.EndNode();
}
示例10: NonVoidInitializer
IExpression NonVoidInitializer(IBlockNode Scope = null)
{
TrackerVariables.IsParsingInitializer = true;
#region ArrayInitializer
if (laKind == OpenSquareBracket)
{
Step();
// ArrayMemberInitializations
var ae = new ArrayInitializer() { Location=t.Location};
LastParsedObject = ae;
var inits=new List<ArrayMemberInitializer>();
bool IsInit = true;
while (IsInit || laKind == (Comma))
{
if (!IsInit) Step();
IsInit = false;
// Allow empty post-comma expression IF the following token finishes the initializer expression
// int[] a=[1,2,3,4,];
if (laKind == CloseSquareBracket)
break;
// ArrayMemberInitialization
var ami = new ArrayMemberInitializer()
{
Left = NonVoidInitializer(Scope)
};
LastParsedObject = ami;
bool HasBeenAssExpr = !(t.Kind == (CloseSquareBracket) || t.Kind == (CloseCurlyBrace));
// AssignExpression : NonVoidInitializer
if (HasBeenAssExpr && laKind == (Colon))
{
Step();
ami.Specialization = NonVoidInitializer(Scope);
}
inits.Add(ami);
}
ae.ArrayMemberInitializations = inits.ToArray();
Expect(CloseSquareBracket);
ae.EndLocation = t.EndLocation;
// auto i=[1,2,3].idup; // in this case, this entire thing is meant to be an AssignExpression but not a dedicated initializer..
if (laKind == Dot)
{
Step();
var ae2 = new PostfixExpression_Access();
LastParsedObject = ae2;
ae2.PostfixForeExpression = ae;
ae2.TemplateOrIdentifier = Type(); //TODO: Is it really a type!?
ae2.EndLocation = t.EndLocation;
if (!IsEOF)
TrackerVariables.IsParsingInitializer = false;
return ae2;
}
if (!IsEOF)
TrackerVariables.IsParsingInitializer = false;
return ae;
}
#endregion
// StructInitializer
if (laKind == OpenCurlyBrace)
{
// StructMemberInitializations
var ae = new StructInitializer() { Location = la.Location };
LastParsedObject = ae;
var inits = new List<StructMemberInitializer>();
bool IsInit = true;
while (IsInit || laKind == (Comma))
{
Step();
IsInit = false;
// Allow empty post-comma expression IF the following token finishes the initializer expression
// int[] a=[1,2,3,4,];
if (laKind == CloseCurlyBrace)
break;
// Identifier : NonVoidInitializer
var sinit = new StructMemberInitializer();
LastParsedObject = sinit;
if (laKind == Identifier && Lexer.CurrentPeekToken.Kind == Colon)
{
Step();
sinit.MemberName = t.Value;
Step();
}
//.........这里部分代码省略.........
示例11: Visit
public ISymbolValue Visit(ArrayInitializer x)
{
return Visit((AssocArrayExpression)x);
}
示例12: case_517
void case_517()
{
var ai = new ArrayInitializer (0, GetLocation (yyVals[-1+yyTop]));
ai.VariableDeclaration = current_variable;
lbag.AddLocation (ai, GetLocation (yyVals[0+yyTop]));
yyVal = ai;
}
示例13: ParseExpr
EXPR ParseExpr(bool isArithExpr)
{
EXPR e = null;
if (tokens[i].type == TokenType.byte_lit)
{
e = new bytelit() { value = (byte)tokens[i].val };
i++;
}
else if (tokens[i].type == TokenType.int_lit)
{
e = new intlit() { value = (int)tokens[i].val };
i++;
}
else if (tokens[i].type == TokenType.string_lit)
{
e = new stringlit() { value = tokens[i].val as string };
i++;
}
else if (tokens[i].type == TokenType.symbol && (char)tokens[i].val == '<')
{
i++;
List<string> fargs = new List<string>();
while (i < tokens.Length && !(tokens[i].type == TokenType.symbol && (char)tokens[i].val == '>'))
{
if (tokens[i].type == TokenType.word)
{
fargs.Add(tokens[i].val as string);
}
i++;
}
i++;
bool lnfc = infnc;
infnc = true;
STMT[] body = ParseBody();
infnc = lnfc;
e = new LambdaExpr() { args = fargs.ToArray(), body = body };
}
else if (tokens[i].type == TokenType.word && tokens[i].val as string == "array" && tokens[i + 1].type == TokenType.symbol && (char)tokens[i + 1].val == '[')
{
i += 2;
EXPR count = ParseExpr(isArithExpr);
i++;
e = new ArrayInitializer() { count = count };
}
else if (tokens[i].type == TokenType.word && tokens[i + 1].type == TokenType.symbol && (char)tokens[i + 1].val == '[')
{
string varname = tokens[i].val as string;
i += 2;
EXPR index = ParseExpr(isArithExpr);
i++;
if (tokens[i].type == TokenType.symbol && (char)tokens[i].val == '=')
{
i++;
EXPR val = ParseExpr(isArithExpr);
e = new ArrayStrElem() { varname = varname, index = index, value = val };
}
else
{
e = new ArrayGetElem() { varname = varname, index = index };
}
}
else if (i + 1 < tokens.Length && tokens[i + 1].type == TokenType.symbol && (char)tokens[i + 1].val == '(')
{
string fname = tokens[i].val as string;
i += 2;
List<EXPR> args = new List<EXPR>();
while (!(tokens[i].type == TokenType.symbol && (char)tokens[i].val == ')'))
{
EXPR ex = ParseExpr(isArithExpr);
if (ex != null)
{
args.Add(ex);
}
else
{
i++;
}
}
i++;
e = new fcall() { fname = fname, args = args.ToArray() };
}
else if (tokens[i].type == TokenType.word && tokens[i].val as string == "asm")
{
i++;
string asm = tokens[i].val as string;
i++;
return new asm() { asmtxt = asm };
}
else if (tokens[i].type == TokenType.word)
{
string vname = tokens[i].val as string;
if (vname.StartsWith("@"))
{
e = new getvarptr() { varname = vname.Substring(1) };
}
else
{
e = new getvar() { varname = vname };
}
//.........这里部分代码省略.........
示例14: yyparse
//.........这里部分代码省略.........
name, current_local_parameters, (Attributes) yyVals[-9+yyTop], yyVals[0+yyTop] != null);
if(current_container.Kind == MemberKind.Interface && current_extensionContainer != null){
var parameters = new List<Parameter>();
var typeExpression = new TypeExpression (compiler.BuiltinTypes.Object, GetLocation (yyVals[-9+yyTop]));
var parameter = new Parameter(typeExpression, "self", Parameter.Modifier.This, null, GetLocation(yyVals[-9+yyTop]));
parameters.Add(parameter);
parameters.Add(new Parameter(typeExpression, "ctx", Parameter.Modifier.NONE, null, GetLocation(yyVals[-9+yyTop])));
var clone = current_local_parameters.Clone();
for(var i = 0; i < clone.Count; i++){
parameters.Add(clone[i]);
}
var parameterTypeExpressions = parameters.Select(p=>p.TypeExpression).ToList();
var key = current_namespace.NS.Name + "," + name.Name + "," + string.Join(",",parameterTypeExpressions.Select(p => p.ToString()));
if(roleExtensionMethodDummies.Add(key)){
var returnType = (FullNamedExpression) yyVals[-7+yyTop];
var parametersCompiled = new ParametersCompiled(parameters.ToArray(),false);
var dummy = Method.Create (current_extensionContainer, generic, (FullNamedExpression) yyVals[-7+yyTop], Modifiers.PUBLIC | Modifiers.STATIC,
name, parametersCompiled, (Attributes) yyVals[-9+yyTop], yyVals[0+yyTop] != null);
var location = GetLocation(yyVals[-9+yyTop]);
var parameterName = new SimpleName("self", null, location);
var getTypeAccess = new MemberAccess(parameterName, "GetType", null, location);
var getTypeExpression = new Invocation(getTypeAccess, new Arguments(0));
var argCount = parameterTypeExpressions.Count-1;
var argumentsForGetMethod = new Arguments(2);
var stringLiteral = new StringLiteral(compiler.BuiltinTypes,name.Name,location);
argumentsForGetMethod.Add(new Argument(stringLiteral));
var typeName = new SimpleName("Type", null, location);
var types = parameterTypeExpressions.Skip(2)
.Select(t =>(Expression)(t.Type != null
? new TypeOf(t.Type,location)
: new TypeOf(t,location))
).ToList();
var initializer = new ArrayInitializer(types,location);
var parameterTypes = new ImplicitlyTypedArrayCreation (
new ComposedTypeSpecifier (1, location),
initializer,
location);
lbag.AddLocation (parameterTypes, location, location);
argumentsForGetMethod.Add(new Argument(parameterTypes));
var getMethodExpression = new Invocation(new MemberAccess(getTypeExpression,"GetMethod"),argumentsForGetMethod);
var argumentsForMethod = new Arguments(2);
var delegatedArguments = parameters.Skip(2).Select(p =>
(Expression)new Cast(
new TypeExpression(compiler.BuiltinTypes.Object,location),
new SimpleName(p.Name,location),
location)).ToList();
argumentsForMethod.Add(new Argument(new SimpleName("self", null, location)));
if(delegatedArguments.Any()){
initializer = new ArrayInitializer(delegatedArguments,location);
argumentsForMethod.Add(new Argument(new ImplicitlyTypedArrayCreation(
new ComposedTypeSpecifier (1, location),
initializer,
location)));
} else {
argumentsForMethod.Add(new Argument(new ArrayCreation(new TypeExpression(compiler.BuiltinTypes.Object,location),new ArrayInitializer(0,location))));
}
var invocation = new Invocation(new MemberAccess(getMethodExpression,"Invoke"),argumentsForMethod);
Statement statement = new StatementExpression(invocation);
var retType = (returnType as TypeExpression);
if(retType != null && retType.Type.Name != "Void"){
var cast = new Cast(returnType,invocation,location);
示例15: case_526
void case_526()
#line 3803 "cs-parser.jay"
{
var ai = new ArrayInitializer ((List<Expression>) yyVals[-2+yyTop], GetLocation (yyVals[-3+yyTop]));
ai.VariableDeclaration = current_variable;
if (yyVals[-1+yyTop] != null) {
lbag.AddLocation (ai, GetLocation (yyVals[-1+yyTop]), GetLocation (yyVals[0+yyTop]));
} else {
lbag.AddLocation (ai, GetLocation (yyVals[0+yyTop]));
}
yyVal = ai;
}