コード例 #1
0
        public void DelegateSyntax_GetIdentifier(string delegateName, bool isGeneric, string expectedResult)
        {
            TypeDef        testDelegate = GetDelegateFromTestAssembly();
            DelegateSyntax syntax       = new DelegateSyntax(testDelegate);

            testDelegate.Name      = delegateName;
            testDelegate.IsGeneric = isGeneric;

            string result = syntax.GetIdentifier();

            Assert.AreEqual(expectedResult, result);
        }
コード例 #2
0
        public SyntaxTokenCollection Format(DelegateSyntax syntax)
        {
            SyntaxTokenCollection tokens = new SyntaxTokenCollection();

            tokens.AddRange(FormatVisibility(syntax));
            tokens.Add(Constants.Space);
            tokens.Add(Constants.KeywordDelegate);
            tokens.Add(Constants.Space);
            tokens.AddRange(FormatReturnType(syntax));
            tokens.Add(Constants.Space);
            tokens.Add(new SyntaxToken(syntax.GetIdentifier(), SyntaxTokens.Text));
            if (_syntax.Class.IsGeneric)
            {
                List <GenericTypeRef> genericTypes = _syntax.GetGenericParameters();
                tokens.AddRange(FormatGenericParameters(genericTypes));
            }
            tokens.AddRange(FormatParameters(syntax.Method));

            return(tokens);
        }
コード例 #3
0
        public SyntaxTokenCollection Format(DelegateSyntax syntax)
        {
            SyntaxTokenCollection tokens = new SyntaxTokenCollection();

            tokens.AddRange(FormatVisibility(syntax));
            tokens.Add(Constants.Space);
            tokens.Add(new SyntaxToken("Delegate", SyntaxTokens.Keyword));
            tokens.Add(Constants.Space);
            if (IsMethodFunction(syntax.GetReturnType()))
            {
                tokens.Add(Constants.KeywordFunction);
            }
            else
            {
                tokens.Add(Constants.KeywordSub);
            }
            tokens.Add(Constants.Space);
            tokens.Add(new SyntaxToken(syntax.GetIdentifier(), SyntaxTokens.Text));
            tokens.AddRange(FormatParameters(syntax.Method));

            // Add the generic details of the delegate
            if (_syntax.Class.IsGeneric)
            {
                List <GenericTypeRef> genericTypes = _syntax.GetGenericParameters();
                tokens.AddRange(FormatGenericParameters(genericTypes));
            }

            if (this.IsMethodFunction(syntax.GetReturnType()))
            {
                tokens.Add(Constants.Space);
                tokens.Add(Constants.KeywordAs);
                tokens.Add(Constants.Space);
                tokens.AddRange(FormatReturnType(syntax));
            }

            return(tokens);
        }