本文整理汇总了C#中Mono.Cecil.AssemblyDefinition.IsPatchingAssembly方法的典型用法代码示例。如果您正苦于以下问题:C# AssemblyDefinition.IsPatchingAssembly方法的具体用法?C# AssemblyDefinition.IsPatchingAssembly怎么用?C# AssemblyDefinition.IsPatchingAssembly使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Mono.Cecil.AssemblyDefinition
的用法示例。
在下文中一共展示了AssemblyDefinition.IsPatchingAssembly方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: PatchAssembly
/// <summary>
/// Patches the current assembly with your patching assembly.
/// </summary>
/// <param name="yourAssembly">Your patching assembly.</param>
/// <exception cref="System.ArgumentException">The assembly MUST have the PatchAssemblyAttribute attribute. Sorry.</exception>
public void PatchAssembly(AssemblyDefinition yourAssembly)
{
try {
/* The point of this method is to introduce all the patched elements in the correct order,
* so the user doesn't have to worry about dependencies between code elements, and can have circular dependencies.
*
* The order is the following:
* 1. Declare all the new types, in the order of their nesting level (.e.g topmost types, nested types, types nested in those, etc),
* But don't set anything that references other things, like BaseType, interfaces, custom attributes, etc.
* Type parameters *are* added at this stage, but no constraints are specified.
* 2. Remove any methods that need removing.
* 3. Declare all the new methods, including signatures and type parameters + constraints, but without setting their bodies.
* This is performed now because types can reference attribute constructors that don't exist until we create them,
* but method definitions alone just reference types, and don't need to know about inheritance or constraints.
* Don't set custom attributes in this stage.
* 4. Add any custom attributes for things that aren't part of the method/type hierarchy, such as assemblies.
* 5. Set the type information we didn't set in (1), according to the same order, including custom attributes.
* When/if modifying type inheritance is allowed, this process will occur at this stage.
* 6. remove/define/modify fields. This is where most enum processing happens. Custom attributes are set at this stage.
* 7. Remove/define/modify properties. This doesn't change anything about methods. Custom attributes are set at this stage.
* 8. Fill/modify the bodies of all remaining methods, and also modify accessibility/attributes of existing ones.
* Note that methods that are the source of DuplicatesBody will be resolved in their unmodified version,
* so the modifications won't influence this functionality.
Custom attributes are set at this stage.
* Also, explicit overrides (what in C# is explicit interface implementation) are specified here.
Standard order of business for order between modify/remove/update:
1. Remove Xs
2. Create new Xs
3. Update existing Xs (+ those we just created)
*/
Log.Information(
"Patching assembly {PatchName:l} [{PatchPath:l}] => {OrigName:l} [{OrigPath:l}]",
yourAssembly.Name.Name,
PathHelper.GetUserFriendlyPath(yourAssembly.MainModule.FullyQualifiedName),
TargetAssembly.Name.Name,
PathHelper.GetUserFriendlyPath(TargetAssembly.MainModule.FullyQualifiedName)
);
if (!yourAssembly.IsPatchingAssembly()) {
throw new PatchDeclerationException(
"The assembly MUST have the PatchAssemblyAttribute attribute. Sorry.");
}
var allTypesInOrder = GetAllTypesInNestingOrder(yourAssembly.MainModule.Types).ToList();
//+ Organizing types by action attribute
var typesByActionSeq =
from type in allTypesInOrder
let typeActionAttr = GetTypeActionAttribute(type)
where typeActionAttr != null && Filter(type)
orderby type.UserFriendlyName()
group new {
yourType = type,
typeActionAttr
} by typeActionAttr.GetType();
var typesByAction = typesByActionSeq.ToSimpleTypeLookup();
Log.Information("Type Tasks: {@Tasks}",
new {
ByTask = new {
Replace = typesByAction[typeof (ReplaceTypeAttribute)].Count(),
Modify = typesByAction[typeof (ModifiesTypeAttribute)].Count(),
Create = typesByAction[typeof (NewTypeAttribute)].Count()
},
Total = typesByAction.Count
});
//++ 1. Creating new types
Log.Information("Creating new types");
foreach (var newTypeAction in typesByAction[typeof (NewTypeAttribute)]) {
var status = CreateNewType(newTypeAction.yourType,
(NewTypeAttribute) newTypeAction.typeActionAttr);
if (status == NewMemberStatus.InvalidItem) {
Log_failed_to_create();
typesByAction.Remove(newTypeAction);
}
}
//+ Pairing types, organizing for modification
//we pair off each yourType with the targetType it modifies (note that a targetType is also one we created just now)
//we'll use these pairings throughout the rest of the method.
var typePairingsSeq =
from typeGroup in typesByAction
from typeAction in typeGroup
group new {
typeAction.yourType,
typeAction.typeActionAttr,
targetType = GetPatchedTypeByName(typeAction.yourType)
} by typeAction.typeActionAttr.GetType();
var typePairings = typePairingsSeq.ToSimpleTypeLookup(); //cache them
foreach (var pairing in typePairings.SelectMany(x => x)) {
if (pairing.targetType == null) {
throw Errors.Missing_member("type",
//.........这里部分代码省略.........