Delegate element.
Inheritance: MemberElement, IGenericElement
Exemple #1
0
        /// <summary>
        /// Creates a clone of this instance.
        /// </summary>
        /// <returns>Clone of the instance with the member element state copied.</returns>
        protected override MemberElement DoMemberClone()
        {
            DelegateElement clone = new DelegateElement();

            //
            // Copy state
            //
            clone._params = _params;

            foreach (TypeParameter typeParam in TypeParameters)
            {
                TypeParameter typeParamClone = typeParam.Clone() as TypeParameter;
                clone.TypeParametersBase.Add(typeParamClone);
            }

            return(clone);
        }
Exemple #2
0
        /// <summary>
        /// Parses a delegate.
        /// </summary>
        /// <param name="access">The member access.</param>
        /// <param name="memberAttributes">The member attributes.</param>
        /// <returns>Delegate code element.</returns>
        private DelegateElement ParseDelegate(
            CodeAccess access, MemberModifiers memberAttributes)
        {
            string delegateType = CaptureWord();

            bool isFunction = false;
            switch (VBKeyword.Normalize(delegateType))
            {
                case VBKeyword.Sub:
                    isFunction = false;
                    break;

                case VBKeyword.Function:
                    isFunction = true;
                    break;

                default:
                    this.OnParseError(
                        "Expected Sub or Function for delegate declaration");
                    break;
            }

            MethodElement methodElement = ParseMethod(
                access, memberAttributes, isFunction, true, false, OperatorType.None, false, false, null);

            DelegateElement delegateElement = new DelegateElement();
            delegateElement.Name = methodElement.Name;
            delegateElement.Access = methodElement.Access;
            delegateElement.MemberModifiers = methodElement.MemberModifiers;
            delegateElement.Parameters = methodElement.Parameters;
            delegateElement.BodyText = methodElement.BodyText;
            if (isFunction)
            {
                delegateElement.Type = methodElement.Type;
            }

            foreach (TypeParameter typeParameter in methodElement.TypeParameters)
            {
                delegateElement.AddTypeParameter(typeParameter);
            }

            return delegateElement;
        }
 /// <summary>
 /// Processes a delegate element.
 /// </summary>
 /// <param name="element">Delegate code element.</param>
 public abstract void VisitDelegateElement(DelegateElement element);
        /// <summary>
        /// Processes a delegate element.
        /// </summary>
        /// <param name="element">Delegate code element.</param>
        public override void VisitDelegateElement(DelegateElement element)
        {
            this.WriteComments(element.HeaderComments);
            this.WriteAttributes(element);

            WriteAccess(element.Access);

            WriteMemberAttributes(
                element.MemberModifiers,
                element[VBExtendedProperties.Overloads] is bool && (bool)element[VBExtendedProperties.Overloads]);

            Writer.Write(VBKeyword.Delegate);
            Writer.Write(' ');

            WriteMethodType(element.Type);

            Writer.Write(element.Name);

            WriteTypeParameters(element);
            WriteParameterList(element.Parameters);

            WriteReturnType(element.Type);
        }
Exemple #5
0
        /// <summary>
        /// Creates a clone of this instance.
        /// </summary>
        /// <returns>Clone of the instance with the member element state copied.</returns>
        protected override MemberElement DoMemberClone()
        {
            DelegateElement clone = new DelegateElement();

            //
            // Copy state
            //
            clone._params = _params;

            foreach (TypeParameter typeParam in TypeParameters)
            {
                TypeParameter typeParamClone = typeParam.Clone() as TypeParameter;
                clone.TypeParametersBase.Add(typeParamClone);
            }

            return clone;
        }
        /// <summary>
        /// Processes a delegate element.
        /// </summary>
        /// <param name="element">Delegate code element.</param>
        public override void VisitDelegateElement(DelegateElement element)
        {
            this.WriteComments(element.HeaderComments);
            this.WriteAttributes(element);

            WriteAccess(element.Access);

            WriteMemberAttributes(element.MemberModifiers);

            Writer.Write(CSharpKeyword.Delegate);
            Writer.Write(' ');

            Writer.Write(element.Type);
            Writer.Write(' ');

            Writer.Write(element.Name);

            WriteTypeParameters(element);
            WriteParameterList(element.Parameters);
            WriteTypeParameterConstraints(element);
            Writer.Write(CSharpSymbol.EndOfStatement);
        }
        /// <summary>
        /// Parses a delegate.
        /// </summary>
        /// <param name="memberName">Member name</param>
        /// <param name="access">Code access</param>
        /// <param name="memberAttributes">Member attributes</param>
        /// <param name="returnType">Return type</param>
        /// <returns>A delegate code element.</returns>
        private DelegateElement ParseDelegate(
            string memberName, CodeAccess access, MemberModifiers memberAttributes, string returnType)
        {
            DelegateElement delegateElement = new DelegateElement();
            delegateElement.Name = memberName;
            delegateElement.Access = access;
            delegateElement.Type = returnType;
            delegateElement.MemberModifiers = memberAttributes;

            int genericIndex = memberName.IndexOf(CSharpSymbol.BeginGeneric);
            bool isGeneric = genericIndex >= 0 && genericIndex < memberName.Length - 1;
            if (isGeneric)
            {
                delegateElement.Name = memberName.Substring(0, genericIndex);
                string typeParameterString = memberName.TrimEnd(CSharpSymbol.EndGeneric).Substring(
                    genericIndex + 1);

                string[] typeParameterNames = typeParameterString.Split(
                    new char[] { CSharpSymbol.AliasSeparator, ' ' },
                    StringSplitOptions.RemoveEmptyEntries);
                foreach (string typeParameterName in typeParameterNames)
                {
                    TypeParameter typeParameter = new TypeParameter();
                    typeParameter.Name = typeParameterName;
                    delegateElement.AddTypeParameter(typeParameter);
                }
            }

            delegateElement.Parameters = this.ParseParameters();

            if (isGeneric)
            {
                ParseTypeParameterConstraints(delegateElement);
            }

            EatChar(CSharpSymbol.EndOfStatement);

            return delegateElement;
        }
Exemple #8
0
        /// <summary>
        /// Parses a delegate.
        /// </summary>
        /// <param name="memberName">Member name</param>
        /// <param name="access">Code access</param>
        /// <param name="memberAttributes">Member attributes</param>
        /// <param name="returnType">Return type</param>
        /// <returns>A delegate code element.</returns>
        private DelegateElement ParseDelegate(
			string memberName, CodeAccess access, MemberModifiers memberAttributes, string returnType)
        {
            DelegateElement delegateElement = new DelegateElement();
            delegateElement.Name = memberName;
            delegateElement.Access = access;
            delegateElement.Type = returnType;
            delegateElement.MemberModifiers = memberAttributes;

            int genericIndex = memberName.IndexOf(CSharpSymbol.BeginGeneric);
            bool isGeneric = genericIndex >= 0 && genericIndex < memberName.Length - 1;
            if (isGeneric)
            {
                delegateElement.Name = memberName.Substring(0, genericIndex);
                string typeParameterString = memberName.TrimEnd(CSharpSymbol.EndGeneric).Substring(
                    genericIndex + 1);

                string[] typeParameterNames = typeParameterString.Split(
                    new char[] { CSharpSymbol.AliasSeparator, ' ' },
                    StringSplitOptions.RemoveEmptyEntries);

                bool checkVariance = false;
                for (int i = 0; i < typeParameterNames.Length; i++)
                {
                    string typeParameterName = typeParameterNames[i];
                    if (typeParameterName == "in" || typeParameterName == "out")
                    {
                        checkVariance = true;
                        continue;
                    }
                    TypeParameter typeParameter = new TypeParameter();

                    if (checkVariance)
                    {
                        checkVariance = false;
                        typeParameter.IsIn = typeParameterNames[i - 1] == "in";
                        typeParameter.IsOut = typeParameterNames[i - 1] == "out";
                    }
                    typeParameter.Name = typeParameterName;
                    delegateElement.AddTypeParameter(typeParameter);
                }
            }

            delegateElement.Parameters = this.ParseParameters();

            if (isGeneric)
            {
                ParseTypeParameterConstraints(delegateElement);
            }

            EatChar(CSharpSymbol.EndOfStatement);

            return delegateElement;
        }