/// <summary>
        /// Foramts the class base portion of a class decleration.
        /// </summary>
        /// <param name="syntax">The syntax details for the class.</param>
        /// <returns>The string representing the class base.</returns>
        public List <SyntaxToken> FormatClassBase(ClassSyntax syntax)
        {
            List <SyntaxToken> tokens = new List <SyntaxToken>();
            bool hasBaseType          = false;

            // Create the list of types and interfaces
            List <SyntaxToken> baseTypesAndInterfaces = new List <SyntaxToken>();

            if (syntax.Class.InheritsFrom != null && syntax.Class.InheritsFrom.GetFullyQualifiedName() != "System.Object")
            {
                tokens.Add(new SyntaxToken(" : ", SyntaxTokens.Text));
                tokens.AddRange(FormatTypeDetails(syntax.GetBaseClass()));
                hasBaseType = true;
            }
            Signatures.TypeDetails[] details = syntax.GetInterfaces();
            for (int i = 0; i < details.Length; i++)
            {
                if (!hasBaseType && i == 0)
                {
                    tokens.Add(new SyntaxToken(": ", SyntaxTokens.Text));
                }
                else if (hasBaseType && i == 0 || i != 0)
                {
                    tokens.Add(new SyntaxToken($",\n\t", SyntaxTokens.Text));
                }
                tokens.AddRange(FormatTypeDetails(details[i]));
            }

            return(tokens);
        }
Ejemplo n.º 2
0
        public void ClassSyntax_GetInterfaces_WhenTypeImplementsNothing_ShouldReturnNoEntries()
        {
            TypeDef     typeDef = new TypeDef();
            ClassSyntax syntax  = new ClassSyntax(typeDef);

            typeDef.Implements = new System.Collections.Generic.List <TypeRef>();

            Array result = syntax.GetInterfaces();

            Assert.IsNotNull(result);
            Assert.AreEqual(0, result.Length);
        }
Ejemplo n.º 3
0
        public void ClassSyntax_GetInterfaces_WhenTypeImplementsNonTypeSpecEntries_ShouldReturnEntries()
        {
            TypeDef     typeDef = new TypeDef();
            ClassSyntax syntax  = new ClassSyntax(typeDef);

            typeDef.Implements = new System.Collections.Generic.List <TypeRef>()
            {
                new TypeRef {
                    Name = "First"
                },
                new TypeRef {
                    Name = "Second"
                }
            };

            // cant test this with typespec entries yet as there is an internal load which requires us to be
            // able to set private variables.

            Array result = syntax.GetInterfaces();

            Assert.AreEqual(2, result.Length);
        }
        public List <SyntaxToken> FormatClassBase(ClassSyntax syntax)
        {
            List <SyntaxToken> tokens = new List <SyntaxToken>();
            bool hasBaseType          = false;

            // Create the list of types and interfaces
            if (syntax.Class.InheritsFrom != null && syntax.Class.InheritsFrom.GetFullyQualifiedName() != "System.Object")
            {
                hasBaseType = true;
            }

            if (hasBaseType)
            {
                tokens.Add(new SyntaxToken("Derives", SyntaxTokens.Keyword));
                tokens.Add(Constants.Space);
                tokens.AddRange(FormatTypeDetails(syntax.GetBaseClass()));
            }

            Signatures.TypeDetails[] interfaces = syntax.GetInterfaces();
            for (int i = 0; i < interfaces.Length; i++)
            {
                if (i == 0)
                {
                    tokens.Add(new SyntaxToken(" _\n\t", SyntaxTokens.Text));
                    tokens.Add(new SyntaxToken("Implements", SyntaxTokens.Keyword));
                    tokens.Add(Constants.Space);
                }
                else if (hasBaseType && i == 0 || i != 0)
                {
                    tokens.Add(new SyntaxToken(", _\n\t\t", SyntaxTokens.Text));
                }
                tokens.AddRange(FormatTypeDetails(interfaces[i]));
            }

            return(tokens);
        }