当前位置: 首页>>代码示例>>C#>>正文


C# AstBuilder.AddField方法代码示例

本文整理汇总了C#中ICSharpCode.Decompiler.Ast.AstBuilder.AddField方法的典型用法代码示例。如果您正苦于以下问题:C# AstBuilder.AddField方法的具体用法?C# AstBuilder.AddField怎么用?C# AstBuilder.AddField使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ICSharpCode.Decompiler.Ast.AstBuilder的用法示例。


在下文中一共展示了AstBuilder.AddField方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: CreateBuilder

		AstBuilder CreateBuilder(IDnlibDef item, CancellationToken token) {
			ModuleDef moduleDef;

			DecompilerContext ctx;
			AstBuilder builder;

			if (item is ModuleDef) {
				var def = (ModuleDef)item;
				moduleDef = def;
				builder = new AstBuilder(ctx = new DecompilerContext(moduleDef) { CancellationToken = token });
				builder.AddAssembly(def, true);
			}
			else if (item is TypeDef) {
				var def = (TypeDef)item;
				moduleDef = def.Module;
				builder = new AstBuilder(ctx = new DecompilerContext(moduleDef) { CancellationToken = token });
				builder.DecompileMethodBodies = false;
				ctx.CurrentType = def;
				builder.AddType(def);
			}
			else if (item is MethodDef) {
				var def = (MethodDef)item;
				moduleDef = def.Module;
				builder = new AstBuilder(ctx = new DecompilerContext(moduleDef) { CancellationToken = token });
				ctx.CurrentType = def.DeclaringType;
				builder.AddMethod(def);
			}
			else if (item is FieldDef) {
				var def = (FieldDef)item;
				moduleDef = def.Module;
				builder = new AstBuilder(ctx = new DecompilerContext(moduleDef) { CancellationToken = token });
				ctx.CurrentType = def.DeclaringType;
				builder.AddField(def);
			}
			else if (item is PropertyDef) {
				var def = (PropertyDef)item;
				moduleDef = def.Module;
				builder = new AstBuilder(ctx = new DecompilerContext(moduleDef) { CancellationToken = token });
				ctx.CurrentType = def.DeclaringType;
				builder.AddProperty(def);
			}
			else if (item is EventDef) {
				var def = (EventDef)item;
				moduleDef = def.Module;
				builder = new AstBuilder(ctx = new DecompilerContext(moduleDef) { CancellationToken = token });
				ctx.CurrentType = def.DeclaringType;
				builder.AddEvent(def);
			}
			else
				return null;

			ctx.Settings = new DecompilerSettings {
				UsingDeclarations = false
			};
			return builder;
		}
开发者ID:mamingxiu,项目名称:dnExplorer,代码行数:56,代码来源:CSharpLanguage.cs

示例2: AddFieldsAndCtors

 void AddFieldsAndCtors(AstBuilder codeDomBuilder, TypeDefinition declaringType, bool isStatic)
 {
     foreach (var field in declaringType.Fields)
     {
         if (field.IsStatic == isStatic)
             codeDomBuilder.AddField(field);
     }
     foreach (var ctor in declaringType.Methods)
     {
         if (ctor.IsConstructor && ctor.IsStatic == isStatic)
             codeDomBuilder.AddMethod(ctor);
     }
 }
开发者ID:dpvreony-forks,项目名称:CodePerspective,代码行数:13,代码来源:Decompile.ICSharp.cs

示例3: GetTooltip

		public override string GetTooltip(MemberReference member)
		{
			MethodDefinition md = member as MethodDefinition;
			PropertyDefinition pd = member as PropertyDefinition;
			EventDefinition ed = member as EventDefinition;
			FieldDefinition fd = member as FieldDefinition;
			if (md != null || pd != null || ed != null || fd != null) {
				AstBuilder b = new AstBuilder(new DecompilerContext(member.Module) { Settings = new DecompilerSettings { UsingDeclarations = false } });
				b.DecompileMethodBodies = false;
				if (md != null)
					b.AddMethod(md);
				else if (pd != null)
					b.AddProperty(pd);
				else if (ed != null)
					b.AddEvent(ed);
				else
					b.AddField(fd);
				b.RunTransformations();
				foreach (var attribute in b.CompilationUnit.Descendants.OfType<AttributeSection>())
					attribute.Remove();

				StringWriter w = new StringWriter();
				b.GenerateCode(new PlainTextOutput(w));
				return Regex.Replace(w.ToString(), @"\s+", " ").TrimEnd();
			}

			return base.GetTooltip(member);
		}
开发者ID:Netring,项目名称:ILSpy,代码行数:28,代码来源:CSharpLanguage.cs

示例4: Decompile

 public ICSharpCode.AvalonEdit.Document.TextDocument Decompile(object obj)
 {
     AvalonEditTextOutput aeto = new AvalonEditTextOutput();
     AstBuilder ast = new AstBuilder(new DecompilerContext(ModuleDefinition.CreateModule("ash", ModuleKind.NetModule)));
     switch (obj.GetType().Name)
     {
         case "AssemblyDefinition":
             ast = new AstBuilder(new DecompilerContext((obj as AssemblyDefinition).MainModule) { Settings = new DecompilerSettings() });
             try { ast.AddAssembly(obj as AssemblyDefinition); }
             catch (AssemblyResolutionException e) { MessageBox.Show("Could not load assembly " + e.AssemblyReference.FullName); }
             break;
         case "TypeDefinition":
             ast = CreateAstBuilder((obj as TypeDefinition), true);
             try { ast.AddType(obj as TypeDefinition); }
             catch (AssemblyResolutionException e) { MessageBox.Show("Could not load assembly " + e.AssemblyReference.FullName); }
             break;
         case "MethodDefinition":
             MethodDefinition method = (obj as MethodDefinition);
             ast = CreateAstBuilder(method.DeclaringType, true);
             if (method.IsConstructor && !method.IsStatic && !method.DeclaringType.IsValueType)
             {
                 foreach (var field in method.DeclaringType.Fields)
                     if (field.IsStatic == method.IsStatic)
                     {
                         try { ast.AddField(field); }
                         catch (AssemblyResolutionException e) { MessageBox.Show("Could not load assembly " + e.AssemblyReference.Name); }
                     }
                 foreach (var ctor in method.DeclaringType.Methods)
                     if (ctor.IsConstructor && ctor.IsStatic == method.IsStatic)
                     {
                         try { ast.AddMethod(ctor); }
                         catch (AssemblyResolutionException e) { MessageBox.Show("Could not load assembly " + e.AssemblyReference.Name); }
                     }
             }
             else
             {
                 try { ast.AddMethod(obj as MethodDefinition); }
                 catch (AssemblyResolutionException e) { MessageBox.Show("Could not load assembly " + e.AssemblyReference.Name); }
             }
             break;
         case "PropertyDefinition":
             ast = CreateAstBuilder((obj as PropertyDefinition).DeclaringType, true);
             try { ast.AddProperty(obj as PropertyDefinition); }
             catch (AssemblyResolutionException e) { MessageBox.Show("Could not load assembly " + e.AssemblyReference.Name); }
             break;
         case "FieldDefinition":
             ast = CreateAstBuilder((obj as FieldDefinition).DeclaringType, true);
             try { ast.AddField(obj as FieldDefinition); }
             catch (AssemblyResolutionException e) { MessageBox.Show("Could not load assembly " + e.AssemblyReference.Name); }
             break;
         case "EventDefinition":
             ast = CreateAstBuilder((obj as EventDefinition).DeclaringType, true);
             try { ast.AddEvent(obj as EventDefinition); }
             catch (AssemblyResolutionException e) { MessageBox.Show("Could not load assembly " + e.AssemblyReference.Name); }
             break;
         default:
             return new ICSharpCode.AvalonEdit.Document.TextDocument();
     }
     try { ast.GenerateCode(aeto); }
     catch (AssemblyResolutionException e) { MessageBox.Show("Could not load assembly upon code generation:\r" + e.AssemblyReference.FullName); }
     return aeto.GetDocument();
 }
开发者ID:net-shell,项目名称:quantum-vaginer,代码行数:62,代码来源:NetDasm.cs


注:本文中的ICSharpCode.Decompiler.Ast.AstBuilder.AddField方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。