本文整理汇总了C#中Mono.Cecil.AssemblyDefinition.GetCustomAttribute方法的典型用法代码示例。如果您正苦于以下问题:C# AssemblyDefinition.GetCustomAttribute方法的具体用法?C# AssemblyDefinition.GetCustomAttribute怎么用?C# AssemblyDefinition.GetCustomAttribute使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Mono.Cecil.AssemblyDefinition
的用法示例。
在下文中一共展示了AssemblyDefinition.GetCustomAttribute方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: PatchAssembly
//.........这里部分代码省略.........
new {
ByTask = new {
CreateAndModify = propActions[typeof (NewMemberAttribute)].Count(),
Remove = propActions[typeof (RemoveThisMemberAttribute)].Count(),
Modify = propActions[typeof (ModifiesTypeAttribute)].Count()
},
Total = propActions.Count
});
//++ 2. Removing methods
//remove all the methods
Log.Header("Removing methods");
foreach (var actionParams in methodActions[typeof (RemoveThisMemberAttribute)]) {
var result = actionParams.targetType.GetMethodsLike(actionParams.yourMethod).ToList().Any(x => actionParams.targetType.Methods.Remove(x));
if (!result) {
LogFailedToRemove("method", actionParams.yourMethod);
}
}
//++ 3. Creating new methods
Log.Header("Creating new methods");
//create all the new methods
foreach (var actionParams in methodActions[typeof (NewMemberAttribute)]) {
var status = CreateNewMethod(actionParams.targetType,
actionParams.yourMethod,
(NewMemberAttribute) actionParams.methodActionAttr);
if (status == NewMemberStatus.InvalidItem) {
Log_failed_to_create();
methodActions.Remove(actionParams);
}
}
//++ 4. Adding custom attributes to module/assembly.
var assemblyImportAttribute = yourAssembly.GetCustomAttribute<ImportCustomAttributesAttribute>();
var moduleImportAttribute = yourAssembly.MainModule.GetCustomAttribute<ImportCustomAttributesAttribute>();
CopyCustomAttributesByImportAttribute(TargetAssembly, yourAssembly, assemblyImportAttribute);
CopyCustomAttributesByImportAttribute(TargetAssembly.MainModule, yourAssembly.MainModule, moduleImportAttribute);
//++ 5. Modifying type declerations
Log.Information("Updating Type Ceclerations");
foreach (var modType in typesByAction[typeof (NewTypeAttribute)]) {
AutoModifyTypeDecleration(modType.yourType);
}
//++ 6. Updating Fields
Log.Header("Clearing fields in replaced types");
//+ Removing fields in replaced types
foreach (var pairing in typePairings[typeof (ReplaceTypeAttribute)]) {
Log.Information("Clearing fields in {0:l}", pairing.targetType.UserFriendlyName());
pairing.targetType.Fields.Clear();
}
//+ Removing fields
Log.Header("Removing fields");
foreach (var fieldAction in fieldActions[typeof (RemoveThisMemberAttribute)]) {
var removed =
fieldAction.targetType.Fields.RemoveWhere(x => x.Name == fieldAction.yourField.Name);
if (!removed) {
LogFailedToRemove("field", fieldAction.yourField);
}
}
//+ Creating new fields
Log.Header("Creating new fields");
foreach (var fieldAction in fieldActions[typeof (NewMemberAttribute)]) {
var status = CreateNewField(fieldAction.targetType,