本文整理汇总了C#中ICSharpCode.NRefactory.Ast.FieldDeclaration类的典型用法代码示例。如果您正苦于以下问题:C# FieldDeclaration类的具体用法?C# FieldDeclaration怎么用?C# FieldDeclaration使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
FieldDeclaration类属于ICSharpCode.NRefactory.Ast命名空间,在下文中一共展示了FieldDeclaration类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: VisitFieldDeclaration
public override object VisitFieldDeclaration(FieldDeclaration fieldDeclaration, object data)
{
base.VisitFieldDeclaration(fieldDeclaration, data); // visit methods
foreach(var field in fieldDeclaration.Fields)
Fields.Add(new AstValue<FieldDeclaration>(field.Name, fieldDeclaration, fieldDeclaration.StartLocation, fieldDeclaration.EndLocation));
return null;
}
示例2: VisitLocalVariableDeclaration
public override object VisitLocalVariableDeclaration(LocalVariableDeclaration localVariableDeclaration, object data)
{
base.VisitLocalVariableDeclaration(localVariableDeclaration, data);
if ((localVariableDeclaration.Modifier & Modifiers.Static) == Modifiers.Static) {
INode parent = localVariableDeclaration.Parent;
while (parent != null && !IsTypeLevel(parent)) {
parent = parent.Parent;
}
if (parent != null) {
INode type = parent.Parent;
if (type != null) {
int pos = type.Children.IndexOf(parent);
if (pos >= 0) {
FieldDeclaration field = new FieldDeclaration(null);
field.TypeReference = localVariableDeclaration.TypeReference;
field.Modifier = Modifiers.Static;
field.Fields = localVariableDeclaration.Variables;
new PrefixFieldsVisitor(field.Fields, "static_" + GetTypeLevelEntityName(parent) + "_").Run(parent);
type.Children.Insert(pos + 1, field);
RemoveCurrentNode();
}
}
}
}
return null;
}
示例3: TrackedVisitIdentifierExpression
public override object TrackedVisitIdentifierExpression(IdentifierExpression identifierExpression, object data)
{
TypeDeclaration typeDeclaration = (TypeDeclaration) AstUtil.GetParentOfType(identifierExpression, typeof(TypeDeclaration));
if (typeDeclaration != null && typeDeclaration.Parent is TypeDeclaration && !IsInvocation(identifierExpression))
{
IList parentFields = AstUtil.GetChildrenWithType(typeDeclaration.Parent, typeof(FieldDeclaration));
IList innerFields = AstUtil.GetChildrenWithType(typeDeclaration, typeof(FieldDeclaration));
FieldDeclaration field = new FieldDeclaration(null);
field.Fields.Add(new VariableDeclaration(identifierExpression.Identifier));
if (!ContainsField(innerFields, field, false) &&
!IdentifierDeclaredInParameter(identifierExpression) &&
ContainsField(parentFields, field, false))
{
string parentTypeName = ((TypeDeclaration) typeDeclaration.Parent).Name;
AddInstanceField(typeDeclaration, parentTypeName);
IdentifierExpression ins = new IdentifierExpression(parentTypeName);
FieldReferenceExpression fieldReferenceExpression = new FieldReferenceExpression(ins, identifierExpression.Identifier);
fieldReferenceExpression.Parent = identifierExpression.Parent;
ReplaceCurrentNode(fieldReferenceExpression);
}
}
return base.TrackedVisitIdentifierExpression(identifierExpression, data);
}
示例4: VisitFieldDeclaration
public object VisitFieldDeclaration(FieldDeclaration fieldDeclaration, object data)
{
for (int i = 0; i < fieldDeclaration.Fields.Count; i++) {
ConvertField(fieldDeclaration.GetTypeForField(i), fieldDeclaration.Fields[i], fieldDeclaration);
}
return null;
}
示例5: VisitFieldDeclaration
public override object VisitFieldDeclaration(FieldDeclaration fieldDeclaration, object data)
{
if (currentInfo != null)
{
currentInfo.AddField(fieldDeclaration);
}
return base.VisitFieldDeclaration(fieldDeclaration, data);
}
示例6: VisitFieldDeclaration
public override object VisitFieldDeclaration(FieldDeclaration fieldDeclaration, object data)
{
if ((fieldDeclaration.Modifier & Modifiers.Const) == Modifiers.Const)
{
UnlockWith(fieldDeclaration);
}
return base.VisitFieldDeclaration(fieldDeclaration, data);
}
示例7: add_Field
public static FieldDeclaration add_Field(this TypeDeclaration typeDeclaration, FieldDeclaration fieldDeclaration)
{
if (typeDeclaration.notNull() && fieldDeclaration.notNull() && typeDeclaration.Children.notNull())
{
//var insertPosition = typeDeclaration.Children.Count;
var insertPosition = 0; // fields are OK to go at the top
typeDeclaration.Children.Insert(insertPosition, fieldDeclaration);
}
return fieldDeclaration;
}
示例8: VisitTypeDeclaration
public override object VisitTypeDeclaration(TypeDeclaration typeDeclaration, object data)
{
base.VisitTypeDeclaration(typeDeclaration, data); // visit methods
typeDeclaration.Attributes.Clear();
typeDeclaration.BaseTypes.Clear();
// add constructor accepting the wrapped object and the field holding the object
FieldDeclaration fd = new FieldDeclaration(null, // no attributes
new TypeReference(typeDeclaration.Name),
Modifiers.Private);
fd.Fields.Add(new VariableDeclaration("wrappedObject"));
typeDeclaration.AddChild(fd);
typeDeclaration.Name += "Wrapper";
if (typeDeclaration.Type == ClassType.Interface) {
typeDeclaration.Type = ClassType.Class;
typeDeclaration.Name = typeDeclaration.Name.Substring(1);
}
ConstructorDeclaration cd = new ConstructorDeclaration(typeDeclaration.Name,
Modifiers.Public,
new List<ParameterDeclarationExpression>(),
null);
cd.Parameters.Add(new ParameterDeclarationExpression(fd.TypeReference,
"wrappedObject"));
// this.wrappedObject = wrappedObject;
Expression fieldReference = new MemberReferenceExpression(new ThisReferenceExpression(),
"wrappedObject");
Expression assignment = new AssignmentExpression(fieldReference,
AssignmentOperatorType.Assign,
new IdentifierExpression("wrappedObject"));
cd.Body = new BlockStatement();
cd.Body.AddChild(new ExpressionStatement(assignment));
typeDeclaration.AddChild(cd);
for (int i = 0; i < typeDeclaration.Children.Count; i++) {
object child = typeDeclaration.Children[i];
if (child is MethodDeclaration) {
MethodDeclaration method = (MethodDeclaration)child;
if (method.Parameters.Count == 0 &&
(method.Name.StartsWith("Is") || method.Name.StartsWith("Get")))
{
// replace the method with a property
PropertyDeclaration prop = new PropertyDeclaration(method.Modifier,
method.Attributes,
method.Name,
null);
prop.TypeReference = method.TypeReference;
prop.GetRegion = new PropertyGetRegion(method.Body, null);
typeDeclaration.Children[i] = prop;
}
}
}
return null;
}
示例9: TrackedVisitFieldDeclaration
public override object TrackedVisitFieldDeclaration(FieldDeclaration fieldDeclaration, object data)
{
if (AstUtil.ContainsModifier(fieldDeclaration, Modifiers.Transient))
{
AttributeSection ats = CreateAttributeSection("System.NonSerializedAttribute", null);
FieldDeclaration replacedField = fieldDeclaration;
replacedField.Attributes.Add(ats);
ReplaceCurrentNode(replacedField);
}
return base.TrackedVisitFieldDeclaration(fieldDeclaration, data);
}
示例10: HasSimilarName
private bool HasSimilarName(FieldDeclaration fieldDeclaration, IList methods)
{
VariableDeclaration declaration = (VariableDeclaration) fieldDeclaration.Fields[0];
string variableName = declaration.Name;
foreach (MethodDeclaration methodDeclaration in methods)
{
if (variableName == methodDeclaration.Name)
return true;
}
return false;
}
示例11: GenerateCode_Field_CreatesField
public void GenerateCode_Field_CreatesField()
{
CreateCodeGenerator();
var field = new FieldDeclaration(new List<AttributeSection>());
field.TypeReference = new TypeReference("MyClass");
field.Modifier = Modifiers.Public;
field.Fields.Add(new VariableDeclaration("myField"));
string code = codeGenerator.GenerateCode(field, String.Empty);
string expectedCode = "public MyClass myField;\r\n";
Assert.AreEqual(expectedCode, code);
}
示例12: TrackedVisitFieldDeclaration
public override object TrackedVisitFieldDeclaration(FieldDeclaration fieldDeclaration, object data)
{
if (AstUtil.ContainsModifier(fieldDeclaration, Modifiers.Static) && IsJavaPrimitiveType(fieldDeclaration.TypeReference))
{
if (fieldDeclaration.TypeReference.RankSpecifier == null || fieldDeclaration.TypeReference.RankSpecifier.Length == 0)
{
VariableDeclaration field = (VariableDeclaration) fieldDeclaration.Fields[0];
if (field.Initializer != null && (field.Initializer is PrimitiveExpression))
AstUtil.ReplaceModifiers(fieldDeclaration, Modifiers.Static, Modifiers.Const);
}
}
return base.TrackedVisitFieldDeclaration(fieldDeclaration, data);
}
示例13: RenameFeildNameSimilarToMethods
private void RenameFeildNameSimilarToMethods(FieldDeclaration fieldDeclaration, IList methods)
{
if (HasSimilarName(fieldDeclaration, methods))
{
VariableDeclaration declaration = (VariableDeclaration) fieldDeclaration.Fields[0];
TypeDeclaration typeDeclaration = (TypeDeclaration) fieldDeclaration.Parent;
string fullName = GetFullName(typeDeclaration);
string key = fullName + "." + declaration.Name;
string newName = declaration.Name + "_Field";
CodeBase.References.Add(key, newName);
declaration.Name = newName;
}
}
示例14: TrackedVisitFieldDeclaration
public override object TrackedVisitFieldDeclaration(FieldDeclaration fieldDeclaration, object data)
{
VariableDeclaration field = (VariableDeclaration) fieldDeclaration.Fields[0];
TypeDeclaration typeDeclaration = (TypeDeclaration) fieldDeclaration.Parent;
NodeTypeExistenceVisitor nodeTypeExistenceVisitor = new NodeTypeExistenceVisitor(typeof(ThisReferenceExpression));
NodeTypeExistenceVisitor indexerNodeExistenceVisitor = new NodeTypeExistenceVisitor(typeof(IndexerExpression));
field.Initializer.AcceptVisitor(nodeTypeExistenceVisitor, null);
field.Initializer.AcceptVisitor(indexerNodeExistenceVisitor, null);
if (field.Initializer != null && (field.Initializer is InvocationExpression || IsArrayCreation(fieldDeclaration) || nodeTypeExistenceVisitor.Contains || indexerNodeExistenceVisitor.Contains)
&& !AstUtil.ContainsModifier(fieldDeclaration, Modifiers.Static))
{
IList constructors = AstUtil.GetChildrenWithType(typeDeclaration, typeof(ConstructorDeclaration));
IdentifierExpression left = new IdentifierExpression(field.Name);
Expression right = field.Initializer;
AssignmentExpression assignmentExpression = new AssignmentExpression(left, AssignmentOperatorType.Assign, right);
ExpressionStatement ExpressionStatement = new ExpressionStatement(assignmentExpression);
field.Initializer = null;
ConstructorDeclaration constructorDeclaration = null;
ExpressionStatement.Parent = constructorDeclaration;
foreach (ConstructorDeclaration consDec in constructors)
{
if (!AstUtil.ContainsModifier(consDec, Modifiers.Static))
{
if (consDec.Parameters.Count == 0)
{
constructorDeclaration = consDec;
constructorDeclaration.Body.Children.Add(ExpressionStatement);
constructorDeclaration.Parent = typeDeclaration;
return base.TrackedVisitFieldDeclaration(fieldDeclaration, data);
}
else
{
consDec.ConstructorInitializer = new ConstructorInitializer();
consDec.ConstructorInitializer.ConstructorInitializerType = ConstructorInitializerType.This;
}
}
}
constructorDeclaration = GetConstructor(ExpressionStatement, typeDeclaration);
constructorDeclaration.Parent = typeDeclaration;
return base.TrackedVisitFieldDeclaration(fieldDeclaration, data);
}
return base.TrackedVisitFieldDeclaration(fieldDeclaration, data);
}
示例15: IsArrayCreation
private bool IsArrayCreation(FieldDeclaration fieldDeclaration)
{
VariableDeclaration field = (VariableDeclaration) fieldDeclaration.Fields[0];
if ((field.Initializer is ArrayCreateExpression) && (fieldDeclaration.TypeReference.RankSpecifier.Length > 0))
{
ArrayCreateExpression arrayCreateExpression = (ArrayCreateExpression) field.Initializer;
if (arrayCreateExpression.Arguments.Count > 0)
{
foreach (Expression argument in arrayCreateExpression.Arguments)
{
if (!(argument is PrimitiveExpression))
return true;
}
}
}
return false;
}