本文整理汇总了C#中ICSharpCode.NRefactory.Ast.CompilationUnit类的典型用法代码示例。如果您正苦于以下问题:C# CompilationUnit类的具体用法?C# CompilationUnit怎么用?C# CompilationUnit使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
CompilationUnit类属于ICSharpCode.NRefactory.Ast命名空间,在下文中一共展示了CompilationUnit类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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;
}
开发者ID:iamnilay3,项目名称:ravendb,代码行数:34,代码来源:QueryParsingUtils.cs
示例2: VisitCompilationUnit
public override object VisitCompilationUnit(CompilationUnit compilationUnit, object data)
{
base.VisitCompilationUnit(compilationUnit, data);
ToVBNetConvertVisitor v = new ToVBNetConvertVisitor();
compilationUnit.AcceptVisitor(v, data);
return null;
}
开发者ID:Adam-Fogle,项目名称:agentralphplugin,代码行数:7,代码来源:CSharpToVBNetConvertVisitor.cs
示例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);
}
开发者ID:almazik,项目名称:ILSpy,代码行数:29,代码来源:Parser.cs
示例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;
}
开发者ID:Bombadil77,项目名称:SharpDevelop,代码行数:30,代码来源:ConvertVisitorGlobal.cs
示例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);
}
开发者ID:pusp,项目名称:o2platform,代码行数:26,代码来源:UsingDeclarationTests.cs
示例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;
}
开发者ID:SiGhTfOrbACQ,项目名称:O2.Platform.Projects,代码行数:27,代码来源:VBNetToCSharpConvertVisitor.cs
示例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);
}
开发者ID:mgagne-atman,项目名称:Projects,代码行数:7,代码来源:ViewComponentVisitor.cs
示例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;
}
}
}
}
}
}
}
}
开发者ID:Bombadil77,项目名称:SharpDevelop,代码行数:35,代码来源:VBNetToCSharpConverter.cs
示例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;
}
开发者ID:kingjiang,项目名称:SharpDevelopLite,代码行数:59,代码来源:CodeSnippetConverter.cs
示例10: Ast_CSharp
public Ast_CSharp(CompilationUnit unit, List<ISpecial> extraSpecials)
{
createAst("");
ExtraSpecials = extraSpecials;
mapAstDetails(unit);
//mapAstDetails(Parser.CompilationUnit);
}
开发者ID:njmube,项目名称:FluentSharp,代码行数:8,代码来源:Ast_CSharp.cs
示例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;
}
开发者ID:paul-green,项目名称:O2.Platform.Scripts,代码行数:8,代码来源:API_ASMX_Proxy.cs
示例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;
}
开发者ID:chinaniit,项目名称:KnockoutGenerator,代码行数:9,代码来源:AstVisitor.cs
示例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;
}
开发者ID:Altaxo,项目名称:Altaxo,代码行数:9,代码来源:ToVBNetConvertVisitor.cs
示例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;
}
开发者ID:pusp,项目名称:o2platform,代码行数:9,代码来源:AstDetails.cs
示例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;
}
开发者ID:sourcewarehouse,项目名称:janett,代码行数:9,代码来源:TestUtil.cs
示例16: ConvertAst
protected override void ConvertAst(CompilationUnit compilationUnit, List<ISpecial> specials, FileProjectItem sourceItem)
{
PreprocessingDirective.CSharpToVB(specials);
IProjectContent pc = ParserService.GetProjectContent(sourceItem.Project) ?? ParserService.CurrentProjectContent;
CSharpToVBNetConvertVisitor visitor = new CSharpToVBNetConvertVisitor(pc, ParserService.GetParseInformation(sourceItem.FileName));
visitor.RootNamespaceToRemove = sourceItem.Project.RootNamespace;
visitor.DefaultImportsToRemove = defaultImports;
visitor.StartupObjectToMakePublic = startupObject;
compilationUnit.AcceptVisitor(visitor, null);
}
开发者ID:Bombadil77,项目名称:SharpDevelop,代码行数:10,代码来源:CSharpToVBNetConverter.cs
示例17: VisitCompilationUnit
public override object VisitCompilationUnit(CompilationUnit compilationUnit, object data)
{
Contract.Requires(compilationUnit != null);
DictClass = new Dictionary<string, ClassStructure>();
// Visit children (E.g. TypeDcelarion objects)
compilationUnit.AcceptChildren(this, data);
return null;
}
开发者ID:hikaruyh88,项目名称:ProjectAnalyzeV3.0,代码行数:10,代码来源:CounterVisitor.cs
示例18: ConvertAst
protected override void ConvertAst(CompilationUnit compilationUnit, List<ISpecial> specials, FileProjectItem sourceItem)
{
PreprocessingDirective.VBToCSharp(specials);
CompilableProject project = (CompilableProject)sourceItem.Project;
RemoveWindowsFormsSpecificCode(compilationUnit, specials, project.OutputType == OutputType.WinExe);
IProjectContent pc = ParserService.GetProjectContent(sourceItem.Project) ?? ParserService.CurrentProjectContent;
VBNetToCSharpConvertVisitor visitor = new VBNetToCSharpConvertVisitorWithMyFormsSupport(pc, ParserService.GetParseInformation(sourceItem.FileName), sourceItem.Project.RootNamespace);
compilationUnit.AcceptVisitor(visitor, null);
}
开发者ID:kingjiang,项目名称:SharpDevelopLite,代码行数:10,代码来源:VBNetToCSharpConverter.cs
示例19: loadCompilationUnit
//DC
/* public void loadCode(string code)
{
code = (code.fileExists()) ? code.fileContents() : code;
var parser = code.csharpAst();
loadCompilationUnit(parser.CompilationUnit);
}*/
//DC
public void loadCompilationUnit(CompilationUnit compilationUnit)
{
try
{
compilationUnit.AcceptVisitor(this, null);
}
catch (Exception ex)
{
ex.log("in MapAstToDom loadCompilationUnit");
}
}
开发者ID:pusp,项目名称:o2platform,代码行数:19,代码来源:MapAstToDom.cs
示例20: Parse
INode Parse(SupportedLanguage sourceLanguage, string sourceCode, out string error)
{
project = new DefaultProjectContent();
project.ReferencedContents.AddRange(ReferencedContents);
if (sourceLanguage == SupportedLanguage.VBNet) {
project.DefaultImports = new DefaultUsing(project);
project.DefaultImports.Usings.AddRange(DefaultImportsToAdd);
}
SnippetParser parser = new SnippetParser(sourceLanguage);
INode result = parser.Parse(sourceCode);
error = parser.Errors.ErrorOutput;
specials = parser.Specials;
if (parser.Errors.Count != 0)
return null;
// now create a dummy compilation unit around the snippet result
switch (parser.SnippetType) {
case SnippetType.CompilationUnit:
compilationUnit = (CompilationUnit)result;
break;
case SnippetType.Expression:
compilationUnit = MakeCompilationUnitFromTypeMembers(
MakeMethodFromBlock(
MakeBlockFromExpression(
(Expression)result
)));
break;
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;
}
开发者ID:Adam-Fogle,项目名称:agentralphplugin,代码行数:54,代码来源:CodeSnippetConverter.cs
注:本文中的ICSharpCode.NRefactory.Ast.CompilationUnit类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论