当前位置: 首页>>代码示例>>C#>>正文


C# AssemblyDefinition.GetCustomAttribute方法代码示例

本文整理汇总了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,
开发者ID:gitter-badger,项目名称:Patchwork,代码行数:67,代码来源:AssemblyPatcher.cs


注:本文中的Mono.Cecil.AssemblyDefinition.GetCustomAttribute方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。