當前位置: 首頁>>代碼示例>>C#>>正文


C# MethodDefinition.SetAccessibility方法代碼示例

本文整理匯總了C#中Mono.Cecil.MethodDefinition.SetAccessibility方法的典型用法代碼示例。如果您正苦於以下問題:C# MethodDefinition.SetAccessibility方法的具體用法?C# MethodDefinition.SetAccessibility怎麽用?C# MethodDefinition.SetAccessibility使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Mono.Cecil.MethodDefinition的用法示例。


在下文中一共展示了MethodDefinition.SetAccessibility方法的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.SetAccessibility方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。