本文整理汇总了C#中ICSharpCode.Decompiler.Ast.AstBuilder.AddProperty方法的典型用法代码示例。如果您正苦于以下问题:C# AstBuilder.AddProperty方法的具体用法?C# AstBuilder.AddProperty怎么用?C# AstBuilder.AddProperty使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ICSharpCode.Decompiler.Ast.AstBuilder
的用法示例。
在下文中一共展示了AstBuilder.AddProperty方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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;
}
示例2: 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);
}
示例3: 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();
}