本文整理匯總了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,