コード例 #1
0
 CodeMemberMethod CreateMethod(string methodName, MethodAccessibility access, MethodScope scope, string returnType)
 {
     return(CreateMethod(methodName, access, scope, new CodeTypeReference(returnType)));
 }
コード例 #2
0
        CodeMemberMethod CreateMethod(string methodName, MethodAccessibility access, MethodScope scope, CodeTypeReference returnType)
        {
            var ret = new CodeMemberMethod {
                Name = methodName,
            };

            if (returnType != null)
            {
                ret.ReturnType = returnType;
            }

            MemberAttributes attrs;

            switch (access)
            {
            case MethodAccessibility.Internal:
                attrs = MemberAttributes.FamilyAndAssembly;
                break;

            case MethodAccessibility.Private:
                attrs = MemberAttributes.Private;
                break;

            case MethodAccessibility.Protected:
                attrs = MemberAttributes.Family;
                break;

            case MethodAccessibility.Public:
                attrs = MemberAttributes.Public;
                break;

            default:
                throw new NotSupportedException($"Method accessibility {access} is not supported");
            }

            if ((scope & MethodScope.Static) == MethodScope.Static)
            {
                attrs |= MemberAttributes.Static | MemberAttributes.Final;
            }
            else if ((scope & MethodScope.Abstract) == MethodScope.Abstract)
            {
                attrs |= MemberAttributes.Abstract;
            }
            else
            {
                if ((scope & MethodScope.Override) == MethodScope.Override)
                {
                    attrs |= MemberAttributes.Override;
                }
                else if ((scope & MethodScope.Virtual) == MethodScope.Virtual)
                {
                }
                else
                {
                    attrs |= MemberAttributes.Final;
                }
            }

            ret.Attributes = attrs;
            return(ret);
        }
コード例 #3
0
 CodeMemberMethod CreateMethod(string methodName, MethodAccessibility access, MethodScope scope)
 {
     return(CreateMethod(methodName, access, scope, (CodeTypeReference)null));
 }