本文整理汇总了C#中FieldDeclaration类的典型用法代码示例。如果您正苦于以下问题:C# FieldDeclaration类的具体用法?C# FieldDeclaration怎么用?C# FieldDeclaration使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
FieldDeclaration类属于命名空间,在下文中一共展示了FieldDeclaration类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AddRange
/// <summary>
/// Adds the elements of an array to the end of this FieldDeclarationCollection.
/// </summary>
/// <param name="items">
/// The array whose elements are to be added to the end of this FieldDeclarationCollection.
/// </param>
public virtual void AddRange(FieldDeclaration[] items)
{
foreach (FieldDeclaration item in items)
{
this.List.Add(item);
}
}
示例2: ExtendDeclaration
public override void ExtendDeclaration(IDeclarationModel declaration, CompilationModel model)
{
// this only applies to properties
var propDecl = declaration as PropertyDeclaration;
if (propDecl == null || propDecl.Container == null)
return;
var container = propDecl.Container;
container.RemoveMember(propDecl);
var field = new FieldDeclaration
{
Container = container,
OriginatingNode = propDecl.OriginatingNode,
OriginatingTree = propDecl.OriginatingTree,
Definition = new FieldDefinition
{
Name = propDecl.Name,
ContainingType = propDecl.Definition.ContainingType,
Kind = DefinitionKind.Member,
MemberKind = MemberDefinitionKind.Field,
Type = propDecl.Definition.Type
}
};
field.Definition.Modifiers.Apply(propDecl.Definition.Modifiers);
container.AddMember(field);
}
示例3: VisitFieldDeclaration
// Fields there is only on Classes or Structs
public override void VisitFieldDeclaration(FieldDeclaration fd)
{
ClassesAndStructs cs = (ClassesAndStructs)GetDeclarationFor(fd);
string name = fd.Variables.Single().Name;
string returnType = fd.ReturnType.ToString();
Visibility v = new Visibility(VisibilityMapper.Map(fd.Modifiers));
if (al.CheckFlag(fd.Modifiers, Modifiers.Const))
{
Constant cf = new Constant(v, name, returnType, fd.Variables.Single().Initializer.ToString());
cs.ConstantFields.Add(cf);
}
else
{
Field f = new Field(v, name,
al.CheckFlag(fd.Modifiers, Modifiers.Static),
al.CheckFlag(fd.Modifiers, Modifiers.Readonly),
returnType
);
cs.Fields.Add(f);
}
AddToNotDefaultReferencedTypes(cs, returnType);
// call base to forward execution
base.VisitFieldDeclaration(fd);
}
示例4: Run
public void Run (RefactoringContext context)
{
var property = context.GetNode<PropertyDeclaration> ();
string backingStoreName = context.GetNameProposal (property.Name);
// create field
var backingStore = new FieldDeclaration ();
backingStore.ReturnType = property.ReturnType.Clone ();
var initializer = new VariableInitializer (backingStoreName);
backingStore.Variables.Add (initializer);
// create new property & implement the get/set bodies
var newProperty = (PropertyDeclaration)property.Clone ();
var id1 = new IdentifierExpression (backingStoreName);
var id2 = new IdentifierExpression (backingStoreName);
newProperty.Getter.Body = new BlockStatement () {
new ReturnStatement (id1)
};
newProperty.Setter.Body = new BlockStatement () {
new ExpressionStatement (new AssignmentExpression (id2, AssignmentOperatorType.Assign, new IdentifierExpression ("value")))
};
using (var script = context.StartScript ()) {
script.Replace (property, newProperty);
script.InsertBefore (property, backingStore);
script.Link (initializer, id1, id2);
}
}
示例5: GenerateNewScript
void GenerateNewScript(Script script, FieldDeclaration fieldDeclaration, RefactoringContext context)
{
var firstOrNullObject = fieldDeclaration.Variables.FirstOrNullObject();
if(firstOrNullObject==null)
return;
var matchedNodes = ComputeMatchNodes(context, firstOrNullObject);
foreach (var matchNode in matchedNodes)
{
var parent = matchNode.Parent;
if (matchNode is VariableInitializer)
{
script.Remove(parent);
}
else
if (matchNode is IdentifierExpression)
{
if(parent is AssignmentExpression)
{
script.Remove(parent.Parent);
}
else
{
var clone = (IdentifierExpression)matchNode.Clone();
clone.Identifier = "TODO";
script.Replace(matchNode, clone);
}
}
}
}
示例6: VisitFieldDeclaration
public override void VisitFieldDeclaration(FieldDeclaration fieldDeclaration)
{
CLRType t = m_clrTypes.Value.Last.Value;
string name = fieldDeclaration.Variables.Single().Name;
string returnType = fieldDeclaration.ReturnType.ToString();
Visibility v = new Visibility(VisibilityMapper.Map(fieldDeclaration.Modifiers));
if (CheckFlag(fieldDeclaration.Modifiers, Modifiers.Const))
{
ConstField cf = new ConstField(v, name, returnType, fieldDeclaration.Variables.Single().Initializer.ToString());
t.ConstantFields.Add(cf); // connect
}
else
{
Field f = new Field(
CheckFlag(fieldDeclaration.Modifiers, Modifiers.Static),
CheckFlag(fieldDeclaration.Modifiers, Modifiers.Readonly),
v,
CheckFlag(fieldDeclaration.Modifiers, Modifiers.Virtual),
name,
CheckFlag(fieldDeclaration.Modifiers, Modifiers.Abstract),
returnType
);
t.Fields.Add(f); // connect
}
AddToNotDefaultReferencedTypes(returnType);
// call base to forward execution
base.VisitFieldDeclaration(fieldDeclaration);
}
示例7: AddFieldForLocal
internal FieldDeclaration AddFieldForLocal(SimpleName localName, Expression initialValue, ISourceLocation sourceLocation) {
FieldDeclaration field = new FieldDeclaration(null, FieldDeclaration.Flags.Static, TypeMemberVisibility.Private,
TypeExpression.For(initialValue.Type), new NameDeclaration(localName.Name, localName.SourceLocation), null, sourceLocation);
field.SetContainingTypeDeclaration(this, false);
this.members.Add(field);
this.localFieldFor.Add(localName.Name.UniqueKeyIgnoringCase, field.FieldDefinition);
return field;
}
示例8: VisitFieldDeclaration
public override void VisitFieldDeclaration(FieldDeclaration fieldDeclaration)
{
if (fieldDeclaration.HasModifier(Modifiers.Static))
{
this.CheckDependency(fieldDeclaration.ReturnType);
base.VisitFieldDeclaration(fieldDeclaration);
}
}
示例9: Verify
public void Verify()
{
FieldDeclaration field = new FieldDeclaration("_customer", new CodeDomTypeReference(typeof(int)));
Assert.AreEqual("_customer", field.Name);
field.Initialize = true;
CodeMemberField codefield = field.ToCodeDom();
Assert.AreEqual("_customer", codefield.Name);
Assert.AreEqual("System.Int32", codefield.Type.BaseType);
}
示例10: AddStandardMembers
internal void AddStandardMembers(Compilation compilation, List<Statement> bodyOfMainRoutine) {
NameDeclaration labelOfFirstStatement = new NameDeclaration(compilation.NameTable.GetNameFor("<<first statement>>"), SourceDummy.SourceLocation);
FieldDeclaration labelField = new FieldDeclaration(null, 0, TypeMemberVisibility.Private,
TypeExpression.For(compilation.PlatformType.SystemInt32.ResolvedType), labelOfFirstStatement, null, SourceDummy.SourceLocation);
this.members.Add(labelField);
this.AddMainMethod(compilation, bodyOfMainRoutine, labelField);
this.AddEntryPointMethod(compilation);
this.AddConstructor(compilation);
}
示例11: VisitFieldDeclaration
public override object VisitFieldDeclaration(FieldDeclaration fieldDeclaration, object data)
{
if ((fieldDeclaration.Modifiers & Modifiers.Const) == Modifiers.Const)
{
UnlockWith(fieldDeclaration);
}
return base.VisitFieldDeclaration(fieldDeclaration, data);
}
示例12: FieldReferenceExpression
public FieldReferenceExpression(Expression target,FieldDeclaration field)
{
if (target==null)
throw new ArgumentNullException("target");
if (field==null)
throw new ArgumentNullException("field");
this.target = target;
this.declaringField = field;
}
示例13: AddMainMethod
private void AddMainMethod(Compilation compilation, List<Statement> bodyOfMainRoutine, FieldDeclaration labelField) {
MethodDeclaration mainMethod = new MethodDeclaration(null, 0, TypeMemberVisibility.Public,
TypeExpression.For(compilation.PlatformType.SystemVoid.ResolvedType), null, new NameDeclaration(compilation.NameTable.GetNameFor("Main"), SourceDummy.SourceLocation), null,
null, null, new BlockStatement(bodyOfMainRoutine, this.SourceLocation), this.SourceLocation);
bodyOfMainRoutine.Add(new SwitchStatement(new SimpleName(labelField.Name, SourceDummy.SourceLocation, false), this.cases, SourceDummy.SourceLocation));
bodyOfMainRoutine.Add(new LabeledStatement(new NameDeclaration(labelField.Name, SourceDummy.SourceLocation), new EmptyStatement(false, SourceDummy.SourceLocation), SourceDummy.SourceLocation));
this.AddLabel(new SimpleName(labelField.Name, SourceDummy.SourceLocation, false));
this.members.Add(mainMethod);
this.mainMethod = mainMethod;
}
示例14: Create
public static OverloadsCollection Create(IEmitter emitter, FieldDeclaration fieldDeclaration)
{
string key = fieldDeclaration.GetHashCode().ToString();
if (emitter.OverloadsCache.ContainsKey(key))
{
return emitter.OverloadsCache[key];
}
return new OverloadsCollection(emitter, fieldDeclaration);
}
示例15: GetFieldDeclaration
protected FieldDeclaration GetFieldDeclaration(String name, AstType propertyType)
{
var declaration = new FieldDeclaration();
declaration.Name = name;
declaration.Modifiers = Modifiers.Public;
declaration.ReturnType = propertyType;
IDELogger.Log("BaseRefactoringDialog::GetFieldDeclaration -- {0}", declaration.Name);
return declaration;
}