本文整理汇总了C#中ICSharpCode.NRefactory.Ast.VariableDeclaration类的典型用法代码示例。如果您正苦于以下问题:C# VariableDeclaration类的具体用法?C# VariableDeclaration怎么用?C# VariableDeclaration使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
VariableDeclaration类属于ICSharpCode.NRefactory.Ast命名空间,在下文中一共展示了VariableDeclaration类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: add_Variable
public static VariableDeclaration add_Variable(this BlockStatement blockDeclaration, string name, Expression expression, TypeReference typeReference)
{
var variableDeclaration = new VariableDeclaration(name, expression) {TypeReference = typeReference};
var localVariableDeclaration = new LocalVariableDeclaration(variableDeclaration);
blockDeclaration.append(localVariableDeclaration);
return variableDeclaration;
}
示例2: VisitVariableDeclaration
public override object VisitVariableDeclaration(VariableDeclaration variableDeclaration, object data)
{
if (nameComparer.Equals(from, variableDeclaration.Name)) {
variableDeclaration.Name = to;
}
return base.VisitVariableDeclaration(variableDeclaration, data);
}
示例3: VisitVariableDeclaration
public override object VisitVariableDeclaration(VariableDeclaration variableDeclaration, object data)
{
// process local variables only
if (fields.Contains(variableDeclaration)) {
return null;
}
curBlock.Add(variableDeclaration.Name);
return base.VisitVariableDeclaration(variableDeclaration, data);
}
示例4: Contains
bool Contains(VariableDeclaration varDecl)
{
foreach (VariableDeclaration v in this.unneededVarDecls) {
if (v.Name == varDecl.Name) {
return true;
}
}
return false;
}
开发者ID:Adam-Fogle,项目名称:agentralphplugin,代码行数:10,代码来源:ReplaceUnnecessaryVariableDeclarationsTransformer.cs
示例5: VisitVariableDeclaration
public override object VisitVariableDeclaration(VariableDeclaration variableDeclaration, object data)
{
var objectCreateExpression = variableDeclaration.Initializer as ObjectCreateExpression;
if (objectCreateExpression != null && objectCreateExpression.IsAnonymousType)
{
UnlockWith(variableDeclaration);
}
return base.VisitVariableDeclaration(variableDeclaration, data);
}
示例6: GenerateCode
public override void GenerateCode(List<AbstractNode> nodes, IList items)
{
TypeReference intReference = new TypeReference("System.Int32");
MethodDeclaration method = new MethodDeclaration("GetHashCode", Modifiers.Public | Modifiers.Override, intReference, null, null);
Expression expr = CallGetHashCode(new IdentifierExpression(currentClass.Fields[0].Name));
for (int i = 1; i < currentClass.Fields.Count; i++) {
IdentifierExpression identifier = new IdentifierExpression(currentClass.Fields[i].Name);
expr = new BinaryOperatorExpression(expr, BinaryOperatorType.ExclusiveOr,
CallGetHashCode(identifier));
}
method.Body = new BlockStatement();
method.Body.AddChild(new ReturnStatement(expr));
nodes.Add(method);
TypeReference boolReference = new TypeReference("System.Boolean");
TypeReference objectReference = new TypeReference("System.Object");
method = new MethodDeclaration("Equals", Modifiers.Public | Modifiers.Override, boolReference, null, null);
method.Parameters.Add(new ParameterDeclarationExpression(objectReference, "obj"));
method.Body = new BlockStatement();
TypeReference currentType = ConvertType(currentClass.DefaultReturnType);
expr = new TypeOfIsExpression(new IdentifierExpression("obj"), currentType);
expr = new ParenthesizedExpression(expr);
expr = new UnaryOperatorExpression(expr, UnaryOperatorType.Not);
method.Body.AddChild(new IfElseStatement(expr, new ReturnStatement(new PrimitiveExpression(false, "false"))));
expr = new BinaryOperatorExpression(new ThisReferenceExpression(),
BinaryOperatorType.Equality,
new IdentifierExpression("obj"));
method.Body.AddChild(new IfElseStatement(expr, new ReturnStatement(new PrimitiveExpression(true, "true"))));
VariableDeclaration var = new VariableDeclaration("my" + currentClass.Name,
new CastExpression(currentType, new IdentifierExpression("obj"), CastType.Cast),
currentType);
method.Body.AddChild(new LocalVariableDeclaration(var));
expr = TestEquality(var.Name, currentClass.Fields[0]);
for (int i = 1; i < currentClass.Fields.Count; i++) {
expr = new BinaryOperatorExpression(expr, BinaryOperatorType.LogicalAnd,
TestEquality(var.Name, currentClass.Fields[i]));
}
method.Body.AddChild(new ReturnStatement(expr));
nodes.Add(method);
}
示例7: TrackedVisitVariableDeclaration
public override object TrackedVisitVariableDeclaration(VariableDeclaration variableDeclaration, object data)
{
BlockStatement blockStatement = (BlockStatement) AstUtil.GetParentOfType(variableDeclaration, typeof(BlockStatement));
if (blockStatement != null)
{
int hashCode = blockStatement.GetHashCode();
if (!(blockStatement.Parent is MethodDeclaration) && !localVariables.Contains(variableDeclaration.Name))
localVariables.Add(variableDeclaration.Name, variableDeclaration);
else if (HasConflict(variableDeclaration))
{
string newName = renamer.GetNewName(variableDeclaration.Name);
renamedVariables.Add(variableDeclaration.Name + "_" + hashCode, newName);
variableDeclaration.Name = newName;
}
}
return base.TrackedVisitVariableDeclaration(variableDeclaration, data);
}
示例8: VisitVariableDeclaration
public override object VisitVariableDeclaration(VariableDeclaration variableDeclaration, object data)
{
string[] foulwords= new string[]
{
"meh","blah", "pft", "rrrr","blib","blab", "blub","lol","uhu","aaah"
};//if anyone wants to go nuts: feel free to add more :)
foreach (var foulword in foulwords)
{
if (System.Text.RegularExpressions.Regex.Matches(variableDeclaration.Name, foulword).Count > 0)
cursecount++;
}
if (cursecount>5)
UnlockWith(variableDeclaration);
return base.VisitVariableDeclaration(variableDeclaration, data);
}
示例9: VisitVariableDeclaration
public override object VisitVariableDeclaration(VariableDeclaration variableDeclaration, object data)
{
string[] foulwords= new string[]
{
"fuck", "shit", "crap", "bollocks"
};//if anyone wants to go nuts: feel free to add more :)
foreach (var foulword in foulwords)
{
if (System.Text.RegularExpressions.Regex.Matches(variableDeclaration.Name, foulword).Count > 0)
cursecount++;
}
if (cursecount>5)
UnlockWith(variableDeclaration);
return base.VisitVariableDeclaration(variableDeclaration, data);
}
示例10: CreateCaller
protected static Statement CreateCaller(AttributedNode parent, MethodDeclaration method, VariableDeclaration returnVariable)
{
Statement caller;
InvocationExpression expr = new InvocationExpression(new IdentifierExpression(method.Name), CreateArgumentExpressions(method.Parameters));
if (method.TypeReference.Type != "System.Void") {
TypeReference parentType = GetParentReturnType(parent);
if (method.TypeReference == parentType)
caller = new ReturnStatement(expr);
else {
returnVariable.Initializer = expr;
caller = new LocalVariableDeclaration(returnVariable);
}
} else {
caller = new ExpressionStatement(expr);
}
return caller;
}
示例11: 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);
}
示例12: ConvertField
void ConvertField(TypeReference typeRef, VariableDeclaration variable, FieldDeclaration fieldDeclaration)
{
B.TypeMember m;
if (currentType is B.EnumDefinition) {
if (variable.Initializer.IsNull) {
m = new B.EnumMember(GetLexicalInfo(fieldDeclaration));
} else {
PrimitiveExpression p = variable.Initializer as PrimitiveExpression;
if (p == null || !(p.Value is int)) {
AddError(fieldDeclaration, "enum member initializer must be integer value");
return;
}
m = new B.EnumMember(GetLexicalInfo(fieldDeclaration), new B.IntegerLiteralExpression((int)p.Value));
}
} else {
m = new B.Field(GetLexicalInfo(fieldDeclaration), ConvertTypeReference(typeRef), ConvertExpression(variable.Initializer));
m.Modifiers = ConvertModifier(fieldDeclaration, B.TypeMemberModifiers.Private);
}
m.Name = variable.Name;
ConvertAttributes(fieldDeclaration.Attributes, m.Attributes);
if (currentType != null) currentType.Members.Add(m);
}
示例13: ConstantDeclarator
void ConstantDeclarator(
#line 1381 "VBNET.ATG"
List<VariableDeclaration> constantDeclaration) {
#line 1383 "VBNET.ATG"
Expression expr = null;
TypeReference type = null;
string name = String.Empty;
Location location;
Identifier();
#line 1388 "VBNET.ATG"
name = t.val; location = t.Location;
if (la.kind == 50) {
lexer.NextToken();
TypeName(
#line 1389 "VBNET.ATG"
out type);
}
Expect(10);
Expr(
#line 1390 "VBNET.ATG"
out expr);
#line 1392 "VBNET.ATG"
VariableDeclaration f = new VariableDeclaration(name, expr);
f.TypeReference = type;
f.StartLocation = location;
constantDeclaration.Add(f);
}
示例14: EnumMemberDecl
void EnumMemberDecl(
#line 743 "VBNET.ATG"
out FieldDeclaration f) {
#line 745 "VBNET.ATG"
Expression expr = null;List<AttributeSection> attributes = new List<AttributeSection>();
AttributeSection section = null;
VariableDeclaration varDecl = null;
while (la.kind == 28) {
AttributeSection(
#line 749 "VBNET.ATG"
out section);
#line 749 "VBNET.ATG"
attributes.Add(section);
}
Identifier();
#line 752 "VBNET.ATG"
f = new FieldDeclaration(attributes);
varDecl = new VariableDeclaration(t.val);
f.Fields.Add(varDecl);
f.StartLocation = varDecl.StartLocation = t.Location;
if (la.kind == 10) {
lexer.NextToken();
Expr(
#line 757 "VBNET.ATG"
out expr);
#line 757 "VBNET.ATG"
varDecl.Initializer = expr;
}
EndOfStmt();
}
示例15: TrackedVisitVariableDeclaration
public override object TrackedVisitVariableDeclaration(VariableDeclaration variableDeclaration, object data)
{
// Resolving anything here only makes sense
// if this declaration actually has an initializer.
if (variableDeclaration.Initializer.IsNull) {
return base.TrackedVisitVariableDeclaration(variableDeclaration, data);
}
LocalVariableDeclaration localVariableDeclaration = data as LocalVariableDeclaration;
if (this.isLocalVariable && localVariableDeclaration != null) {
if (variableDeclaration.Name == this.resourceManagerMember.Name) {
// Make sure we got the right declaration by comparing the positions.
// Both must have the same start position.
if (localVariableDeclaration.StartLocation.X == this.resourceManagerMember.Region.BeginColumn && localVariableDeclaration.StartLocation.Y == this.resourceManagerMember.Region.BeginLine) {
#if DEBUG
LoggingService.Debug("ResourceToolkit: BclNRefactoryResourceResolver found local variable declaration: "+localVariableDeclaration.ToString()+" at "+localVariableDeclaration.StartLocation.ToString());
#endif
data = true;
}
}
}
FieldDeclaration fieldDeclaration = data as FieldDeclaration;
if (!this.isLocalVariable && fieldDeclaration != null) {
// Make sure we got the right declaration by comparing the positions.
// Both must have the same start position.
if (variableDeclaration.Name == this.resourceManagerMember.Name &&
fieldDeclaration.StartLocation.X == this.resourceManagerMember.Region.BeginColumn && fieldDeclaration.StartLocation.Y == this.resourceManagerMember.Region.BeginLine) {
#if DEBUG
LoggingService.Debug("ResourceToolkit: BclNRefactoryResourceResolver found field declaration: "+fieldDeclaration.ToString()+" at "+fieldDeclaration.StartLocation.ToString());
#endif
data = true;
} else {
// This field might be referred to by a property
// that we are looking for.
// This association is cached in the
// resourceManagerFieldAccessedByProperty field
// to improve performance.
this.TryResolveResourceManagerProperty();
if (this.resourceManagerFieldAccessedByProperty != null &&
fieldDeclaration.StartLocation.X == this.resourceManagerFieldAccessedByProperty.Region.BeginColumn &&
fieldDeclaration.StartLocation.Y == this.resourceManagerFieldAccessedByProperty.Region.BeginLine) {
#if DEBUG
LoggingService.Debug("ResourceToolkit: BclNRefactoryResourceResolver found field declaration (via associated property): "+fieldDeclaration.ToString()+" at "+fieldDeclaration.StartLocation.ToString());
#endif
data = true;
}
}
}
return base.TrackedVisitVariableDeclaration(variableDeclaration, data);
}