本文整理汇总了C#中IMetadataHost类的典型用法代码示例。如果您正苦于以下问题:C# IMetadataHost类的具体用法?C# IMetadataHost怎么用?C# IMetadataHost使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
IMetadataHost类属于命名空间,在下文中一共展示了IMetadataHost类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TypeInferencer
internal TypeInferencer(INamedTypeReference containingType, IMetadataHost host) {
Contract.Requires(containingType != null);
Contract.Requires(host != null);
this.containingType = containingType;
this.host = host;
this.platformType = containingType.PlatformType;
}
示例2: FieldAssignmentReplacementBuilder
public FieldAssignmentReplacementBuilder(FieldReference field, IMetadataHost host, ExpressionStatement assignment, ReplacementRegistry registry)
{
this.field = field;
this.host = host;
this.assignment = assignment;
this.registry = registry;
}
示例3: FindClosureMoveNext
/// <summary>
/// For an iterator method, find the closure class' MoveNext method and return its body.
/// </summary>
/// <param name="host"></param>
/// <param name="possibleIterator">The (potential) iterator method.</param>
/// <returns>Dummy.MethodBody if <paramref name="possibleIterator"/> does not fit into the code pattern of an iterator method,
/// or the body of the MoveNext method of the corresponding closure class if it does.
/// </returns>
public static IMethodBody/*?*/ FindClosureMoveNext(IMetadataHost host, ISourceMethodBody/*!*/ possibleIterator) {
if (possibleIterator is Dummy) return null;
var nameTable = host.NameTable;
var possibleIteratorBody = possibleIterator.Block;
foreach (var statement in possibleIteratorBody.Statements) {
var expressionStatement = statement as IExpressionStatement;
if (expressionStatement != null)
return FirstStatementIsIteratorCreation(host, possibleIterator, nameTable, statement);
break;
}
foreach (var statement in possibleIteratorBody.Statements){
//var lds = statement as ILocalDeclarationStatement;
//if (lds != null) {
// if (lds.InitialValue != null)
// return null;
// else
// continue;
//}
var returnStatement = statement as IReturnStatement;
if (returnStatement == null) return null;
var blockExpression = returnStatement.Expression as IBlockExpression;
if (blockExpression == null) return null;
foreach (var s in blockExpression.BlockStatement.Statements) {
return FirstStatementIsIteratorCreation(host, possibleIterator, nameTable, s);
}
}
return null;
}
示例4: AnonymousDelegateCachingRemover
internal AnonymousDelegateCachingRemover(IMetadataHost host, Hashtable<IAnonymousDelegate>/*?*/ delegatesCachedInFields,
Hashtable<LocalDefinition, AnonymousDelegate>/*?*/ delegatesCachedInLocals)
: base(host) {
Contract.Requires(host != null);
this.delegatesCachedInFields = delegatesCachedInFields;
this.delegatesCachedInLocals = delegatesCachedInLocals;
}
示例5: FirstStatementIsIteratorCreation
private static IMethodBody/*?*/ FirstStatementIsIteratorCreation(IMetadataHost host, ISourceMethodBody possibleIterator, INameTable nameTable, IStatement statement) {
ICreateObjectInstance createObjectInstance = GetICreateObjectInstance(statement);
if (createObjectInstance == null) {
// If the first statement in the method body is not the creation of iterator closure, return a dummy.
// Possible corner case not handled: a local is used to hold the constant value for the initial state of the closure.
return null;
}
ITypeReference closureType/*?*/ = createObjectInstance.MethodToCall.ContainingType;
ITypeReference unspecializedClosureType = ContractHelper.Unspecialized(closureType);
if (!AttributeHelper.Contains(unspecializedClosureType.Attributes, host.PlatformType.SystemRuntimeCompilerServicesCompilerGeneratedAttribute))
return null;
INestedTypeReference closureTypeAsNestedTypeReference = unspecializedClosureType as INestedTypeReference;
if (closureTypeAsNestedTypeReference == null) return null;
ITypeReference unspecializedClosureContainingType = ContractHelper.Unspecialized(closureTypeAsNestedTypeReference.ContainingType);
if (closureType != null && TypeHelper.TypesAreEquivalent(possibleIterator.MethodDefinition.ContainingTypeDefinition, unspecializedClosureContainingType)) {
IName MoveNextName = nameTable.GetNameFor("MoveNext");
foreach (ITypeDefinitionMember member in closureType.ResolvedType.GetMembersNamed(MoveNextName, false)) {
IMethodDefinition moveNext = member as IMethodDefinition;
if (moveNext != null) {
ISpecializedMethodDefinition moveNextGeneric = moveNext as ISpecializedMethodDefinition;
if (moveNextGeneric != null)
moveNext = moveNextGeneric.UnspecializedVersion.ResolvedMethod;
return moveNext.Body;
}
}
}
return null;
}
示例6: CalculateCyclomaticComplexity
private static int CalculateCyclomaticComplexity(this IMethodDefinition method, PdbReader pdb, IMetadataHost host)
{
var methodBody = method.Decompile(pdb, host);
var cyclomaticComplexityCalculator = new CyclomaticComplexityCalculator();
cyclomaticComplexityCalculator.Traverse(methodBody.Statements());
return cyclomaticComplexityCalculator.Result;
}
示例7: AnalyzeFileInHost
private static void AnalyzeFileInHost(string toAnalyse, IMetadataHost host)
{
AnalyzeFileWithPdb(toAnalyse, host, (pdb) =>
{
AnalyzeAssembly(host.LoadUnitFrom(toAnalyse) as IAssembly, pdb);
});
}
示例8: AnalyzeAssemblyInHost
private void AnalyzeAssemblyInHost(IMetadataHost host, IAssembly assembly, string pdbPath)
{
if (pdbPath != null)
AnalyzeAssemblyInHostWithProgramDatabase(assembly, host, pdbPath);
else
AnalyzeTypes(assembly, null, host, Report);
}
示例9: SpecifiedMethodCallRegistrar
public SpecifiedMethodCallRegistrar(IMetadataHost host, ILogger log, ReplacementRegistry registry)
{
this.host = host;
this.log = log;
this.registry = registry;
reflector = new UnitReflector(host);
}
示例10: TypeAndMethods
private TypeMetricsWithMethodMetrics TypeAndMethods(PdbReader pdb, IMetadataHost host, INamedTypeDefinition type)
{
var typeAndMethods = new TypeMetricsWithMethodMetrics();
typeAndMethods.AddMethodReports(AnalyzeMethods(type, pdb, host));
typeAndMethods.Type = AnalyzeType(type, pdb, typeAndMethods.Methods);
return typeAndMethods;
}
示例11: Decompile
public static SourceMethodBody Decompile(this IMethodDefinition method, PdbReader pdb, IMetadataHost host)
{
return new SourceMethodBody(method.Body, host, pdb, pdb,
DecompilerOptions.Loops |
DecompilerOptions.AnonymousDelegates |
DecompilerOptions.Iterators);
}
示例12: Reachable
internal static void Reachable(
IMetadataHost host,
ISlice<MethodReferenceAdaptor, FieldReferenceAdaptor, TypeReferenceAdaptor, IAssemblyReference> slice,
HashSet<object> thingsToKeep,
HashSet<uint> methodsWhoseBodiesShouldBeKept,
out Dictionary<IMethodDefinition, uint> contractOffsets
) {
Contract.Requires(host != null);
Contract.Requires(slice != null);
Contract.Requires(thingsToKeep != null);
Contract.Requires(methodsWhoseBodiesShouldBeKept != null);
var traverser = new MetadataTraverser();
var me = new FindReachable(host, traverser, slice, thingsToKeep, methodsWhoseBodiesShouldBeKept);
traverser.TraverseIntoMethodBodies = true;
traverser.PreorderVisitor = me;
var methodsToTraverse = slice.Methods;
foreach (var m in methodsToTraverse) {
var methodDefinition = m.reference.ResolvedMethod;
traverser.Traverse(methodDefinition);
}
foreach (var c in slice.Chains) {
VisitChain(c, traverser);
}
contractOffsets = me.contractOffsets;
return;
}
示例13: RewriteModule
public static IModule RewriteModule(IMetadataHost host, ILocalScopeProvider localScopeProvider, ISourceLocationProvider sourceLocationProvider, IModule module)
{
var m = new PropertyChangedWeaver(host);
m._rewriter = new ReferenceReplacementRewriter(host, localScopeProvider, sourceLocationProvider);
return m.Rewrite(module);
}
示例14: Of
public static int Of(IMethodDefinition method, PdbReader pdb, IMetadataHost host)
{
if (method.HasOperations())
return method.CalculateStatements(pdb, host);
else
return 0;
}
示例15: SharpMockTypes
public SharpMockTypes(IMetadataHost host)
{
var funcs = new Dictionary<int, INamedTypeReference>();
var acts = new Dictionary<int, INamedTypeReference>();
var sharpMockTypes =
host.LoadUnitFrom(
System.Reflection.Assembly.GetExecutingAssembly().Location);
var sharpMockDelegateTypes = sharpMockTypes as IAssembly;
Unit = sharpMockTypes;
foreach (var type in sharpMockDelegateTypes.GetAllTypes())
{
if (type.Name.Value == "VoidAction")
{
acts.Add(type.GenericParameterCount, type);
}
if (type.Name.Value == "Function")
{
funcs.Add(type.GenericParameterCount - 1, type);
}
}
functions = new GenericMethodTypeDictionary(funcs, "Unable to find type Function<> with {0} input parameter arguments.");
actions = new GenericMethodTypeDictionary(acts, "Unable to find type VoidAction<> with {0} parameter arguments.");
}