本文整理汇总了C#中ICSharpCode.NRefactory.Ast.UsingDeclaration类的典型用法代码示例。如果您正苦于以下问题:C# UsingDeclaration类的具体用法?C# UsingDeclaration怎么用?C# UsingDeclaration使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
UsingDeclaration类属于ICSharpCode.NRefactory.Ast命名空间,在下文中一共展示了UsingDeclaration类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: VisitUsingDeclaration
public object VisitUsingDeclaration(UsingDeclaration usingDeclaration, object data)
{
foreach (Using u in usingDeclaration.Usings) {
VisitUsing(u, data);
}
return null;
}
示例2: UsingDirective
void UsingDirective() {
#line 189 "cs.ATG"
string qualident = null; TypeReference aliasedType = null;
Expect(121);
#line 192 "cs.ATG"
Location startPos = t.Location;
Qualident(
#line 193 "cs.ATG"
out qualident);
if (la.kind == 3) {
lexer.NextToken();
NonArrayType(
#line 194 "cs.ATG"
out aliasedType);
}
Expect(11);
#line 196 "cs.ATG"
if (qualident != null && qualident.Length > 0) {
INode node;
if (aliasedType != null) {
node = new UsingDeclaration(qualident, aliasedType);
} else {
node = new UsingDeclaration(qualident);
}
node.StartLocation = startPos;
node.EndLocation = t.EndLocation;
compilationUnit.AddChild(node);
}
}
示例3: RemoveCurrentNamespaceUsings
public void RemoveCurrentNamespaceUsings()
{
string program = @"package Janett.Translator;
public class Translation
{
}";
string expected = @"namespace Janett.Translator
{
public class Translation
{
}
}";
CompilationUnit cu = TestUtil.ParseProgram(program);
NamespaceDeclaration ns = (NamespaceDeclaration) cu.Children[0];
UsingDeclaration us1 = new UsingDeclaration("Refactoring", AstUtil.GetTypeReference("Janett.Translator.Refactoring", ns));
UsingDeclaration us2 = new UsingDeclaration("Transformation", AstUtil.GetTypeReference("Janett.Translator.Transformation", ns));
ns.Children.Insert(0, us2);
ns.Children.Insert(0, us1);
us1.Parent = ns;
us2.Parent = ns;
VisitCompilationUnit(cu, null);
TestUtil.CodeEqual(expected, TestUtil.GenerateCode(cu));
}
示例4: VisitUsingDeclaration
public override object VisitUsingDeclaration(UsingDeclaration usingDeclaration, object data)
{
base.VisitUsingDeclaration(usingDeclaration, data);
if (usingDeclaration.Usings.Count == 0) {
RemoveCurrentNode();
}
return null;
}
示例5: TrackedVisitUsingDeclaration
public override object TrackedVisitUsingDeclaration(UsingDeclaration usingDeclaration, object data)
{
Using usi = (Using) usingDeclaration.Usings[0];
string type = GetShortReferenceTypeName(usi);
if (similarTypes.Contains(type))
RemoveCurrentNode();
return null;
}
示例6: VisitUsingDeclaration
public override object VisitUsingDeclaration(UsingDeclaration usingDeclaration, object data)
{
base.VisitUsingDeclaration(usingDeclaration, data);
if (usingDeclaration.Parent is NamespaceDeclaration) {
nodesToMoveToCompilationUnit.Add(usingDeclaration);
RemoveCurrentNode();
}
return null;
}
示例7: VisitUsingDeclaration
public override object VisitUsingDeclaration(UsingDeclaration usingDeclaration, object data)
{
foreach (var usingLine in usingDeclaration.Usings)
if (usingLine.IsAlias)
TypeResolver.AliasNamespace(usingLine.Name, usingLine.Alias.Type);
else
TypeResolver.UseNamespace(usingLine.Name);
return base.VisitUsingDeclaration(usingDeclaration, data);
}
示例8: TrackedVisitNamespaceDeclaration
public override object TrackedVisitNamespaceDeclaration(NamespaceDeclaration namespaceDeclaration, object data)
{
NamespaceDeclaration replacedNamespace = namespaceDeclaration;
UsingDeclaration usingDeclaration = new UsingDeclaration("java.lang.*");
replacedNamespace.Children.Insert(0, usingDeclaration);
ReplaceCurrentNode(replacedNamespace);
return base.TrackedVisitNamespaceDeclaration(namespaceDeclaration, data);
}
示例9: VisitUsingDeclaration
public override object VisitUsingDeclaration (UsingDeclaration node, object data)
{
//Usings = new HashSet<string> ();
foreach (Using item in node.Usings) {
if (item.IsAlias)
throw CreateException (node, "Aliases not are supported");
if (!Usings.Contains (item.Name))
Usings.Add (item.Name);
}
return null;
}
示例10: AddUsing
private void AddUsing(INode currentNode, object data, string name)
{
string ns = name.Substring(name.LastIndexOf('.') + 1);
NamespaceDeclaration namespaceDeclaration = (NamespaceDeclaration) AstUtil.GetParentOfType(currentNode, typeof(NamespaceDeclaration));
UsingDeclaration usingDeclaration = new UsingDeclaration(ns);
usingDeclaration.Parent = namespaceDeclaration;
((Using) usingDeclaration.Usings[0]).Alias = AstUtil.GetTypeReference(name, usingDeclaration);
IList usings = AstUtil.GetChildrenWithType(namespaceDeclaration, typeof(UsingDeclaration));
if (! ContainsUsing(usings, usingDeclaration) && !ContainsUsing((IList) data, usingDeclaration))
((IList) data).Add(usingDeclaration);
}
示例11: add_Using
public static UsingDeclaration add_Using(this CompilationUnit compilationUnit, string @namespace)
{
@namespace = @namespace.remove(";").trim();
var currentUsingDeclaration = [email protected](@namespace);
if (currentUsingDeclaration != null)
// these UsingDeclaration & Using classes are a bit of a mess (need to normalize this later)
return new UsingDeclaration(currentUsingDeclaration.wrapOnList());
var newUsing = new UsingDeclaration(@namespace);
compilationUnit.insert(newUsing);
return newUsing;
}
示例12: FieldTwoLayerInvocation
public void FieldTwoLayerInvocation()
{
string program = TestUtil.StatementParse("Field f; f.getName().indexOf('$')");
string expected = TestUtil.StatementParse("Field f; java.lang.String.instancehelper_indexOf(f.getName(), '$')");
CompilationUnit cu = TestUtil.ParseProgram(program);
CompilationUnit cv = TestUtil.ParseProgram(expected);
UsingDeclaration usiDec = new UsingDeclaration("Field", new TypeReference("java.lang.reflect.Field"));
((NamespaceDeclaration) cu.Children[0]).Children.Insert(0, usiDec);
((NamespaceDeclaration) cv.Children[0]).Children.Insert(0, usiDec);
VisitCompilationUnit(cu, null);
TestUtil.CodeEqual(TestUtil.GenerateCode(cv), TestUtil.GenerateCode(cu));
}
示例13: AddAssembly
public void AddAssembly(AssemblyDefinition assemblyDefinition)
{
Ast.UsingDeclaration astUsing = new Ast.UsingDeclaration("System");
astCompileUnit.Children.Add(astUsing);
foreach(TypeDefinition typeDef in assemblyDefinition.MainModule.Types) {
// Skip nested types - they will be added by the parent type
if (typeDef.DeclaringType != null) continue;
// Skip the <Module> class
if (typeDef.Name == "<Module>") continue;
AddType(typeDef);
}
}
示例14: Used
public void Used()
{
string program = TestUtil.PackageMemberParse("public class A {object obj = new ToStringBuilder();}");
string expected = TestUtil.NamespaceMemberParse("using ToStringBuilder = NClassifier.Util.ToStringBuilder; public class A {object obj = new ToStringBuilder();}");
CompilationUnit cu = TestUtil.ParseProgram(program);
NamespaceDeclaration ns = (NamespaceDeclaration) cu.Children[0];
UsingDeclaration us = new UsingDeclaration("ToStringBuilder", AstUtil.GetTypeReference("NClassifier.Util.ToStringBuilder", ns));
ns.Children.Insert(0, us);
us.Parent = ns;
Mode = "DotNet";
VisitCompilationUnit(cu, null);
TestUtil.CodeEqual(expected, TestUtil.GenerateCode(cu));
}
示例15: ContainsUsing
private bool ContainsUsing(IList usingList, UsingDeclaration usingDec)
{
foreach (UsingDeclaration usi in usingList)
{
Using usingDeclared = (Using) usingDec.Usings[0];
Using usiUsing = (Using) usi.Usings[0];
if (usiUsing.IsAlias && usingDeclared.IsAlias)
{
if (usiUsing.Name == usingDeclared.Name &&
usiUsing.Alias.Type == usingDeclared.Alias.Type)
return true;
}
else if (!(usiUsing.IsAlias && usingDeclared.IsAlias))
{
if (usingDeclared.Name == usiUsing.Name)
return true;
}
}
return false;
}