本文整理汇总了C#中IMethodBody类的典型用法代码示例。如果您正苦于以下问题:C# IMethodBody类的具体用法?C# IMethodBody怎么用?C# IMethodBody使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
IMethodBody类属于命名空间,在下文中一共展示了IMethodBody类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: DebugReplacementGeneratorForBody
public override ILGenerator DebugReplacementGeneratorForBody(IMethodBody methodBody) {
string warningText = "Attempt to execute garbage collected method: " + methodBody.MethodDefinition.ToString();
var generator = new ILGenerator(host, methodBody.MethodDefinition);
// emit console warning
generator.Emit(OperationCode.Ldstr, warningText);
generator.Emit(OperationCode.Call, this.consoleWriteLine);
//emit stack trace
// pushes stack trace on stack
generator.Emit(OperationCode.Call, this.environmentGetStackTrace);
// consumes stack trace
generator.Emit(OperationCode.Call, this.consoleWriteLine);
// may want to flush output?
// emit exit
generator.Emit(OperationCode.Ldc_I4_M1);
generator.Emit(OperationCode.Call, this.environmentExit);
// Makes the verifier happy; this should never be reached
AppendEmitExceptionThrow(generator);
return generator;
}
开发者ID:modulexcite,项目名称:Microsoft.Cci.Metadata,代码行数:29,代码来源:Sweep.cs
示例2: Traverse
public override void Traverse(IMethodBody methodBody) {
sourceEmitterOutput.WriteLine("");
this.sourceEmitterOutput.WriteLine(MemberHelper.GetMethodSignature(methodBody.MethodDefinition,
NameFormattingOptions.Signature|NameFormattingOptions.ReturnType|NameFormattingOptions.ParameterModifiers|NameFormattingOptions.ParameterName));
sourceEmitterOutput.WriteLine("");
if (this.pdbReader != null)
PrintScopes(methodBody);
else
PrintLocals(methodBody.LocalVariables);
this.cdfg = ControlAndDataFlowGraph<AiBasicBlock<Instruction>, Instruction>.GetControlAndDataFlowGraphFor(host, methodBody, this.pdbReader);
this.cfgQueries = new ControlGraphQueries<AiBasicBlock<Instruction>, Instruction>(this.cdfg);
SingleAssigner<AiBasicBlock<Instruction>, Instruction>.GetInSingleAssignmentForm(host.NameTable, this.cdfg, this.cfgQueries, this.pdbReader);
this.valueMappings = new ValueMappings<Instruction>(this.host.PlatformType, new Z3Wrapper.Wrapper(host.PlatformType));
AbstractInterpreter<AiBasicBlock<Instruction>, Instruction>.InterpretUsingAbstractValues(this.cdfg, this.cfgQueries, this.valueMappings);
var numberOfBlocks = this.cdfg.BlockFor.Count;
foreach (var block in this.cdfg.AllBlocks) {
this.PrintBlock(block);
}
sourceEmitterOutput.WriteLine("**************************************************************");
sourceEmitterOutput.WriteLine();
}
开发者ID:RUB-SysSec,项目名称:Probfuscator,代码行数:25,代码来源:SourceEmitter.cs
示例3: MinimalReplacementGeneratorForBody
public virtual ILGenerator MinimalReplacementGeneratorForBody(IMethodBody methodBody) {
var generator = new ILGenerator(host, methodBody.MethodDefinition);
AppendEmitExceptionThrow(generator);
return generator;
}
开发者ID:modulexcite,项目名称:Microsoft.Cci.Metadata,代码行数:7,代码来源:Sweep.cs
示例4: SynthesizedMethodBodyDecorator
public SynthesizedMethodBodyDecorator(IMethodBody methodBody, IList<IType> locals, byte[] customBody)
: this(methodBody)
{
this.customBody = customBody;
var index = 0;
this.locals = locals.Select(t => new SynthesizedLocalVariable(index++, t)).ToList();
}
开发者ID:SperoSophia,项目名称:il2bc,代码行数:7,代码来源:SynthesizedMethodBodyDecorator.cs
示例5: VerifyResult
protected void VerifyResult(IMethodBody mb)
{
var s_actual = mb.StringJoin(Environment.NewLine);
s_actual = Regex.Replace(s_actual, @"Snippets.<>c__DisplayClass.*::", "<Closure>::");
s_actual = Regex.Replace(s_actual, @"CS\$<>8__locals.*\)", "<Closure>)");
s_actual = Regex.Replace(s_actual, @"0x[a-fA-f0-9]{8}", "<MetadataToken>");
VerifyResult(s_actual);
}
开发者ID:xeno-by,项目名称:truesight-lite,代码行数:8,代码来源:Tests.Boilerplate.cs
示例6: Rewrite
/// <summary>
/// Rewrites the target method body. This class will only insert a single call into the beginning of the
/// method that writes it's signature using the <see cref="TestUtil"/> class.
/// </summary>
/// <param name="methodBody">
/// The method body to rewrite.
/// </param>
/// <returns>
/// The rewritten method body.
/// </returns>
public override IMethodBody Rewrite(IMethodBody methodBody)
{
if (this.rewriter == null)
{
throw new InvalidOperationException("Unable to rewrite method body. Call Rewrite(IInstrumentationTarget target) instead of calling this directly.");
}
return this.rewriter.Rewrite(methodBody);
}
开发者ID:jduv,项目名称:WinBert,代码行数:19,代码来源:DynamicCallGraphInstrumentor.cs
示例7: SerializeMethodDebugInfo
public byte[] SerializeMethodDebugInfo(EmitContext context, IMethodBody methodBody, uint methodToken, bool isEncDelta, bool suppressNewCustomDebugInfo, out bool emitExternNamespaces)
{
emitExternNamespaces = false;
// CONSIDER: this may not be the same "first" method as in Dev10, but
// it shouldn't matter since all methods will still forward to a method
// containing the appropriate information.
if (_methodBodyWithModuleInfo == null) //UNDONE: || edit-and-continue
{
// This module level information could go on every method (and does in
// the edit-and-continue case), but - as an optimization - we'll just
// put it on the first method we happen to encounter and then put a
// reference to the first method's token in every other method (so they
// can find the information).
if (context.Module.GetAssemblyReferenceAliases(context).Any())
{
_methodTokenWithModuleInfo = methodToken;
_methodBodyWithModuleInfo = methodBody;
emitExternNamespaces = true;
}
}
var customDebugInfo = ArrayBuilder<MemoryStream>.GetInstance();
SerializeIteratorClassMetadata(methodBody, customDebugInfo);
// NOTE: This is an attempt to match Dev10's apparent behavior. For iterator methods (i.e. the method
// that appears in source, not the synthesized ones), Dev10 only emits the ForwardIterator and IteratorLocal
// custom debug info (e.g. there will be no information about the usings that were in scope).
// NOTE: There seems to be an unusual behavior in ISymUnmanagedWriter where, if all the methods in a type are
// iterator methods, no custom debug info is emitted for any method. Adding a single non-iterator
// method causes the custom debug info to be produced for all methods (including the iterator methods).
// Since we are making the same ISymUnmanagedWriter calls as Dev10, we see the same behavior (i.e. this
// is not a regression).
if (methodBody.StateMachineTypeName == null)
{
SerializeNamespaceScopeMetadata(context, methodBody, customDebugInfo);
SerializeStateMachineLocalScopes(methodBody, customDebugInfo);
}
if (!suppressNewCustomDebugInfo)
{
SerializeDynamicLocalInfo(methodBody, customDebugInfo);
// delta doesn't need this information - we use information recorded by previous generation emit
if (!isEncDelta)
{
var encMethodInfo = MetadataWriter.GetEncMethodDebugInfo(methodBody);
SerializeCustomDebugInformation(encMethodInfo, customDebugInfo);
}
}
byte[] result = SerializeCustomDebugMetadata(customDebugInfo);
customDebugInfo.Free();
return result;
}
开发者ID:elemk0vv,项目名称:roslyn-1,代码行数:56,代码来源:CustomDebugInfoWriter.cs
示例8: SynthesizedMethodDecorator
public SynthesizedMethodDecorator(
IMethod method,
IMethodBody methodBody,
IEnumerable<IParameter> parameters,
IModule module) : this(method)
{
this.methodBody = methodBody;
this.module = module;
this.parameters = parameters;
}
开发者ID:afrog33k,项目名称:csnative,代码行数:10,代码来源:SynthesizedMethodDecorator.cs
示例9: Rewrite
public override IMethodBody Rewrite(IMethodBody methodBody) {
this.cdfg = ControlAndDataFlowGraph<BasicBlock<Instruction>, Instruction>.GetControlAndDataFlowGraphFor(this.host, methodBody);
this.ilGenerator = new ILGenerator(host, methodBody.MethodDefinition);
var numberOfBlocks = this.cdfg.BlockFor.Count;
this.labelFor = new Hashtable<ILGeneratorLabel>(numberOfBlocks);
this.counterFieldsForCurrentMethod = new NestedTypeDefinition() {
BaseClasses = new List<ITypeReference>(1) { this.host.PlatformType.SystemObject },
ContainingTypeDefinition = methodBody.MethodDefinition.ContainingTypeDefinition,
Fields = new List<IFieldDefinition>((int)numberOfBlocks*2),
Methods = new List<IMethodDefinition>(1),
InternFactory = this.host.InternFactory,
IsBeforeFieldInit = true,
IsClass = true,
IsSealed = true,
IsAbstract = true,
Name = this.host.NameTable.GetNameFor(methodBody.MethodDefinition.Name+"_Counters"+methodBody.MethodDefinition.InternedKey),
Visibility = TypeMemberVisibility.Assembly,
};
this.fieldOffsets = new List<uint>((int)numberOfBlocks*2);
foreach (var exceptionInfo in methodBody.OperationExceptionInformation) {
this.ilGenerator.AddExceptionHandlerInformation(exceptionInfo.HandlerKind, exceptionInfo.ExceptionType,
this.GetLabelFor(exceptionInfo.TryStartOffset), this.GetLabelFor(exceptionInfo.TryEndOffset),
this.GetLabelFor(exceptionInfo.HandlerStartOffset), this.GetLabelFor(exceptionInfo.HandlerEndOffset),
exceptionInfo.HandlerKind == HandlerKind.Filter ? this.GetLabelFor(exceptionInfo.FilterDecisionStartOffset) : null);
}
if (this.pdbReader == null) {
foreach (var localDef in methodBody.LocalVariables)
this.ilGenerator.AddVariableToCurrentScope(localDef);
} else {
foreach (var ns in this.pdbReader.GetNamespaceScopes(methodBody)) {
foreach (var uns in ns.UsedNamespaces)
this.ilGenerator.UseNamespace(uns.NamespaceName.Value);
}
this.scopeEnumerator = this.pdbReader.GetLocalScopes(methodBody).GetEnumerator();
this.scopeEnumeratorIsValid = this.scopeEnumerator.MoveNext();
}
foreach (var block in this.cdfg.AllBlocks)
this.InstrumentBlock(block);
while (this.scopeStack.Count > 0) {
this.ilGenerator.EndScope();
this.scopeStack.Pop();
}
this.ilGenerator.AdjustBranchSizesToBestFit();
this.InjectMethodToDumpCounters();
return new ILGeneratorMethodBody(this.ilGenerator, methodBody.LocalsAreZeroed, (ushort)(methodBody.MaxStack+2), methodBody.MethodDefinition,
methodBody.LocalVariables, IteratorHelper.GetSingletonEnumerable((ITypeDefinition)this.counterFieldsForCurrentMethod));
}
开发者ID:modulexcite,项目名称:Microsoft.Cci.Metadata,代码行数:55,代码来源:AddInstrumentation.cs
示例10: DoBuildControlFlowGraph
public static ControlFlowGraph DoBuildControlFlowGraph(IMethodBody cil, Symbols symbols)
{
ReadOnlyDictionary<ControlFlowBlock, ReadOnlyCollection<IILOp>> blocks2parts;
var cfg = CreateCarcass.DoCreateCarcass(cil, out blocks2parts);
foreach (var cfb in blocks2parts.Keys)
{
InitialDecompilation.DoPrimaryDecompilation(cfb, blocks2parts[cfb], symbols);
}
return cfg;
}
开发者ID:xeno-by,项目名称:truesight-lite,代码行数:11,代码来源:BuildControlFlowGraph.cs
示例11: SerializeMethodDynamicAnalysisData
internal void SerializeMethodDynamicAnalysisData(IMethodBody bodyOpt)
{
var data = bodyOpt?.DynamicAnalysisData;
if (data == null)
{
_methodTable.Add(default(MethodRow));
return;
}
BlobHandle spanBlob = SerializeSpans(data.Spans, _documentIndex);
_methodTable.Add(new MethodRow { Spans = spanBlob });
}
开发者ID:XieShuquan,项目名称:roslyn,代码行数:13,代码来源:MetadataWriter.DynamicAnalysis.cs
示例12: Rewrite
public override IMethodBody Rewrite(IMethodBody body)
{
var method = body.MethodDefinition;
_log.Info("Rewriting IMethodBody of: " + method + " Pass: " + MutationTarget.PassInfo);
var newBody = new SourceMethodBody(Host)
{
MethodDefinition = method,
LocalsAreZeroed = true
};
var block = new BlockStatement();
newBody.Block = block;
var replacement = method.ContainingTypeDefinition.Methods.Single(m => m.ToString() == MutationTarget.PassInfo);
var methodCall = new MethodCall
{
MethodToCall = replacement,
Type = replacement.Type,
ThisArgument = new ThisReference() {Type = method.ContainingTypeDefinition}
};
foreach (var param in replacement.Parameters)
{
methodCall.Arguments.Add(new BoundExpression()
{
Definition = method.Parameters
.First(p =>
((INamedTypeReference)p.Type).Name.Value ==
((INamedTypeReference)param.Type).Name.Value)
});
// methodCall.Arguments.Add(method.Parameters.First(p => new ));
}
if (replacement.Type == Host.PlatformType.SystemVoid)
{
block.Statements.Add(new ExpressionStatement
{
Expression = methodCall
});
block.Statements.Add(new ReturnStatement());
}
else
{
block.Statements.Add(new ReturnStatement
{
Expression = methodCall
});
}
return newBody;
}
开发者ID:Refresh06,项目名称:visualmutator,代码行数:51,代码来源:OMR_OverloadingMethodContentsChange.cs
示例13: Visit
public override void Visit(IMethodBody body)
{
var method = body.MethodDefinition;
_log.Info("Visiting IMethodBody of: " + method);
var methods = FindCandidateMethods(method);
var compatibileMethods = methods.Where(m => m.Parameters
.All(p => method.Parameters.Any(p2 => p2.Type == p.Type))).ToList();
if(compatibileMethods.Count != 0)
{
MarkMutationTarget(body, compatibileMethods.First().ToString().InList());
}
}
开发者ID:Refresh06,项目名称:visualmutator,代码行数:16,代码来源:OMR_OverloadingMethodContentsChange.cs
示例14: Traverse
public override void Traverse(IMethodBody methodBody)
{
var moduleInfo = _module.ModulesInfo.Single();
var smb = new Microsoft.Cci.ILToCodeModel.SourceMethodBody(methodBody, _module.Host, moduleInfo.PdbReader, moduleInfo.LocalScopeProvider, DecompilerOptions.None);
_visitor.MethodBodyEnter(smb);
Traverse(smb);
var descriptor = _visitor.MethodBodyExit(smb);
var targetsDescriptors = _visitor.MutationTargets.Select(t => t.ProcessingContext.Descriptor).ToList();
// _log.Debug("Returned :"+ descriptor+" comparing with mutaion targets: "+ targetsDescriptors.MakeString());
if(targetsDescriptors.Any(a => a.IsContainedIn(descriptor)))
{
_log.Debug("Adding method body :" + descriptor );
_methodBodies.Add(methodBody, smb);
}
}
开发者ID:Refresh06,项目名称:visualmutator,代码行数:17,代码来源:VisualCodeTraverser.cs
示例15: TryGetFirstFieldReference
/// <summary>
/// Tries to get the first field reference in the method body
/// </summary>
/// <param name="body"></param>
/// <param name="field"></param>
/// <returns></returns>
public static bool TryGetFirstFieldReference(IMethodBody body, out IFieldReference field)
{
Contract.Requires(body != null);
Contract.Ensures(!Contract.Result<bool>() || Contract.ValueAtReturn(out field) != null);
foreach (var operation in body.Operations)
{
if (operation.OperationCode == OperationCode.Stfld ||
operation.OperationCode == OperationCode.Ldfld)
{
field = (IFieldReference)operation.Value;
return field != null;
}
}
field = null;
return false;
}
开发者ID:mestriga,项目名称:Microsoft.CciSamples,代码行数:24,代码来源:CcsHelper.cs
示例16: Traverse
public override void Traverse(IMethodBody methodBody)
{
PrintToken(CSharpToken.LeftCurly);
ISourceMethodBody/*?*/ sourceMethodBody = methodBody as ISourceMethodBody;
if (sourceMethodBody == null)
{
var options = DecompilerOptions.Loops;
if (!printCompilerGeneratedMembers)
options |= (DecompilerOptions.AnonymousDelegates | DecompilerOptions.Iterators);
sourceMethodBody = new SourceMethodBody(methodBody, host, pdbReader, pdbReader, options);
}
if (noIL)
Traverse(sourceMethodBody.Block.Statements);
else
{
// this.Traverse(sourceMethodBody.Block);
// PrintToken(CSharpToken.NewLine);
if (pdbReader != null)
PrintScopes(methodBody);
else
PrintLocals(methodBody.LocalVariables);
int currentIndex = -1; // a number no index matches
foreach (IOperation operation in methodBody.Operations)
{
if (pdbReader != null)
{
foreach (IPrimarySourceLocation psloc in pdbReader.GetPrimarySourceLocationsFor(operation.Location))
{
if (psloc.StartIndex != currentIndex)
{
PrintSourceLocation(psloc);
currentIndex = psloc.StartIndex;
}
}
}
PrintOperation(operation);
}
}
PrintToken(CSharpToken.RightCurly);
}
开发者ID:Refresh06,项目名称:visualmutator,代码行数:44,代码来源:VisualSourceEmitter.cs
示例17: TraverseChildren
public override void TraverseChildren(IMethodBody methodBody) {
if (this.pdbReader != null)
this.PrintScopes(methodBody);
else
this.PrintLocals(methodBody.LocalVariables);
int currentIndex = -1; // a number no index matches
foreach (IOperation operation in methodBody.Operations) {
if (this.pdbReader != null) {
foreach (IPrimarySourceLocation psloc in this.pdbReader.GetPrimarySourceLocationsFor(operation.Location)) {
if (psloc.StartIndex != currentIndex) {
this.PrintSourceLocation(psloc);
currentIndex = psloc.StartIndex;
}
}
}
this.PrintOperation(operation);
}
}
开发者ID:modulexcite,项目名称:Microsoft.Cci.Metadata,代码行数:19,代码来源:SourceEmitter.cs
示例18: Visit
// TODO: Add support for fields, properties, type definitions and attributes as well
//
// Example:
// [Serializable]
// public class Foo {}
//
// The 'Serializable' (Which is not supported on most platforms) is not found
public override void Visit(IMethodBody method)
{
var calls = method.Operations
.Where(opcode => opcode.OperationCode == OperationCode.Call
|| opcode.OperationCode == OperationCode.Callvirt
|| opcode.OperationCode == OperationCode.Newobj);
var foundInterestingCall = false;
foreach (var call in calls)
{
var calledMethod = (IMethodReference)call.Value;
var calledId = calledMethod.DocId();
MissingMemberInfo memberInfo = null;
if (!_interestingMethods.TryGetValue(calledId, out memberInfo))
{
// Try again with unwrapped member
var unwrappedId = calledMethod.UnWrapMember().DocId();
_interestingMethods.TryGetValue(unwrappedId, out memberInfo);
}
if (memberInfo != null)
{
foundInterestingCall = true;
var sourceItems = _pdbReader
.GetClosestPrimarySourceLocationsFor(call.Location)
.Select(l => GetSourceMappedItem(l, memberInfo));
_foundItems.AddRange(sourceItems);
}
}
// Check signature for interesting return type to catch polymorphic returns
// TODO: Does this condition need to be met? Should we check every return type?
if (!foundInterestingCall)
{
CheckReturnType(method);
}
base.Visit(method);
}
开发者ID:AlexGhiondea,项目名称:dotnet-apiport,代码行数:50,代码来源:CciMetadataTraverser.cs
示例19: ShouldForwardNamespaceScopes
/// <summary>
/// Returns true if the namespace scope for this method should be forwarded to another method.
/// Returns non-null <paramref name="forwardToMethod"/> if the forwarding should be done directly via UsingNamespace,
/// null if the forwarding is done via custom debug info.
/// </summary>
public bool ShouldForwardNamespaceScopes(EmitContext context, IMethodBody methodBody, uint methodToken, out IMethodDefinition forwardToMethod)
{
if (ShouldForwardToPreviousMethodWithUsingInfo(context, methodBody) || methodBody.ImportScope == null)
{
// SerializeNamespaceScopeMetadata will do the actual forwarding in case this is a CSharp method.
// VB on the other hand adds a "@methodtoken" to the scopes instead.
if (context.Module.GenerateVisualBasicStylePdb)
{
forwardToMethod = _previousMethodBodyWithUsingInfo.MethodDefinition;
}
else
{
forwardToMethod = null;
}
return true;
}
_previousMethodBodyWithUsingInfo = methodBody;
_previousMethodTokenWithUsingInfo = methodToken;
forwardToMethod = null;
return false;
}
开发者ID:elemk0vv,项目名称:roslyn-1,代码行数:28,代码来源:CustomDebugInfoWriter.cs
示例20: SourceMethodBody
/// <summary>
/// Allocates a metadata (IL) representation along with a source level representation of the body of a method or of a property/event accessor.
/// </summary>
/// <param name="ilMethodBody">A method body whose IL operations should be decompiled into a block of statements that will be the
/// result of the Block property of the resulting source method body.</param>
/// <param name="host">An object representing the application that is hosting the converter. It is used to obtain access to some global
/// objects and services such as the shared name table and the table for interning references.</param>
/// <param name="sourceLocationProvider">An object that can map some kinds of ILocation objects to IPrimarySourceLocation objects. May be null.</param>
/// <param name="localScopeProvider">An object that can provide information about the local scopes of a method.</param>
/// <param name="options">Set of options that control decompilation.</param>
public SourceMethodBody(IMethodBody ilMethodBody, IMetadataHost host, ISourceLocationProvider/*?*/ sourceLocationProvider,
ILocalScopeProvider/*?*/ localScopeProvider, DecompilerOptions options = DecompilerOptions.None)
: base(host, sourceLocationProvider, localScopeProvider) {
Contract.Requires(ilMethodBody != null);
Contract.Requires(host != null);
this.ilMethodBody = ilMethodBody;
this.host = host;
this.nameTable = host.NameTable;
this.sourceLocationProvider = sourceLocationProvider;
this.pdbReader = sourceLocationProvider as PdbReader;
this.localScopeProvider = localScopeProvider;
this.options = options;
this.platformType = ilMethodBody.MethodDefinition.ContainingTypeDefinition.PlatformType;
if (IteratorHelper.EnumerableIsNotEmpty(ilMethodBody.LocalVariables))
this.LocalsAreZeroed = ilMethodBody.LocalsAreZeroed;
else
this.LocalsAreZeroed = true;
this.MethodDefinition = ilMethodBody.MethodDefinition;
this.privateHelperFieldsToRemove = null;
this.privateHelperMethodsToRemove = null;
this.privateHelperTypesToRemove = null;
this.cdfg = ControlAndDataFlowGraph<BasicBlock<Instruction>, Instruction>.GetControlAndDataFlowGraphFor(host, ilMethodBody, localScopeProvider);
}
开发者ID:Refresh06,项目名称:visualmutator,代码行数:34,代码来源:SourceMethodBody.cs
注:本文中的IMethodBody类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论