本文整理汇总了C#中ICSharpCode.NRefactory.Ast.CompilationUnit类的典型用法代码示例。如果您正苦于以下问题:C# CompilationUnit类的具体用法?C# CompilationUnit怎么用?C# CompilationUnit使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
CompilationUnit类属于ICSharpCode.NRefactory.Ast命名空间,在下文中一共展示了CompilationUnit类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GenerateText
public static string GenerateText(TypeDeclaration type, OrderedPartCollection<AbstractDynamicCompilationExtension> extensions)
{
var unit = new CompilationUnit();
var namespaces = new HashSet<string>
{
typeof (SystemTime).Namespace,
typeof (AbstractViewGenerator).Namespace,
typeof (Enumerable).Namespace,
typeof (IEnumerable<>).Namespace,
typeof (IEnumerable).Namespace,
typeof (int).Namespace,
typeof (LinqOnDynamic).Namespace,
typeof(Field).Namespace,
};
foreach (var extension in extensions)
{
foreach (var ns in extension.Value.GetNamespacesToImport())
{
namespaces.Add(ns);
}
}
foreach (var ns in namespaces)
{
unit.AddChild(new Using(ns));
}
unit.AddChild(type);
var output = new CSharpOutputVisitor();
unit.AcceptVisitor(output, null);
return output.Text;
}
示例2: VisitCompilationUnit
public override object VisitCompilationUnit(CompilationUnit compilationUnit, object data)
{
base.VisitCompilationUnit(compilationUnit, data);
ToVBNetConvertVisitor v = new ToVBNetConvertVisitor();
compilationUnit.AcceptVisitor(v, data);
return null;
}
示例3: VBNET
/*
*/
void VBNET() {
#line 231 "VBNET.ATG"
lexer.NextToken(); // get the first token
compilationUnit = new CompilationUnit();
while (la.kind == 1) {
lexer.NextToken();
}
while (la.kind == 136) {
OptionStmt();
}
while (la.kind == 108) {
ImportsStmt();
}
while (
#line 237 "VBNET.ATG"
IsGlobalAttrTarget()) {
GlobalAttributeSection();
}
while (StartOf(1)) {
NamespaceMemberDecl();
}
Expect(0);
}
示例4: VisitCompilationUnit
public object VisitCompilationUnit(CompilationUnit compilationUnit, object data)
{
module = new B.Module();
module.LexicalInfo = new B.LexicalInfo(fileName, 1, 1);
compilationUnit.AcceptChildren(this, data);
if (entryPointMethod != null) {
bool allMembersAreStatic = true;
foreach (B.TypeMember member in entryPointMethod.DeclaringType.Members) {
allMembersAreStatic &= member.IsStatic;
}
if (allMembersAreStatic) {
entryPointMethod.DeclaringType.Attributes.Add(MakeAttribute(("module")));
} else {
lastLexicalInfo = entryPointMethod.LexicalInfo;
B.Expression expr = MakeReferenceExpression(entryPointMethod.DeclaringType.Name + ".Main");
B.MethodInvocationExpression mie = new B.MethodInvocationExpression(lastLexicalInfo, expr);
if (entryPointMethod.Parameters.Count > 0) {
mie.Arguments.Add(MakeReferenceExpression("argv"));
}
B.SimpleTypeReference ret = entryPointMethod.ReturnType as B.SimpleTypeReference;
if (ret.Name == "void" || ret.Name == "System.Void")
module.Globals.Add(new B.ExpressionStatement(mie));
else
module.Globals.Add(new B.ReturnStatement(lastLexicalInfo, mie, null));
}
}
B.Module tmp = module;
module = null;
return tmp;
}
示例5: CheckAliases
void CheckAliases(CompilationUnit u)
{
Assert.AreEqual(3, u.Children.Count);
Assert.IsTrue(u.Children[0] is UsingDeclaration);
UsingDeclaration ud = (UsingDeclaration)u.Children[0];
Assert.AreEqual(1, ud.Usings.Count);
Assert.IsTrue(((Using)ud.Usings[0]).IsAlias);
Assert.AreEqual("TESTME", ud.Usings[0].Name);
Assert.AreEqual("System", ud.Usings[0].Alias.Type);
Assert.IsTrue(u.Children[1] is UsingDeclaration);
ud = (UsingDeclaration)u.Children[1];
Assert.AreEqual(1, ud.Usings.Count);
Assert.IsTrue(((Using)ud.Usings[0]).IsAlias);
Assert.AreEqual("myAlias", ud.Usings[0].Name);
Assert.AreEqual("My.Name.Space", ud.Usings[0].Alias.Type);
Assert.IsTrue(u.Children[2] is UsingDeclaration);
ud = (UsingDeclaration)u.Children[2];
Assert.AreEqual(1, ud.Usings.Count);
Assert.IsTrue(((Using)ud.Usings[0]).IsAlias);
Assert.AreEqual("StringCollection", ud.Usings[0].Name);
Assert.AreEqual("System.Collections.Generic.List", ud.Usings[0].Alias.Type);
Assert.AreEqual("System.String", ud.Usings[0].Alias.GenericTypes[0].Type);
}
示例6: VisitCompilationUnit
public override object VisitCompilationUnit(CompilationUnit compilationUnit, object data)
{
base.VisitCompilationUnit(compilationUnit, data);
if (!string.IsNullOrEmpty(NamespacePrefixToAdd)) {
for (int i = 0; i < compilationUnit.Children.Count; i++) {
NamespaceDeclaration ns = compilationUnit.Children[i] as NamespaceDeclaration;
if (ns != null) {
ns.Name = NamespacePrefixToAdd + "." + ns.Name;
}
if (compilationUnit.Children[i] is TypeDeclaration || compilationUnit.Children[i] is DelegateDeclaration) {
ns = new NamespaceDeclaration(NamespacePrefixToAdd);
ns.AddChild(compilationUnit.Children[i]);
compilationUnit.Children[i] = ns;
}
}
}
ToCSharpConvertVisitor v = new ToCSharpConvertVisitor();
compilationUnit.AcceptVisitor(v, data);
if (projectContent != null && projectContent.DefaultImports != null) {
int index = 0;
foreach (string u in projectContent.DefaultImports.Usings) {
compilationUnit.Children.Insert(index++, new UsingDeclaration(u));
}
}
return null;
}
示例7: VisitCompilationUnit
public override object VisitCompilationUnit(CompilationUnit compilationUnit, object data)
{
_treeService.PushArea("Components");
object r = base.VisitCompilationUnit(compilationUnit, data);
_treeService.PopNode();
return base.VisitCompilationUnit(compilationUnit, data);
}
示例8: RemoveWindowsFormsSpecificCode
void RemoveWindowsFormsSpecificCode(CompilationUnit compilationUnit, List<ISpecial> specials, bool keepCode)
{
for (int i = 0; i < specials.Count; i++) {
PreprocessingDirective ppd = specials[i] as PreprocessingDirective;
if (ppd != null && ppd.Cmd == "#if") {
if (ppd.Arg == "_MyType = \"WindowsForms\"") {
int depth = 1;
for (int j = i + 1; j < specials.Count; j++) {
ppd = specials[j] as PreprocessingDirective;
if (ppd != null) {
if (ppd.Cmd == "#if") {
depth++;
} else if (ppd.Cmd == "#endif") {
depth--;
if (depth == 0) {
if (keepCode) {
// keep code, remove only the ifdef
specials.RemoveAt(j);
specials.RemoveAt(i);
} else {
// remove ifdef including the code
compilationUnit.AcceptVisitor(new RemoveMembersInRangeVisitor(
DomRegion.FromLocation(specials[i].StartPosition, specials[j].EndPosition)), null);
specials.RemoveRange(i, j - i + 1);
}
i--;
break;
}
}
}
}
}
}
}
}
示例9: Parse
INode Parse(SupportedLanguage sourceLanguage, string sourceCode, out string error)
{
project = new DefaultProjectContent();
project.ReferencedContents.AddRange(ReferencedContents);
if (sourceLanguage == SupportedLanguage.VBNet) {
project.Language = LanguageProperties.VBNet;
project.DefaultImports = new DefaultUsing(project);
project.DefaultImports.Usings.AddRange(DefaultImportsToAdd);
} else {
project.Language = LanguageProperties.CSharp;
}
SnippetParser parser = new SnippetParser(sourceLanguage);
INode result = parser.Parse(sourceCode);
error = parser.Errors.ErrorOutput;
specials = parser.Specials;
if (parser.Errors.Count != 0)
return null;
wasExpression = parser.SnippetType == SnippetType.Expression;
if (wasExpression) {
// Special case 'Expression': expressions may be replaced with other statements in the AST by the ConvertVisitor,
// but we need to return a 'stable' node so that the correct transformed AST is returned.
// Thus, we wrap any expressions into a statement block.
result = MakeBlockFromExpression((Expression)result);
}
// now create a dummy compilation unit around the snippet result
switch (parser.SnippetType) {
case SnippetType.CompilationUnit:
compilationUnit = (CompilationUnit)result;
break;
case SnippetType.Expression:
case SnippetType.Statements:
compilationUnit = MakeCompilationUnitFromTypeMembers(
MakeMethodFromBlock(
(BlockStatement)result
));
break;
case SnippetType.TypeMembers:
compilationUnit = MakeCompilationUnitFromTypeMembers(result.Children);
break;
default:
throw new NotSupportedException("Unknown snippet type: " + parser.SnippetType);
}
// convert NRefactory CU in DOM CU
NRefactoryASTConvertVisitor visitor = new NRefactoryASTConvertVisitor(project);
visitor.VisitCompilationUnit(compilationUnit, null);
visitor.Cu.FileName = sourceLanguage == SupportedLanguage.CSharp ? "a.cs" : "a.vb";
// and register the compilation unit in the DOM
foreach (IClass c in visitor.Cu.Classes) {
project.AddClassToNamespaceList(c);
}
parseInfo = new ParseInformation();
parseInfo.SetCompilationUnit(visitor.Cu);
return result;
}
示例10: Ast_CSharp
public Ast_CSharp(CompilationUnit unit, List<ISpecial> extraSpecials)
{
createAst("");
ExtraSpecials = extraSpecials;
mapAstDetails(unit);
//mapAstDetails(Parser.CompilationUnit);
}
示例11: SetUp
public API_ASMX_Proxy SetUp()
{
PropName = "_web_Service";
Proxy_CompilationUnit = new CompilationUnit();
Proxy_CompilationUnit.add_Using("System");
Proxy_CompilationUnit.add_Using("System.Web.Services");
return this;
}
示例12: VisitCompilationUnit
public override object VisitCompilationUnit(CompilationUnit compilationUnit, object data)
{
Contract.Requires(compilationUnit != null);
// Visit children (E.g. TypeDcelarion objects)
compilationUnit.AcceptChildren(this, data);
return null;
}
示例13: VisitCompilationUnit
public override object VisitCompilationUnit(CompilationUnit compilationUnit, object data)
{
base.VisitCompilationUnit(compilationUnit, data);
for (int i = 0; i < nodesToMoveToCompilationUnit.Count; i++) {
compilationUnit.Children.Insert(i, nodesToMoveToCompilationUnit[i]);
nodesToMoveToCompilationUnit[i].Parent = compilationUnit;
}
return null;
}
示例14: rewriteCode_CSharp
public void rewriteCode_CSharp(CompilationUnit unit, IList<ISpecial> specials)
{
var outputVisitor = new CSharpOutputVisitor();
using (SpecialNodesInserter.Install(specials, outputVisitor)) {
unit.AcceptVisitor(outputVisitor, null);
}
//codeTextBox.Text = outputVisitor.Text.Replace("\t", " ");
CSharpCode = outputVisitor.Text;
}
示例15: GetStatementNodeOf
public static Expression GetStatementNodeOf(CompilationUnit compilationUnit, int index)
{
NamespaceDeclaration ns = (NamespaceDeclaration) compilationUnit.Children[0];
TypeDeclaration ty = (TypeDeclaration) ns.Children[0];
MethodDeclaration md = (MethodDeclaration) ty.Children[0];
ExpressionStatement st = (ExpressionStatement) md.Body.Children[index];
Expression exp = st.Expression;
return exp;
}