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


C# MethodDefinition.GetAccessbility方法代码示例

本文整理汇总了C#中Mono.Cecil.MethodDefinition.GetAccessbility方法的典型用法代码示例。如果您正苦于以下问题:C# MethodDefinition.GetAccessbility方法的具体用法?C# MethodDefinition.GetAccessbility怎么用?C# MethodDefinition.GetAccessbility使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Mono.Cecil.MethodDefinition的用法示例。


在下文中一共展示了MethodDefinition.GetAccessbility方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ModifyMethod

        private void ModifyMethod(TypeDefinition targetType, MethodDefinition yourMethod,
			MemberActionAttribute memberAction, MethodDefinition targetMethod)
        {
            Log_modifying_member("method", yourMethod);
            var insertAttribute = yourMethod.GetCustomAttribute<DuplicatesBodyAttribute>();
            var bodySource = insertAttribute == null ? yourMethod : GetBodySource(targetType, yourMethod, insertAttribute);
            ModificationScope scope = memberAction.Scope;
            if (scope.HasFlag(AdvancedModificationScope.ExplicitOverrides)) {
                targetMethod.Overrides.Clear();
                foreach (var explicitOverride in yourMethod.Overrides) {
                    targetMethod.Overrides.Add(FixMethodReference(explicitOverride));
                }
            }

            var attrFilter = AttrFilter(scope);
            CopyCustomAttributes(targetMethod, yourMethod, attrFilter);
            CopyCustomAttributes(targetMethod.MethodReturnType, yourMethod.MethodReturnType, attrFilter);
            for (int i = 0; i < yourMethod.Parameters.Count; i++) {
                CopyCustomAttributes(targetMethod.Parameters[i], yourMethod.Parameters[i], attrFilter);
            }
            for (int i = 0; i < yourMethod.GenericParameters.Count; i++) {
                CopyCustomAttributes(targetMethod.GenericParameters[i], yourMethod.GenericParameters[i], attrFilter);
            }

            if ((scope & ModificationScope.Accessibility) != 0) {
                targetMethod.SetAccessibility(yourMethod.GetAccessbility());
            }

            if (scope.HasFlag(ModificationScope.Body)) {
                if (yourMethod.Body != null) {
                    TransferMethodBody(targetMethod, bodySource);
                } else {
                    //this happens in abstract methods and some others.
                    targetMethod.Body = null;
                }
            }
            if (EmbedHistory) {
                targetMethod.AddPatchedByMemberAttribute(yourMethod);
            }

            var toggleAttributesAttr = yourMethod.GetCustomAttribute<ToggleMethodAttributes>();
            var toggleValue = toggleAttributesAttr?.Attributes ?? 0;
            targetMethod.Attributes ^= (MethodAttributes) toggleValue;
        }
开发者ID:GregRos,项目名称:Patchwork,代码行数:44,代码来源:ModifyExisting.cs

示例2: ModifyMethod

        /// <summary>
        ///     Patches the target method by overwriting some aspects with your method, such as: its body and accessibility. Also allows adding custom attributes.
        /// </summary>
        /// <param name="targetMethod">The target method.</param>
        /// <param name="yourMethod">Your method.</param>
        /// <param name="scope">The extent to which to modify the method..</param>
        private void ModifyMethod(MethodDefinition targetMethod, MethodDefinition yourMethod, ModificationScope scope, bool isNew)
        {
            if ((scope & ModificationScope.Accessibility) != 0) {
                targetMethod.SetAccessibility(yourMethod.GetAccessbility());
            }

            if (isNew) {
                //There is absolutely no point allowing you to modify the explicit overrides of existing methods.
                //I thought of adding an enum value, but it will just cause confusion.
                targetMethod.Overrides.Clear();
                foreach (var explicitOverride in yourMethod.Overrides) {
                    targetMethod.Overrides.Add(FixMethodReference(explicitOverride));
                }
            }

            if ((scope & ModificationScope.CustomAttributes) != 0) {
                CopyCustomAttributes(targetMethod, yourMethod);
                CopyCustomAttributes(targetMethod.MethodReturnType, yourMethod.MethodReturnType);
                for (int i = 0; i < yourMethod.Parameters.Count; i++) {
                    CopyCustomAttributes(targetMethod.Parameters[i], yourMethod.Parameters[i]);
                }
                for (int i = 0; i < yourMethod.GenericParameters.Count; i++) {
                    CopyCustomAttributes(targetMethod.GenericParameters[i], yourMethod.GenericParameters[i]);
                }
            }

            if ((scope & ModificationScope.Body) == 0) {
                return;
            }

            if (yourMethod.Body != null) {
                TransferMethodBody(targetMethod, yourMethod);
            } else {
                //this happens in abstract methods and some others.
                targetMethod.Body = null;
            }
        }
开发者ID:gitter-badger,项目名称:Patchwork,代码行数:43,代码来源:ModifyExisting.cs


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