本文整理汇总了C#中ICSharpCode.NRefactory.Ast.ArrayCreateExpression类的典型用法代码示例。如果您正苦于以下问题:C# ArrayCreateExpression类的具体用法?C# ArrayCreateExpression怎么用?C# ArrayCreateExpression使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ArrayCreateExpression类属于ICSharpCode.NRefactory.Ast命名空间,在下文中一共展示了ArrayCreateExpression类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: VisitArrayCreateExpression
public override object VisitArrayCreateExpression(ArrayCreateExpression arrayCreateExpression, object data)
{
for (int i = 0; i < arrayCreateExpression.Arguments.Count; i++) {
arrayCreateExpression.Arguments[i] = Expression.AddInteger(arrayCreateExpression.Arguments[i], -1);
}
return base.VisitArrayCreateExpression(arrayCreateExpression, data);
}
示例2: VisitArrayCreateExpression
public override object VisitArrayCreateExpression(ArrayCreateExpression array, object data)
{
for(int i = 0; i < array.Arguments.Count; i++) {
array.Arguments[i] = Deparenthesize(array.Arguments[i]);
}
return base.VisitArrayCreateExpression(array, data);
}
示例3: VisitArrayCreateExpression
public override object VisitArrayCreateExpression(ArrayCreateExpression arrayCreateExpression, object data)
{
if (arrayCreateExpression.IsImplicitlyTyped) {
return CreateResolveResult(arrayCreateExpression.ArrayInitializer);
} else {
return CreateTypeResolveResult(TypeVisitor.CreateReturnType(arrayCreateExpression.CreateType, resolver));
}
}
示例4: VisitArrayCreateExpression
public override object VisitArrayCreateExpression(ArrayCreateExpression arrayCreateExpression, object data)
{
arrayCreateExpression.CreateType.Parent = arrayCreateExpression;
arrayCreateExpression.ArrayInitializer.Parent = arrayCreateExpression;
foreach (INode argument in arrayCreateExpression.Arguments)
argument.Parent = arrayCreateExpression;
return base.VisitArrayCreateExpression(arrayCreateExpression, data);
}
示例5: VisitArrayCreateExpression
public override object VisitArrayCreateExpression(ArrayCreateExpression arrayCreateExpression, object data)
{
if (arrayCreateExpression.ArrayInitializer == null) {
return new CodeArrayCreateExpression(ConvType(arrayCreateExpression.CreateType),
arrayCreateExpression.Arguments[0].AcceptVisitor(this, data) as CodeExpression);
}
return new CodeArrayCreateExpression(ConvType(arrayCreateExpression.CreateType),
GetExpressionList(arrayCreateExpression.ArrayInitializer.CreateExpressions));
}
示例6: VisitArrayCreateExpression
public override object VisitArrayCreateExpression(ArrayCreateExpression arrayCreateExpression, object data)
{
for (int i = 0; i < arrayCreateExpression.Arguments.Count; i++) {
arrayCreateExpression.Arguments[i] = Expression.AddInteger(arrayCreateExpression.Arguments[i], 1);
}
if (arrayCreateExpression.ArrayInitializer.CreateExpressions.Count == 0) {
arrayCreateExpression.ArrayInitializer = null;
}
return base.VisitArrayCreateExpression(arrayCreateExpression, data);
}
示例7: GetArrayInitStatements
private List<Statement> GetArrayInitStatements(ArrayCreateExpression arrayCreateExpression, string variableName, List<Expression> initializerList)
{
List<Statement> list = new List<Statement>();
for (int idx = 0; idx < initializerList.Count; idx++)
{
AssignmentExpression assignment = InitArrayStatement(arrayCreateExpression, variableName, ((CollectionInitializerExpression) initializerList[idx]).CreateExpressions, idx);
ExpressionStatement expressionStatement = new ExpressionStatement(assignment);
list.Add(expressionStatement);
}
return list;
}
示例8: VisitArrayCreateExpression
public virtual object VisitArrayCreateExpression(ArrayCreateExpression arrayCreateExpression, object data) {
Debug.Assert((arrayCreateExpression != null));
Debug.Assert((arrayCreateExpression.CreateType != null));
Debug.Assert((arrayCreateExpression.Arguments != null));
Debug.Assert((arrayCreateExpression.ArrayInitializer != null));
arrayCreateExpression.CreateType.AcceptVisitor(this, data);
foreach (Expression o in arrayCreateExpression.Arguments) {
Debug.Assert(o != null);
o.AcceptVisitor(this, data);
}
return arrayCreateExpression.ArrayInitializer.AcceptVisitor(this, data);
}
示例9: TrackedVisitArrayCreateExpression
public override object TrackedVisitArrayCreateExpression(ArrayCreateExpression arrayCreateExpression, object data)
{
string variableName = GetVariableName(arrayCreateExpression);
List<Expression> initializerList = arrayCreateExpression.ArrayInitializer.CreateExpressions;
Expression replacedExpression = arrayCreateExpression;
if (initializerList.Count > 0 && initializerList[0] is CollectionInitializerExpression && data is InsertionBlockData)
{
ArrayCreateExpression replacedArrayCreateExpression = arrayCreateExpression;
replacedArrayCreateExpression.ArrayInitializer = null;
replacedArrayCreateExpression.Arguments.Add(new PrimitiveExpression(initializerList.Count, initializerList.Count.ToString()));
string arrayTypeName = arrayCreateExpression.CreateType.Type + "s";
Position position = Position.After;
if (variableName == null)
{
variableName = arrayTypeName;
position = Position.Before;
}
List<Statement> initStatements = GetArrayInitStatements(replacedArrayCreateExpression, variableName, initializerList);
InsertionBlockData insertionBlockData = (InsertionBlockData) data;
insertionBlockData.Block = (BlockStatement) AstUtil.GetParentOfType(replacedArrayCreateExpression, typeof(BlockStatement));
insertionBlockData.BlockChildIndex = GetBlockChildIndex(replacedArrayCreateExpression, position);
insertionBlockData.Statements = initStatements;
if (variableName == arrayTypeName)
{
IdentifierExpression identifierExpression = new IdentifierExpression(variableName);
replacedExpression = identifierExpression;
VariableDeclaration variableDeclaration = new VariableDeclaration(variableName, arrayCreateExpression);
LocalVariableDeclaration localVariable = new LocalVariableDeclaration(variableDeclaration);
localVariable.TypeReference = arrayCreateExpression.CreateType;
initStatements.Insert(0, localVariable);
}
ReplaceCurrentNode(replacedExpression);
}
return base.TrackedVisitArrayCreateExpression(arrayCreateExpression, data);
}
示例10: VisitArrayCreateExpression
public virtual object VisitArrayCreateExpression(ArrayCreateExpression arrayCreateExpression, object data) {
Debug.Assert((arrayCreateExpression != null));
Debug.Assert((arrayCreateExpression.CreateType != null));
Debug.Assert((arrayCreateExpression.Arguments != null));
Debug.Assert((arrayCreateExpression.ArrayInitializer != null));
nodeStack.Push(arrayCreateExpression.CreateType);
arrayCreateExpression.CreateType.AcceptVisitor(this, data);
arrayCreateExpression.CreateType = ((TypeReference)(nodeStack.Pop()));
for (int i = 0; i < arrayCreateExpression.Arguments.Count; i++) {
Expression o = arrayCreateExpression.Arguments[i];
Debug.Assert(o != null);
nodeStack.Push(o);
o.AcceptVisitor(this, data);
o = (Expression)nodeStack.Pop();
if (o == null)
arrayCreateExpression.Arguments.RemoveAt(i--);
else
arrayCreateExpression.Arguments[i] = o;
}
nodeStack.Push(arrayCreateExpression.ArrayInitializer);
arrayCreateExpression.ArrayInitializer.AcceptVisitor(this, data);
arrayCreateExpression.ArrayInitializer = ((CollectionInitializerExpression)(nodeStack.Pop()));
return null;
}
示例11: ObjectCreateExpression
void ObjectCreateExpression(
#line 1935 "VBNET.ATG"
out Expression oce) {
#line 1937 "VBNET.ATG"
TypeReference type = null;
Expression initializer = null;
List<Expression> arguments = null;
ArrayList dimensions = null;
oce = null;
bool canBeNormal; bool canBeReDim;
Expect(148);
if (StartOf(7)) {
NonArrayTypeName(
#line 1945 "VBNET.ATG"
out type, false);
if (la.kind == 25) {
lexer.NextToken();
NormalOrReDimArgumentList(
#line 1946 "VBNET.ATG"
out arguments, out canBeNormal, out canBeReDim);
Expect(26);
if (la.kind == 23 ||
#line 1947 "VBNET.ATG"
la.kind == Tokens.OpenParenthesis) {
if (
#line 1947 "VBNET.ATG"
la.kind == Tokens.OpenParenthesis) {
ArrayTypeModifiers(
#line 1948 "VBNET.ATG"
out dimensions);
CollectionInitializer(
#line 1949 "VBNET.ATG"
out initializer);
} else {
CollectionInitializer(
#line 1950 "VBNET.ATG"
out initializer);
}
}
#line 1952 "VBNET.ATG"
if (canBeReDim && !canBeNormal && initializer == null) initializer = new CollectionInitializerExpression();
}
}
#line 1956 "VBNET.ATG"
if (initializer == null) {
oce = new ObjectCreateExpression(type, arguments);
} else {
if (dimensions == null) dimensions = new ArrayList();
dimensions.Insert(0, (arguments == null) ? 0 : Math.Max(arguments.Count - 1, 0));
type.RankSpecifier = (int[])dimensions.ToArray(typeof(int));
ArrayCreateExpression ace = new ArrayCreateExpression(type, initializer as CollectionInitializerExpression);
ace.Arguments = arguments;
oce = ace;
}
if (la.kind == 218) {
#line 1970 "VBNET.ATG"
NamedArgumentExpression memberInitializer = null;
lexer.NextToken();
#line 1974 "VBNET.ATG"
CollectionInitializerExpression memberInitializers = new CollectionInitializerExpression();
memberInitializers.StartLocation = la.Location;
Expect(23);
MemberInitializer(
#line 1978 "VBNET.ATG"
out memberInitializer);
#line 1979 "VBNET.ATG"
memberInitializers.CreateExpressions.Add(memberInitializer);
while (la.kind == 12) {
lexer.NextToken();
MemberInitializer(
#line 1981 "VBNET.ATG"
out memberInitializer);
#line 1982 "VBNET.ATG"
memberInitializers.CreateExpressions.Add(memberInitializer);
}
Expect(24);
#line 1986 "VBNET.ATG"
memberInitializers.EndLocation = t.Location;
if(oce is ObjectCreateExpression)
{
((ObjectCreateExpression)oce).ObjectInitializer = memberInitializers;
}
}
}
示例12: VisitReDimStatement
public override object VisitReDimStatement(ReDimStatement reDimStatement, object data)
{
base.VisitReDimStatement(reDimStatement, data);
if (resolver.CompilationUnit == null)
return null;
if (reDimStatement.ReDimClauses.Count != 1)
return null;
if (reDimStatement.IsPreserve) {
if (reDimStatement.ReDimClauses[0].Arguments.Count > 1) {
// multidimensional Redim Preserve
// replace with:
// MyArray = (int[,])Microsoft.VisualBasic.CompilerServices.Utils.CopyArray(MyArray, new int[dim1+1, dim2+1]);
ResolveResult rr = Resolve(reDimStatement.ReDimClauses[0].TargetObject);
if (rr != null && rr.ResolvedType != null && rr.ResolvedType.IsArrayReturnType) {
ArrayCreateExpression ace = new ArrayCreateExpression(ConvertType(rr.ResolvedType));
foreach (Expression arg in reDimStatement.ReDimClauses[0].Arguments) {
ace.Arguments.Add(Expression.AddInteger(arg, 1));
}
ReplaceCurrentNode(new ExpressionStatement(
new AssignmentExpression(
reDimStatement.ReDimClauses[0].TargetObject,
AssignmentOperatorType.Assign,
new CastExpression(
ace.CreateType,
new InvocationExpression(
MakeFieldReferenceExpression("Microsoft.VisualBasic.CompilerServices.Utils.CopyArray"),
new List<Expression> {
reDimStatement.ReDimClauses[0].TargetObject,
ace
}
),
CastType.Cast
)
)));
}
}
} else {
// replace with array create expression
ResolveResult rr = Resolve(reDimStatement.ReDimClauses[0].TargetObject);
if (rr != null && rr.ResolvedType != null && rr.ResolvedType.IsArrayReturnType) {
ArrayCreateExpression ace = new ArrayCreateExpression(ConvertType(rr.ResolvedType));
foreach (Expression arg in reDimStatement.ReDimClauses[0].Arguments) {
ace.Arguments.Add(Expression.AddInteger(arg, 1));
}
ReplaceCurrentNode(new ExpressionStatement(
new AssignmentExpression(reDimStatement.ReDimClauses[0].TargetObject, AssignmentOperatorType.Assign, ace)));
}
}
return null;
}
示例13: NewExpression
void NewExpression(
#line 2065 "cs.ATG"
out Expression pexpr) {
#line 2066 "cs.ATG"
pexpr = null;
List<Expression> parameters = new List<Expression>();
TypeReference type = null;
Expression expr;
Expect(89);
if (StartOf(10)) {
NonArrayType(
#line 2073 "cs.ATG"
out type);
}
if (la.kind == 16 || la.kind == 20) {
if (la.kind == 20) {
#line 2079 "cs.ATG"
ObjectCreateExpression oce = new ObjectCreateExpression(type, parameters);
lexer.NextToken();
#line 2080 "cs.ATG"
if (type == null) Error("Cannot use an anonymous type with arguments for the constructor");
if (StartOf(25)) {
Argument(
#line 2081 "cs.ATG"
out expr);
#line 2081 "cs.ATG"
SafeAdd(oce, parameters, expr);
while (la.kind == 14) {
lexer.NextToken();
Argument(
#line 2082 "cs.ATG"
out expr);
#line 2082 "cs.ATG"
SafeAdd(oce, parameters, expr);
}
}
Expect(21);
#line 2084 "cs.ATG"
pexpr = oce;
if (la.kind == 16) {
CollectionOrObjectInitializer(
#line 2085 "cs.ATG"
out expr);
#line 2085 "cs.ATG"
oce.ObjectInitializer = (CollectionInitializerExpression)expr;
}
} else {
#line 2086 "cs.ATG"
ObjectCreateExpression oce = new ObjectCreateExpression(type, parameters);
CollectionOrObjectInitializer(
#line 2087 "cs.ATG"
out expr);
#line 2087 "cs.ATG"
oce.ObjectInitializer = (CollectionInitializerExpression)expr;
#line 2088 "cs.ATG"
pexpr = oce;
}
} else if (la.kind == 18) {
lexer.NextToken();
#line 2093 "cs.ATG"
ArrayCreateExpression ace = new ArrayCreateExpression(type);
/* we must not change RankSpecifier on the null type reference*/
if (ace.CreateType.IsNull) { ace.CreateType = new TypeReference(""); }
pexpr = ace;
int dims = 0; List<int> ranks = new List<int>();
if (la.kind == 14 || la.kind == 19) {
while (la.kind == 14) {
lexer.NextToken();
#line 2100 "cs.ATG"
dims += 1;
}
Expect(19);
#line 2101 "cs.ATG"
ranks.Add(dims); dims = 0;
while (la.kind == 18) {
lexer.NextToken();
while (la.kind == 14) {
lexer.NextToken();
#line 2102 "cs.ATG"
++dims;
}
Expect(19);
#line 2102 "cs.ATG"
//.........这里部分代码省略.........
示例14: VisitArrayCreateExpression
public override object VisitArrayCreateExpression(ArrayCreateExpression arrayCreateExpression, object data)
{
if (arrayCreateExpression.IsImplicitlyTyped) {
// Console.WriteLine (arrayCreateExpression.ArrayInitializer);
return Resolve (arrayCreateExpression.ArrayInitializer);
}
return CreateResult (arrayCreateExpression.CreateType);
}
示例15: ObjectCreateExpression
void ObjectCreateExpression(
#line 1860 "VBNET.ATG"
out Expression oce) {
#line 1862 "VBNET.ATG"
TypeReference type = null;
Expression initializer = null;
List<Expression> arguments = null;
ArrayList dimensions = null;
oce = null;
bool canBeNormal; bool canBeReDim;
Expect(127);
NonArrayTypeName(
#line 1869 "VBNET.ATG"
out type, false);
if (la.kind == 24) {
lexer.NextToken();
NormalOrReDimArgumentList(
#line 1870 "VBNET.ATG"
out arguments, out canBeNormal, out canBeReDim);
Expect(25);
if (la.kind == 22 ||
#line 1871 "VBNET.ATG"
la.kind == Tokens.OpenParenthesis) {
if (
#line 1871 "VBNET.ATG"
la.kind == Tokens.OpenParenthesis) {
ArrayTypeModifiers(
#line 1872 "VBNET.ATG"
out dimensions);
CollectionInitializer(
#line 1873 "VBNET.ATG"
out initializer);
} else {
CollectionInitializer(
#line 1874 "VBNET.ATG"
out initializer);
}
}
#line 1876 "VBNET.ATG"
if (canBeReDim && !canBeNormal && initializer == null) initializer = new CollectionInitializerExpression();
}
#line 1879 "VBNET.ATG"
if (type == null) type = new TypeReference("Object"); // fallback type on parser errors
if (initializer == null) {
oce = new ObjectCreateExpression(type, arguments);
} else {
if (dimensions == null) dimensions = new ArrayList();
dimensions.Insert(0, (arguments == null) ? 0 : Math.Max(arguments.Count - 1, 0));
type.RankSpecifier = (int[])dimensions.ToArray(typeof(int));
ArrayCreateExpression ace = new ArrayCreateExpression(type, initializer as CollectionInitializerExpression);
ace.Arguments = arguments;
oce = ace;
}
}