本文整理汇总了C#中Mono.Cecil.ModuleDefinition.GetTypes方法的典型用法代码示例。如果您正苦于以下问题:C# ModuleDefinition.GetTypes方法的具体用法?C# ModuleDefinition.GetTypes怎么用?C# ModuleDefinition.GetTypes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Mono.Cecil.ModuleDefinition
的用法示例。
在下文中一共展示了ModuleDefinition.GetTypes方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Read
public static ModuleReader Read(ModuleDefinition module)
{
var reader = new ModuleReader();
if (module.AssemblyReferences.All(reference => reference.Name != "Stiletto"))
{
return reader;
}
var allTypes = module.GetTypes();
foreach (var t in allTypes)
{
if (IsModule(t))
{
reader.ModuleTypes.Add(t);
}
if (IsInject(t))
{
reader.InjectTypes.Add(t);
}
}
return reader;
}
示例2: findAll
public static List<MethodDefinition> findAll(ModuleDefinition module)
{
var list = new List<MethodDefinition>();
foreach (var type in module.GetTypes()) {
foreach (var method in type.Methods) {
if (isInvalidMethod(method))
list.Add(method);
}
}
return list;
}
示例3: find
public static List<MethodDefinition> find(ModuleDefinition module)
{
var inlinedMethods = new List<MethodDefinition>();
foreach (var type in module.GetTypes()) {
foreach (var method in type.Methods) {
if (MethodCallInliner.canInline(method))
inlinedMethods.Add(method);
}
}
return inlinedMethods;
}
示例4: find
public static List<MethodDefinition> find(ModuleDefinition module, IEnumerable<MethodDefinition> notInlinedMethods)
{
var notInlinedMethodsDict = new Dictionary<MethodDefinition, bool>();
foreach (var method in notInlinedMethods)
notInlinedMethodsDict[method] = true;
var inlinedMethods = new List<MethodDefinition>();
foreach (var type in module.GetTypes()) {
foreach (var method in type.Methods) {
if (!notInlinedMethodsDict.ContainsKey(method) && canInline(method))
inlinedMethods.Add(method);
}
}
return inlinedMethods;
}
示例5: Select
public IEnumerable<TypeDefinition> Select(ModuleDefinition moduleDefinition)
{
var typesToProcess = new List<TypeDefinition>();
foreach (TypeDefinition type in moduleDefinition.GetTypes())
{
if (CanVirtualize(type))
{
if ((!IsContainer(type) && !ImplementsInterfaces(type))
|| HasDoVirtualizeAttribute(type))
{
typesToProcess.Add(type);
}
}
}
return typesToProcess;
}
示例6: MapCallsToVirtual
public void MapCallsToVirtual(IEnumerable<MethodDefinition> members, ModuleDefinition moduleDefinition)
{
foreach (TypeDefinition typeDefinition in moduleDefinition.GetTypes())
{
if (typeDefinition.IsAbstract || typeDefinition.IsEnum)
{
continue;
}
foreach (MethodDefinition methodDefinition in typeDefinition.Methods)
{
if (methodDefinition.HasBody)
{
ReplaceCallsTo(methodDefinition, members);
}
}
}
}
示例7: Parse
private IEnumerable<LocalizedString> Parse (ModuleDefinition module)
{
return
from type in module.GetTypes()
where !LOCALIZATION_TYPES.Contains (type.FullName)
from method in type.Methods
where method.HasBody && method.Body.Instructions.Count > 0
from invocation in ParseLocalizedStringInvocations (method.Body.Instructions [0])
from localized_string in ParseLocalizedStringInvocation (invocation)
select localized_string;
}
示例8: Weave
/// <summary>
/// Weaves the specified module definition.
/// </summary>
/// <param name="moduleDefinition">The module definition.</param>
public void Weave(ModuleDefinition moduleDefinition)
{
var auditTimer = new AuditTimer();
var stopwatch = new Stopwatch();
stopwatch.Start();
// sanity check
auditTimer.NewZone("IAdvice location");
var adviceInterface = TypeResolver.Resolve(moduleDefinition, Binding.AdviceInterfaceName, true);
if (adviceInterface == null)
{
Logger.WriteWarning("IAdvice interface not found here, exiting");
return;
}
// runtime check
auditTimer.NewZone("Runtime check");
var targetFramework = GetTargetFramework(moduleDefinition);
InjectAsPrivate = targetFramework.Silverlight == null && targetFramework.WindowsPhone == null;
//Logger.WriteDebug("t1: {0}ms", (int)stopwatch.ElapsedMilliseconds);
// weave methods (they can be property-related, too)
auditTimer.NewZone("Weavable methods detection");
var weavableMethods = GetMarkedMethods(moduleDefinition, adviceInterface).ToArray();
auditTimer.NewZone("Methods weaving");
weavableMethods.AsParallel().ForAll(m => WeaveMethod(moduleDefinition, m, adviceInterface));
auditTimer.NewZone("Weavable interfaces detection");
var weavableInterfaces = GetAdviceHandledInterfaces(moduleDefinition).ToArray();
auditTimer.NewZone("Interface methods weaving");
weavableInterfaces.AsParallel().ForAll(i => WeaveInterface(moduleDefinition, i));
//Logger.WriteDebug("t2: {0}ms", (int)stopwatch.ElapsedMilliseconds);
// and then, the info advices
auditTimer.NewZone("Info advices weaving");
var infoAdviceInterface = TypeResolver.Resolve(moduleDefinition, Binding.InfoAdviceInterfaceName, true);
moduleDefinition.GetTypes().AsParallel().ForAll(t => WeaveInfoAdvices(moduleDefinition, t, infoAdviceInterface));
auditTimer.LastZone();
//Logger.WriteDebug("t3: {0}ms", (int)stopwatch.ElapsedMilliseconds);
var report = auditTimer.GetReport();
var maxLength = report.Keys.Max(k => k.Length);
Logger.WriteDebug("--- Timings --------------------------");
foreach (var reportPart in report)
Logger.WriteDebug("{0} : {1}ms", reportPart.Key.PadRight(maxLength), (int)reportPart.Value.TotalMilliseconds);
Logger.WriteDebug("--------------------------------------");
Logger.Write("MrAdvice {3} weaved module '{0}' (targeting framework {2}) in {1}ms",
moduleDefinition.Assembly.FullName, (int)stopwatch.ElapsedMilliseconds, targetFramework, Product.Version);
}
示例9: GetAdviceHandledInterfaces
/// <summary>
/// Gets the advice handled interfaces.
/// This is done by analyzing calls in all methods from module
/// </summary>
/// <param name="moduleDefinition">The module definition.</param>
/// <param name="invokedMethod">The invoked method.</param>
/// <param name="genericParameterIndex">Index of the generic parameter.</param>
/// <returns></returns>
private static IEnumerable<Tuple<TypeReference, MethodDefinition>> GetAdviceHandledInterfaces(ModuleDefinition moduleDefinition,
MethodReference invokedMethod, int genericParameterIndex)
{
return moduleDefinition.GetTypes().SelectMany(t => t.GetMethods().Where(m => m.HasBody)
.AsParallel().SelectMany(definition => GetAdviceHandledInterfaces(definition, invokedMethod, genericParameterIndex)));
}
示例10: find
public static List<MethodDefinition> find(ModuleDefinition module)
{
// Not all garbage methods are inlined, possibly because we remove some code that calls
// the garbage method before the methods inliner has a chance to inline it. Try to find
// all garbage methods and other code will figure out if there are any calls left.
var inlinedMethods = new List<MethodDefinition>();
foreach (var type in module.GetTypes()) {
foreach (var method in type.Methods) {
if (!method.IsStatic)
continue;
if (!method.IsAssembly && !method.IsCompilerControlled && !method.IsPrivate)
continue;
if (method.GenericParameters.Count > 0)
continue;
if (method.Name == ".cctor")
continue;
if (method.Body == null)
continue;
var instrs = method.Body.Instructions;
if (instrs.Count < 2)
continue;
switch (instrs[0].OpCode.Code) {
case Code.Ldc_I4:
case Code.Ldc_I4_0:
case Code.Ldc_I4_1:
case Code.Ldc_I4_2:
case Code.Ldc_I4_3:
case Code.Ldc_I4_4:
case Code.Ldc_I4_5:
case Code.Ldc_I4_6:
case Code.Ldc_I4_7:
case Code.Ldc_I4_8:
case Code.Ldc_I4_M1:
case Code.Ldc_I4_S:
case Code.Ldc_I8:
case Code.Ldc_R4:
case Code.Ldc_R8:
case Code.Ldftn:
case Code.Ldnull:
case Code.Ldstr:
case Code.Ldtoken:
case Code.Ldsfld:
case Code.Ldsflda:
if (instrs[1].OpCode.Code != Code.Ret)
continue;
break;
case Code.Ldarg:
case Code.Ldarg_S:
case Code.Ldarg_0:
case Code.Ldarg_1:
case Code.Ldarg_2:
case Code.Ldarg_3:
case Code.Ldarga:
case Code.Ldarga_S:
case Code.Call:
case Code.Newobj:
if (!isCallMethod(method))
continue;
break;
default:
continue;
}
inlinedMethods.Add(method);
}
}
return inlinedMethods;
}
示例11: getType
public static TypeDefinition getType(ModuleDefinition module, TypeReference typeReference)
{
if (typeReference == null)
return null;
if (typeReference is TypeDefinition)
return (TypeDefinition)typeReference;
foreach (var type in module.GetTypes()) {
if (MemberReferenceHelper.compareTypes(type, typeReference))
return type;
}
return null;
}
示例12: GetOrderedTypes
private static List<TypeDefinition> GetOrderedTypes(
ModuleDefinition mainModule,
List<String> explicitTypesOrder)
{
var unorderedTypes = mainModule.GetTypes()
.Where(item => item.FullName != "<Module>")
.ToList();
if (explicitTypesOrder == null || explicitTypesOrder.Count == 0)
{
return SortTypesAccordingUsages(
unorderedTypes, mainModule.FullyQualifiedName);
}
return explicitTypesOrder
.Join(unorderedTypes, outer => outer, inner => inner.FullName, (inner, outer) => outer)
.ToList();
}
示例13: WeaveInterface
/// <summary>
/// Weaves the interface.
/// What we do here is:
/// - creating a class (wich is named after the interface name)
/// - this class implements all interface members
/// - all members invoke Invocation.ProcessInterfaceMethod
/// </summary>
/// <param name="moduleDefinition">The module definition.</param>
/// <param name="interfaceType">Type of the interface.</param>
private void WeaveInterface(ModuleDefinition moduleDefinition, TypeReference interfaceType)
{
Logger.WriteDebug("Weaving interface '{0}'", interfaceType.FullName);
TypeDefinition implementationType;
TypeDefinition advisedInterfaceType;
TypeDefinition interfaceTypeDefinition;
lock (moduleDefinition)
{
// ensure we're creating the interface only once
var implementationTypeName = GetImplementationTypeName(interfaceType.Name);
var implementationTypeNamespace = interfaceType.Namespace;
if (moduleDefinition.GetTypes().Any(t => t.Namespace == implementationTypeNamespace && t.Name == implementationTypeName))
return;
// now, create the implementation type
interfaceTypeDefinition = interfaceType.Resolve();
var typeAttributes = (InjectAsPrivate ? TypeAttributes.NotPublic : TypeAttributes.Public) | TypeAttributes.Class | TypeAttributes.BeforeFieldInit;
advisedInterfaceType = TypeResolver.Resolve(moduleDefinition, Binding.AdvisedInterfaceTypeName, true);
var advisedInterfaceTypeReference = moduleDefinition.SafeImport(advisedInterfaceType);
implementationType = new TypeDefinition(implementationTypeNamespace, implementationTypeName, typeAttributes, advisedInterfaceTypeReference);
lock (moduleDefinition)
moduleDefinition.Types.Add(implementationType);
}
implementationType.Interfaces.Add(interfaceType);
// create empty .ctor. This .NET mofo wants it!
var baseEmptyConstructor = moduleDefinition.SafeImport(advisedInterfaceType.Resolve().GetConstructors().Single());
const MethodAttributes ctorAttributes = MethodAttributes.Public | MethodAttributes.HideBySig | MethodAttributes.SpecialName | MethodAttributes.RTSpecialName;
var method = new MethodDefinition(".ctor", ctorAttributes, moduleDefinition.TypeSystem.Void);
method.Body.Instructions.Add(Instruction.Create(OpCodes.Ldarg_0));
method.Body.Instructions.Add(Instruction.Create(OpCodes.Call, baseEmptyConstructor));
method.Body.Instructions.Add(Instruction.Create(OpCodes.Ret));
implementationType.Methods.Add(method);
// create implementation methods
foreach (var interfaceMethod in interfaceTypeDefinition.GetMethods().Where(m => !m.IsSpecialName))
WeaveInterfaceMethod(interfaceMethod, implementationType, true);
// create implementation properties
foreach (var interfaceProperty in interfaceTypeDefinition.Properties)
{
var implementationProperty = new PropertyDefinition(interfaceProperty.Name, PropertyAttributes.None, interfaceProperty.PropertyType);
implementationType.Properties.Add(implementationProperty);
if (interfaceProperty.GetMethod != null)
implementationProperty.GetMethod = WeaveInterfaceMethod(interfaceProperty.GetMethod, implementationType, InjectAsPrivate);
if (interfaceProperty.SetMethod != null)
implementationProperty.SetMethod = WeaveInterfaceMethod(interfaceProperty.SetMethod, implementationType, InjectAsPrivate);
}
// create implementation events
foreach (var interfaceEvent in interfaceTypeDefinition.Events)
{
var implementationEvent = new EventDefinition(interfaceEvent.Name, EventAttributes.None, moduleDefinition.SafeImport(interfaceEvent.EventType));
implementationType.Events.Add(implementationEvent);
if (interfaceEvent.AddMethod != null)
implementationEvent.AddMethod = WeaveInterfaceMethod(interfaceEvent.AddMethod, implementationType, InjectAsPrivate);
if (interfaceEvent.RemoveMethod != null)
implementationEvent.RemoveMethod = WeaveInterfaceMethod(interfaceEvent.RemoveMethod, implementationType, InjectAsPrivate);
}
}