NArrange.VisualBasic.VBParser.ParseMethod C# (CSharp) Method

ParseMethod() private method

Parses a method.
private ParseMethod ( CodeAccess access, MemberModifiers memberAttributes, bool isFunction, bool isDelegate, bool isOperator, OperatorType operatorType, bool inInterface, bool isExternal, string externalModifier ) : MethodElement
access CodeAccess The member access.
memberAttributes MemberModifiers The member attributes.
isFunction bool Whether or not the method is a function.
isDelegate bool Whether or not the method is a delegate.
isOperator bool Whether or not the method is an operator.
operatorType OperatorType Type of the operator.
inInterface bool Whether or not the method is in an interface.
isExternal bool Whether or not the method is external.
externalModifier string The external modifier.
return NArrange.Core.CodeElements.MethodElement
        private MethodElement ParseMethod(
			CodeAccess access,
			MemberModifiers memberAttributes,
			bool isFunction,
			bool isDelegate,
			bool isOperator,
			OperatorType operatorType,
			bool inInterface,
			bool isExternal,
			string externalModifier)
        {
            MethodElement method = new MethodElement();

            method.Name = CaptureWord();
            if (isOperator)
            {
                // Handle greater than/less than for the method name since these will get
                // excluded with < and > being alias breaks (needed by attributes).
                while (NextChar == VBSymbol.BeginAttribute || NextChar == VBSymbol.EndAttribute)
                {
                    TryReadChar();
                    method.Name += CurrentChar + CaptureWord();
                }
            }

            method.Access = access;
            method.MemberModifiers = memberAttributes;

            method.IsOperator = isOperator;
            method.OperatorType = operatorType;
            method[VBExtendedProperties.ExternalModifier] = externalModifier;

            if (isExternal)
            {
                method.MemberModifiers = method.MemberModifiers | MemberModifiers.External;

                EatLineContinuation();

                EatWord(VBKeyword.Lib);

                EatLineContinuation();

                EatChar(VBSymbol.BeginString);
                string library = CaptureWord().TrimEnd(VBSymbol.BeginString);

                method[VBExtendedProperties.ExternalLibrary] = library;

                EatLineContinuation();

                if (NextChar != VBSymbol.BeginParameterList)
                {
                    EatLineContinuation();

                    EatWord(VBKeyword.Alias);

                    EatLineContinuation();

                    EatChar(VBSymbol.BeginString);
                    string alias = CaptureWord().TrimEnd(VBSymbol.BeginString);

                    method[VBExtendedProperties.ExternalAlias] = alias;
                }
            }

            EatLineContinuation();

            EatChar(VBSymbol.BeginParameterList);
            EatWhiteSpace();
            string paramsTemp = string.Empty;

            if (char.ToLower(NextChar) == char.ToLower(VBKeyword.Of[0]))
            {
                TryReadChar();
                paramsTemp += CurrentChar;

                if (char.ToLower(NextChar) == char.ToLower(VBKeyword.Of[1]))
                {
                    TryReadChar();
                    paramsTemp = string.Empty;

                    this.ParseTypeParameters(method);

                    EatChar(VBSymbol.BeginParameterList);
                    EatWhiteSpace();
                }
            }

            method.Parameters = paramsTemp + ParseNestedText(
                VBSymbol.BeginParameterList, VBSymbol.EndParameterList, false, false);

            if (isFunction || isOperator)
            {
                EatLineContinuation();
                if (char.ToUpper(NextChar) == VBKeyword.As[0])
                {
                    EatWord(VBKeyword.As);
                    method.Type = CaptureTypeName();
                }
                else
                {
                    method.Type = string.Empty;
                }
            }

            EatWhiteSpace();

            string[] implements;
            string[] handles;
            bool parseHandles = !(isFunction || isOperator || isDelegate);
            string blockTemp = TryParseImplementsOrHandles(out implements, out handles, parseHandles);
            if (parseHandles)
            {
                method[VBExtendedProperties.Handles] = handles;
            }

            foreach (string implementation in implements)
            {
                InterfaceReference interfaceReference =
                    new InterfaceReference(implementation, InterfaceReferenceType.Interface);
                method.AddImplementation(interfaceReference);
            }

            if ((memberAttributes & MemberModifiers.Abstract) != MemberModifiers.Abstract &&
                !inInterface && !isExternal)
            {
                if (isFunction || isOperator)
                {
                    if (isOperator)
                    {
                        method.BodyText = (blockTemp + this.ParseBlock(VBKeyword.Operator)).Trim();
                    }
                    else if (!isDelegate)
                    {
                        method.BodyText = (blockTemp + this.ParseBlock(VBKeyword.Function)).Trim();
                    }
                }
                else if (!isDelegate)
                {
                    method.BodyText = (blockTemp + this.ParseBlock(VBKeyword.Sub)).Trim();
                }
            }

            return method;
        }