Ejemplo n.º 1
0
        /// <summary>
        /// Initializes a new instance of the UsingDirective class.
        /// </summary>
        /// <param name="document">The document that contains the element.</param>
        /// <param name="parent">The parent of the element.</param>
        /// <param name="declaration">The declaration code for this element.</param>
        /// <param name="generated">Indicates whether the code element was generated or written by hand.</param>
        /// <param name="namespace">The namespace being used.</param>
        /// <param name="alias">Optional alias for the namespace, if any.</param>
        internal UsingDirective(
            CsDocument document,
            CsElement parent,
            Declaration declaration,
            bool generated,
            string @namespace,
            string alias)
            : base(document,
            parent,
            ElementType.UsingDirective,
            "using " + declaration.Name,
            null,
            null,
            declaration,
            false,
            generated)
        {
            Param.Ignore(document);
            Param.Ignore(parent);
            Param.Ignore(declaration);
            Param.Ignore(generated);
            Param.AssertValidString(@namespace, "namespace");
            Param.Ignore(alias);

            this.namespaceType = @namespace;

            if (alias != null)
            {
                this.alias = alias;
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Initializes a new instance of the EnumItem class.
        /// </summary>
        /// <param name="document">The document that contains the element.</param>
        /// <param name="parent">The parent of the element.</param>
        /// <param name="header">The Xml header for this element.</param>
        /// <param name="attributes">The list of attributes attached to this element.</param>
        /// <param name="declaration">The declaration code for this element.</param>
        /// <param name="initialization">The initialization expression, if there is one.</param>
        /// <param name="unsafeCode">Indicates whether the element resides within a block of unsafe code.</param>
        /// <param name="generated">Indicates whether the code element was generated or written by hand.</param>
        internal EnumItem(
            CsDocument document,
            Enum parent,
            XmlHeader header,
            ICollection<Attribute> attributes,
            Declaration declaration,
            Expression initialization,
            bool unsafeCode,
            bool generated)
            : base(document,
            parent,
            ElementType.EnumItem, 
            "enum item " + declaration.Name, 
            header, 
            attributes,
            declaration,
            unsafeCode,
            generated)
        {
            Param.Ignore(document, parent, header, attributes, declaration, initialization, unsafeCode, generated);

            this.initialization = initialization;
            if (this.initialization != null)
            {
                this.AddExpression(this.initialization);
            }
        }
Ejemplo n.º 3
0
 internal Field(CsDocument document, CsElement parent, XmlHeader header, ICollection<Microsoft.StyleCop.CSharp.Attribute> attributes, Declaration declaration, TypeToken fieldType, bool unsafeCode, bool generated)
     : base(document, parent, ElementType.Field, "field " + declaration.Name, header, attributes, declaration, unsafeCode, generated)
 {
     this.type = fieldType;
     this.isConst = base.Declaration.ContainsModifier(new CsTokenType[] { CsTokenType.Const });
     this.isReadOnly = base.Declaration.ContainsModifier(new CsTokenType[] { CsTokenType.Readonly });
 }
Ejemplo n.º 4
0
        /// <summary>
        /// Initializes a new instance of the Destructor class.
        /// </summary>
        /// <param name="document">The documenent that contains the element.</param>
        /// <param name="parent">The parent of the element.</param>
        /// <param name="header">The Xml header for this element.</param>
        /// <param name="attributes">The list of attributes attached to this element.</param>
        /// <param name="declaration">The declaration code for this element.</param>
        /// <param name="unsafeCode">Indicates whether the element resides within a block of unsafe code.</param>
        /// <param name="generated">Indicates whether the code element was generated or written by hand.</param>
        internal Destructor(
            CsDocument document,
            CsElement parent,
            XmlHeader header,
            ICollection<Attribute> attributes,
            Declaration declaration,
            bool unsafeCode,
            bool generated)
            : base(document,
            parent,
            ElementType.Destructor,
            "destructor " + declaration.Name,
            header,
            attributes,
            declaration,
            unsafeCode,
            generated)
        {
            Param.AssertNotNull(document, "document");
            Param.AssertNotNull(parent, "parent");
            Param.Ignore(header);
            Param.Ignore(attributes);
            Param.AssertNotNull(declaration, "declaration");
            Param.Ignore(unsafeCode);
            Param.Ignore(generated);

            // Static destructors are always public.
            if (this.Declaration.ContainsModifier(CsTokenType.Static))
            {
                this.Declaration.AccessModifierType = AccessModifierType.Public;
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Initializes a new instance of the ClassBase class.
        /// </summary>
        /// <param name="document">The document that contains the element.</param>
        /// <param name="parent">The parent of the element.</param>
        /// <param name="type">The element type.</param>
        /// <param name="name">The name of this element.</param>
        /// <param name="header">The Xml header for this element.</param>
        /// <param name="attributes">The list of attributes attached to this element.</param>
        /// <param name="declaration">The declaration code for this element.</param>
        /// <param name="typeConstraints">The list of type constraints on the element.</param>
        /// <param name="unsafeCode">Indicates whether the element resides within a block of unsafe code.</param>
        /// <param name="generated">Indicates whether the code element was generated or written by hand.</param>
        internal ClassBase(
            CsDocument document,
            CsElement parent,
            ElementType type,
            string name,
            XmlHeader header,
            ICollection<Attribute> attributes,
            Declaration declaration,
            ICollection<TypeParameterConstraintClause> typeConstraints,
            bool unsafeCode,
            bool generated)
            : base(document, parent, type, name, header, attributes, declaration, unsafeCode, generated)
        {
            Param.Ignore(document, parent, type, name, header, attributes, declaration, typeConstraints, unsafeCode, generated);

            this.typeConstraints = typeConstraints;

            // Set the parent of the type constraint clauses.
            if (typeConstraints != null)
            {
                Debug.Assert(typeConstraints.IsReadOnly, "The typeconstraints collection should be read-only.");

                foreach (TypeParameterConstraintClause constraint in typeConstraints)
                {
                    constraint.ParentElement = this;
                }
            }
        }
Ejemplo n.º 6
0
 internal Method(CsDocument document, CsElement parent, XmlHeader header, ICollection<Microsoft.StyleCop.CSharp.Attribute> attributes, Declaration declaration, TypeToken returnType, IList<Parameter> parameters, ICollection<TypeParameterConstraintClause> typeConstraints, bool unsafeCode, bool generated)
     : base(document, parent, ElementType.Method, "method " + declaration.Name, header, attributes, declaration, unsafeCode, generated)
 {
     this.returnType = returnType;
     this.parameters = parameters;
     this.typeConstraints = typeConstraints;
     if ((this.parameters.Count > 0) && base.Declaration.ContainsModifier(new CsTokenType[] { CsTokenType.Static }))
     {
         foreach (Parameter parameter in this.parameters)
         {
             if ((parameter.Modifiers & ParameterModifiers.This) != ParameterModifiers.None)
             {
                 this.extensionMethod = true;
             }
             break;
         }
     }
     base.QualifiedName = CodeParser.AddQualifications(this.parameters, base.QualifiedName);
     if ((base.Declaration.Name.IndexOf(".", StringComparison.Ordinal) > -1) && !base.Declaration.Name.StartsWith("this.", StringComparison.Ordinal))
     {
         base.Declaration.AccessModifierType = AccessModifierType.Public;
     }
     if (typeConstraints != null)
     {
         foreach (TypeParameterConstraintClause clause in typeConstraints)
         {
             clause.ParentElement = this;
         }
     }
 }
Ejemplo n.º 7
0
        /// <summary>
        /// Initializes a new instance of the Field class.
        /// </summary>
        /// <param name="document">The documenent that contains the element.</param>
        /// <param name="parent">The parent of the element.</param>
        /// <param name="header">The Xml header for this element.</param>
        /// <param name="attributes">The list of attributes attached to this element.</param>
        /// <param name="declaration">The declaration code for this element.</param>
        /// <param name="fieldType">The type of the field.</param>
        /// <param name="unsafeCode">Indicates whether the element resides within a block of unsafe code.</param>
        /// <param name="generated">Indicates whether the code element was generated or written by hand.</param>
        internal Field(
            CsDocument document,
            CsElement parent,
            XmlHeader header,
            ICollection<Attribute> attributes,
            Declaration declaration,
            TypeToken fieldType,
            bool unsafeCode,
            bool generated)
            : base(document, 
            parent, 
            ElementType.Field, 
            "field " + declaration.Name, 
            header,
            attributes,
            declaration, 
            unsafeCode,
            generated)
        {
            Param.AssertNotNull(document, "document");
            Param.AssertNotNull(parent, "parent");
            Param.Ignore(header);
            Param.Ignore(attributes);
            Param.AssertNotNull(declaration, "declaration");
            Param.AssertNotNull(fieldType, "fieldType");
            Param.Ignore(unsafeCode);
            Param.Ignore(generated);

            this.type = fieldType;

            // Determine whether the item is const or readonly.
            this.isConst = this.Declaration.ContainsModifier(CsTokenType.Const);
            this.isReadOnly = this.Declaration.ContainsModifier(CsTokenType.Readonly);
        }
Ejemplo n.º 8
0
 protected void SetInheritedItems(Declaration declaration)
 {
     Param.RequireNotNull(declaration, "declaration");
     bool flag = false;
     bool flag2 = false;
     List<string> list = new List<string>();
     foreach (CsToken token in declaration.Tokens)
     {
         if (flag)
         {
             if ((((token.CsTokenType != CsTokenType.WhiteSpace) && (token.CsTokenType != CsTokenType.EndOfLine)) && ((token.CsTokenType != CsTokenType.SingleLineComment) && (token.CsTokenType != CsTokenType.MultiLineComment))) && (token.CsTokenType != CsTokenType.PreprocessorDirective))
             {
                 if (((token.Text.Length >= 2) && (token.Text[0] == 'I')) && char.IsUpper(token.Text[1]))
                 {
                     list.Add(CodeParser.TrimType(token.Text));
                 }
                 else
                 {
                     this.baseClass = CodeParser.TrimType(token.Text);
                 }
                 flag = false;
             }
             continue;
         }
         if (flag2)
         {
             if ((((token.CsTokenType != CsTokenType.WhiteSpace) && (token.CsTokenType != CsTokenType.EndOfLine)) && ((token.CsTokenType != CsTokenType.SingleLineComment) && (token.CsTokenType != CsTokenType.MultiLineComment))) && (token.CsTokenType != CsTokenType.PreprocessorDirective))
             {
                 list.Add(CodeParser.TrimType(token.Text));
                 flag2 = false;
             }
         }
         else
         {
             if (token.CsTokenType == CsTokenType.Where)
             {
                 break;
             }
             if (token.Text == ":")
             {
                 if (this.baseClass.Length > 0)
                 {
                     break;
                 }
                 flag = true;
                 continue;
             }
             if (token.CsTokenType == CsTokenType.Comma)
             {
                 flag2 = true;
             }
         }
     }
     if (list.Count > 0)
     {
         this.implementedInterfaces = list.ToArray();
     }
 }
Ejemplo n.º 9
0
 internal Property(CsDocument document, CsElement parent, XmlHeader header, ICollection<Microsoft.StyleCop.CSharp.Attribute> attributes, Declaration declaration, TypeToken returnType, bool unsafeCode, bool generated)
     : base(document, parent, ElementType.Property, "property " + declaration.Name, header, attributes, declaration, unsafeCode, generated)
 {
     this.returnType = returnType;
     if ((base.Declaration.Name.IndexOf(".", StringComparison.Ordinal) > -1) && !base.Declaration.Name.StartsWith("this.", StringComparison.Ordinal))
     {
         base.Declaration.AccessModifierType = AccessModifierType.Public;
     }
 }
Ejemplo n.º 10
0
 internal UsingDirective(CsDocument document, CsElement parent, Declaration declaration, bool generated, string @namespace, string alias)
     : base(document, parent, ElementType.UsingDirective, "using " + declaration.Name, null, null, declaration, false, generated)
 {
     this.namespaceType = string.Empty;
     this.alias = string.Empty;
     this.namespaceType = @namespace;
     if (alias != null)
     {
         this.alias = alias;
     }
 }
Ejemplo n.º 11
0
 internal Indexer(CsDocument document, CsElement parent, XmlHeader header, ICollection<Microsoft.StyleCop.CSharp.Attribute> attributes, Declaration declaration, TypeToken returnType, IList<Parameter> parameters, bool unsafeCode, bool generated)
     : base(document, parent, ElementType.Indexer, "indexer " + declaration.Name, header, attributes, declaration, unsafeCode, generated)
 {
     this.returnType = returnType;
     this.parameters = parameters;
     base.QualifiedName = CodeParser.AddQualifications(this.parameters, base.QualifiedName);
     if ((base.Declaration.Name.IndexOf(".", StringComparison.Ordinal) > -1) && !base.Declaration.Name.StartsWith("this.", StringComparison.Ordinal))
     {
         base.Declaration.AccessModifierType = AccessModifierType.Public;
     }
 }
Ejemplo n.º 12
0
        /// <summary>
        /// Initializes a new instance of the Delegate class.
        /// </summary>
        /// <param name="document">The document that contains the element.</param>
        /// <param name="parent">The parent of the element.</param>
        /// <param name="header">The Xml header for this element.</param>
        /// <param name="attributes">The list of attributes attached to this element.</param>
        /// <param name="declaration">The declaration code for this element.</param>
        /// <param name="returnType">The return type.</param>
        /// <param name="parameters">The parameters to the delegate.</param>
        /// <param name="typeConstraints">The list of type constraints on the element.</param>
        /// <param name="unsafeCode">Indicates whether the element resides within a block of unsafe code.</param>
        /// <param name="generated">Indicates whether this is generated code.</param>
        internal Delegate(
            CsDocument document,
            CsElement parent,
            XmlHeader header,
            ICollection<Attribute> attributes,
            Declaration declaration,
            TypeToken returnType,
            IList<Parameter> parameters,
            ICollection<TypeParameterConstraintClause> typeConstraints,
            bool unsafeCode,
            bool generated)
            : base(document,
            parent,
            ElementType.Delegate, 
            "delegate " + declaration.Name,
            header, 
            attributes,
            declaration,
            unsafeCode,
            generated)
        {
            Param.AssertNotNull(document, "document");
            Param.AssertNotNull(parent, "parent");
            Param.Ignore(header);
            Param.Ignore(attributes);
            Param.AssertNotNull(declaration, "declaration");
            Param.AssertNotNull(returnType, "returnType");
            Param.AssertNotNull(parameters, "parameters");
            Param.Ignore(typeConstraints);
            Param.Ignore(unsafeCode);
            Param.Ignore(generated);

            this.returnType = returnType;
            this.typeConstraints = typeConstraints;
            this.parameters = parameters;

            Debug.Assert(parameters.IsReadOnly, "The parameters collection should be read-only.");

            // Add the qualifications
            this.QualifiedName = CodeParser.AddQualifications(this.parameters, this.QualifiedName);

            // Set the parent of the type constraint clauses.
            if (typeConstraints != null)
            {
                Debug.Assert(typeConstraints.IsReadOnly, "The collection of type constraints should be read-only.");

                foreach (TypeParameterConstraintClause constraint in typeConstraints)
                {
                    constraint.ParentElement = this;
                }
            }
        }
Ejemplo n.º 13
0
        /// <summary>
        /// Initializes a new instance of the Constructor class.
        /// </summary>
        /// <param name="document">The documenent that contains the element.</param>
        /// <param name="parent">The parent of the element.</param>
        /// <param name="header">The Xml header for this element.</param>
        /// <param name="attributes">The list of attributes attached to this element.</param>
        /// <param name="declaration">The declaration code for this element.</param>
        /// <param name="parameters">The parameters to the constructor.</param>
        /// <param name="initializerExpression">The constructor initializer, if there is one.</param>
        /// <param name="unsafeCode">Indicates whether the element resides within a block of unsafe code.</param>
        /// <param name="generated">Indicates whether the code element was generated or written by hand.</param>
        internal Constructor(
            CsDocument document,
            CsElement parent,
            XmlHeader header,
            ICollection<Attribute> attributes,
            Declaration declaration,
            IList<Parameter> parameters,
            MethodInvocationExpression initializerExpression,
            bool unsafeCode,
            bool generated)
            : base(document,
            parent,
            ElementType.Constructor,
            "constructor " + declaration.Name,
            header,
            attributes,
            declaration,
            unsafeCode,
            generated)
        {
            Param.AssertNotNull(document, "document");
            Param.AssertNotNull(parent, "parent");
            Param.Ignore(header);
            Param.Ignore(attributes);
            Param.AssertNotNull(declaration, "declaration");
            Param.AssertNotNull(parameters, "parameters");
            Param.Ignore(initializerExpression);
            Param.Ignore(unsafeCode);
            Param.Ignore(generated);

            // Static constructors are always public.
            if (this.Declaration.ContainsModifier(CsTokenType.Static))
            {
                this.Declaration.AccessModifierType = AccessModifierType.Public;
            }

            this.parameters = parameters;
            Debug.Assert(parameters.IsReadOnly, "The parameters collection should be read-only.");

            // Add the qualifications
            this.QualifiedName = CodeParser.AddQualifications(this.parameters, this.QualifiedName);

            // If there is an initializer expression, add it to the statement list for this constructor.
            if (initializerExpression != null)
            {
                this.initializer = initializerExpression;

                ConstructorInitializerStatement initializerStatement = new ConstructorInitializerStatement(
                    initializerExpression.Tokens, initializerExpression);
                this.AddStatement(initializerStatement);
            }
        }
Ejemplo n.º 14
0
 internal ClassBase(CsDocument document, CsElement parent, ElementType type, string name, XmlHeader header, ICollection<Microsoft.StyleCop.CSharp.Attribute> attributes, Declaration declaration, ICollection<TypeParameterConstraintClause> typeConstraints, bool unsafeCode, bool generated)
     : base(document, parent, type, name, header, attributes, declaration, unsafeCode, generated)
 {
     this.baseClass = string.Empty;
     this.implementedInterfaces = new string[0];
     this.typeConstraints = typeConstraints;
     if (typeConstraints != null)
     {
         foreach (TypeParameterConstraintClause clause in typeConstraints)
         {
             clause.ParentElement = this;
         }
     }
 }
Ejemplo n.º 15
0
 /// <summary>
 /// Initializes a new instance of the DocumentRoot class.
 /// </summary>
 /// <param name="document">The document that this element belongs to.</param>
 /// <param name="declaration">The decleration class for this element.</param>
 /// <param name="generated">Indicates whether the element contains generated code.</param>
 internal DocumentRoot(CsDocument document, Declaration declaration, bool generated)
     : base(document,
     null, 
     ElementType.Root,
     Strings.DocumentRoot,
     null, 
     null,
     declaration, 
     false,
     generated)
 {
     Param.AssertNotNull(document, "document");
     Param.AssertNotNull(declaration, "declaration");
     Param.Ignore(generated);
 }
Ejemplo n.º 16
0
 /// <summary>
 /// Initializes a new instance of the ExternAliasDirective class.
 /// </summary>
 /// <param name="document">The document that contains the element.</param>
 /// <param name="parent">The parent of the element.</param>
 /// <param name="declaration">The declaration code for this element.</param>
 /// <param name="generated">Indicates whether the code element was generated or written by hand.</param>
 internal ExternAliasDirective(
     CsDocument document,
     CsElement parent,
     Declaration declaration,
     bool generated)
     : base(document,
     parent,
     ElementType.ExternAliasDirective,
     "extern alias " + declaration.Name,
     null,
     null,
     declaration,
     false,
     generated)
 {
     Param.Ignore(document, parent, declaration, generated);
 }
Ejemplo n.º 17
0
        /// <summary>
        /// Initializes a new instance of the Indexer class.
        /// </summary>
        /// <param name="document">The documenent that contains the element.</param>
        /// <param name="parent">The parent of the element.</param>
        /// <param name="header">The Xml header for this element.</param>
        /// <param name="attributes">The list of attributes attached to this element.</param>
        /// <param name="declaration">The declaration code for this element.</param>
        /// <param name="returnType">The return type of the indexer.</param>
        /// <param name="parameters">The parameters to the indexer.</param>
        /// <param name="unsafeCode">Indicates whether the element resides within a block of unsafe code.</param>
        /// <param name="generated">Indicates whether the code element was generated or written by hand.</param>
        internal Indexer(
            CsDocument document,
            CsElement parent,
            XmlHeader header,
            ICollection<Attribute> attributes,
            Declaration declaration,
            TypeToken returnType,
            IList<Parameter> parameters,
            bool unsafeCode,
            bool generated)
            : base(document, 
            parent, 
            ElementType.Indexer, 
            "indexer " + declaration.Name, 
            header, 
            attributes,
            declaration, 
            unsafeCode,
            generated)
        {
            Param.AssertNotNull(document, "document");
            Param.AssertNotNull(parent, "parent");
            Param.Ignore(header);
            Param.Ignore(attributes);
            Param.AssertNotNull(declaration, "declaration");
            Param.Ignore(returnType);
            Param.AssertNotNull(parameters, "parameters");
            Param.Ignore(unsafeCode);
            Param.Ignore(generated);

            this.returnType = returnType;
            this.parameters = parameters;

            Debug.Assert(parameters.IsReadOnly, "The parameters collection should be read-only.");

            // Add the qualifications
            this.QualifiedName = CodeParser.AddQualifications(this.parameters, this.QualifiedName);

            // If this is an explicit interface member implementation and our access modifier
            // is currently set to private because we don't have one, then it should be public instead.
            if (this.Declaration.Name.IndexOf(".", StringComparison.Ordinal) > -1 &&
                !this.Declaration.Name.StartsWith("this.", StringComparison.Ordinal))
            {
                this.Declaration.AccessModifierType = AccessModifierType.Public;
            }
        }
Ejemplo n.º 18
0
 /// <summary>
 /// Initializes a new instance of the Namespace class.
 /// </summary>
 /// <param name="document">The document that contains the element.</param>
 /// <param name="parent">The parent of the element.</param>
 /// <param name="header">The Xml header for this element.</param>
 /// <param name="attributes">The list of attributes attached to this element.</param>
 /// <param name="declaration">The declaration code for this element.</param>
 /// <param name="unsafeCode">Indicates whether the element resides within a block of unsafe code.</param>
 /// <param name="generated">Indicates whether the code element was generated or written by hand.</param>
 internal Namespace(
     CsDocument document,
     CsElement parent,
     XmlHeader header,
     ICollection<Attribute> attributes,
     Declaration declaration,
     bool unsafeCode,
     bool generated)
     : base(document,
     parent,
     ElementType.Namespace,
     "namespace " + declaration.Name,
     header,
     attributes,
     declaration,
     unsafeCode,
     generated)
 {
     Param.Ignore(document, parent, header, attributes, declaration, unsafeCode, generated);
 }
Ejemplo n.º 19
0
        /// <summary>
        /// Initializes a new instance of the Accessor class.
        /// </summary>
        /// <param name="document">The documenent that contains the element.</param>
        /// <param name="parent">The parent of the element.</param>
        /// <param name="accessorType">The type of the accessor.</param>
        /// <param name="header">The Xml header for this element.</param>
        /// <param name="attributes">The list of attributes attached to this element.</param>
        /// <param name="declaration">The declaration code for this element.</param>
        /// <param name="unsafeCode">Indicates whether the element resides within a block of unsafe code.</param>
        /// <param name="generated">Indicates whether the code element was generated or written by hand.</param>
        internal Accessor(
            CsDocument document,
            CsElement parent,
            AccessorType accessorType,
            XmlHeader header,
            ICollection<Attribute> attributes,
            Declaration declaration,
            bool unsafeCode,
            bool generated)
            : base(document, 
            parent, 
            ElementType.Accessor, 
            declaration.Name + " accessor",
            header, 
            attributes,
            declaration, 
            unsafeCode,
            generated)
        {
            Param.AssertNotNull(document, "document");
            Param.AssertNotNull(parent, "parent");
            Param.Ignore(accessorType);
            Param.Ignore(header);
            Param.Ignore(attributes);
            Param.AssertNotNull(declaration, "declaration");
            Param.Ignore(unsafeCode);
            Param.Ignore(generated);

            this.accessorType = accessorType;

            // Make sure the type and name match.
            Debug.Assert(
                (accessorType == AccessorType.Get && declaration.Name == "get") ||
                (accessorType == AccessorType.Set && declaration.Name == "set") ||
                (accessorType == AccessorType.Add && declaration.Name == "add") ||
                (accessorType == AccessorType.Remove && declaration.Name == "remove"),
                "The accessor type does not match its name.");

            this.FillDetails(parent);
        }
Ejemplo n.º 20
0
 /// <summary>
 /// Initializes a new instance of the EmptyElement class.
 /// </summary>
 /// <param name="document">The documenent that contains the element.</param>
 /// <param name="parent">The parent of the element.</param>
 /// <param name="declaration">The declaration code for this element.</param>
 /// <param name="unsafeCode">Indicates whether the element resides within a block of unsafe code.</param>
 /// <param name="generated">Indicates whether the code element was generated or written by hand.</param>
 internal EmptyElement(
     CsDocument document,
     CsElement parent,
     Declaration declaration,
     bool unsafeCode,
     bool generated)
     : base(document,
     parent,
     ElementType.EmptyElement,
     Strings.EmptyElement,
     null,
     null,
     declaration,
     unsafeCode,
     generated)
 {
     Param.AssertNotNull(document, "document");
     Param.AssertNotNull(parent, "parent");
     Param.AssertNotNull(declaration, "declaration");
     Param.Ignore(unsafeCode);
     Param.Ignore(generated);
 }
Ejemplo n.º 21
0
 /// <summary>
 /// Initializes a new instance of the Interface class.
 /// </summary>
 /// <param name="document">The document that contains the element.</param>
 /// <param name="parent">The parent of the element.</param>
 /// <param name="header">The Xml header for this element.</param>
 /// <param name="attributes">The list of attributes attached to this element.</param>
 /// <param name="declaration">The declaration code for this element.</param>
 /// <param name="typeConstraints">The list of type constraints on the class, if any.</param>
 /// <param name="unsafeCode">Indicates whether the element resides within a block of unsafe code.</param>
 /// <param name="generated">Indicates whether the code element was generated or written by hand.</param>
 internal Interface(
     CsDocument document,
     CsElement parent,
     XmlHeader header,
     ICollection<Attribute> attributes,
     Declaration declaration,
     ICollection<TypeParameterConstraintClause> typeConstraints,
     bool unsafeCode,
     bool generated)
     : base(document,
     parent,
     ElementType.Interface,
     "interface " + declaration.Name,
     header,
     attributes,
     declaration,
     typeConstraints,
     unsafeCode,
     generated)
 {
     Param.Ignore(document, parent, header, attributes, declaration, typeConstraints, unsafeCode, generated);
 }
Ejemplo n.º 22
0
        /// <summary>
        /// Initializes a new instance of the Property class.
        /// </summary>
        /// <param name="document">The documenent that contains the element.</param>
        /// <param name="parent">The parent of the element.</param>
        /// <param name="header">The Xml header for this element.</param>
        /// <param name="attributes">The list of attributes attached to this element.</param>
        /// <param name="declaration">The declaration code for this element.</param>
        /// <param name="returnType">The property return type.</param>
        /// <param name="unsafeCode">Indicates whether the element resides within a block of unsafe code.</param>
        /// <param name="generated">Indicates whether the code element was generated or written by hand.</param>
        internal Property(
            CsDocument document,
            CsElement parent,
            XmlHeader header,
            ICollection<Attribute> attributes,
            Declaration declaration,
            TypeToken returnType,
            bool unsafeCode,
            bool generated)
            : base(document, 
            parent, 
            ElementType.Property, 
            "property " + declaration.Name, 
            header, 
            attributes,
            declaration, 
            unsafeCode,
            generated)
        {
            Param.AssertNotNull(document, "document");
            Param.AssertNotNull(parent, "parent");
            Param.Ignore(header);
            Param.Ignore(attributes);
            Param.AssertNotNull(declaration, "declaration");
            Param.AssertNotNull(returnType, "returnType");
            Param.Ignore(unsafeCode);
            Param.Ignore(generated);

            this.returnType = returnType;

            // If this is an explicit interface member implementation and our access modifier
            // is currently set to private because we don't have one, then it should be public instead.
            if (this.Declaration.Name.IndexOf(".", StringComparison.Ordinal) > -1 &&
                !this.Declaration.Name.StartsWith("this.", StringComparison.Ordinal))
            {
                this.Declaration.AccessModifierType = AccessModifierType.Public;
            }
        }
Ejemplo n.º 23
0
        /// <summary>
        /// Parses and returns a field.
        /// </summary>
        /// <param name="parent">The parent of the element.</param>
        /// <param name="elementReference">A reference to the element being created.</param>
        /// <param name="unsafeCode">Indicates whether the code is marked as unsafe.</param>
        /// <param name="generated">Indicates whether the code is marked as generated code.</param>
        /// <param name="xmlHeader">The element's documentation header.</param>
        /// <param name="attributes">The attributes on the element.</param>
        /// <returns>Returns the element.</returns>
        private Field ParseField(
            CsElement parent, 
            Reference<ICodePart> elementReference,
            bool unsafeCode, 
            bool generated, 
            XmlHeader xmlHeader, 
            ICollection<Attribute> attributes)
        {
            Param.AssertNotNull(parent, "parent");
            Param.AssertNotNull(elementReference, "elementReference");
            Param.Ignore(unsafeCode);
            Param.Ignore(generated);
            Param.Ignore(xmlHeader);
            Param.Ignore(attributes);

            Node<CsToken> previousTokenNode = this.tokens.Last;

            // Get the modifiers and access.
            AccessModifierType accessModifier = AccessModifierType.Private;
            Dictionary<CsTokenType, CsToken> modifiers = this.GetElementModifiers(elementReference, ref accessModifier, FieldModifiers);

            unsafeCode |= modifiers.ContainsKey(CsTokenType.Unsafe);

            // Get the field type.
            TypeToken fieldType = this.GetTypeToken(elementReference, unsafeCode, true);
            Node<CsToken> fieldTypeNode = this.tokens.InsertLast(fieldType);

            // Get all of the variable declarators.
            IList<VariableDeclaratorExpression> declarators = this.ParseFieldDeclarators(elementReference, unsafeCode, fieldType);

            if (declarators.Count == 0)
            {
                throw this.CreateSyntaxException();
            }

            VariableDeclarationExpression declarationExpression = new VariableDeclarationExpression(
                new CsTokenList(this.tokens, declarators[0].Tokens.First, this.tokens.Last),
                new LiteralExpression(this.tokens, fieldTypeNode),
                declarators);

            // Create the field.
            Node<CsToken> firstTokenNode = previousTokenNode == null ? this.tokens.First : previousTokenNode.Next;
            CsTokenList declarationTokens = new CsTokenList(this.tokens, firstTokenNode, this.tokens.Last);
            Declaration declaration = new Declaration(
                declarationTokens, declarators[0].Identifier.Text, ElementType.Field, accessModifier, modifiers);

            Field field = new Field(
                this.document, parent, xmlHeader, attributes, declaration, fieldType, unsafeCode, generated);
            elementReference.Target = field;

            // Get the trailing semicolon.
            this.tokens.Add(this.GetToken(CsTokenType.Semicolon, SymbolType.Semicolon, elementReference));

            // Create the variable declaration statement and add it to the field.
            field.VariableDeclarationStatement = new VariableDeclarationStatement(
                new CsTokenList(this.tokens, declarators[0].Tokens.First, this.tokens.Last),
                field.Const,
                declarationExpression);

            return field;
        }
Ejemplo n.º 24
0
        /// <summary>
        /// Parses and returns a event.
        /// </summary>
        /// <param name="parent">The parent of the element.</param>
        /// <param name="elementReference">A reference to the element being created.</param>
        /// <param name="unsafeCode">Indicates whether the code is marked as unsafe.</param>
        /// <param name="generated">Indicates whether the code is marked as generated code.</param>
        /// <param name="xmlHeader">The element's documentation header.</param>
        /// <param name="attributes">The attributes on the element.</param>
        /// <returns>Returns the element.</returns>
        private Event ParseEvent(
            CsElement parent,
            Reference<ICodePart> elementReference,
            bool unsafeCode,
            bool generated,
            XmlHeader xmlHeader,
            ICollection<Attribute> attributes)
        {
            Param.AssertNotNull(parent, "parent");
            Param.AssertNotNull(elementReference, "elementReference");
            Param.Ignore(unsafeCode);
            Param.Ignore(generated);
            Param.Ignore(xmlHeader);
            Param.Ignore(attributes);

            Node<CsToken> previousTokenNode = this.tokens.Last;

            // Get the modifiers and access.
            AccessModifierType accessModifier = AccessModifierType.Private;

            // Events within interfaces always have the access of the parent interface.
            Interface parentInterface = parent as Interface;
            if (parentInterface != null)
            {
                accessModifier = parentInterface.AccessModifier;
            }

            // Get declared modifiers.
            Dictionary<CsTokenType, CsToken> modifiers = this.GetElementModifiers(elementReference, ref accessModifier, EventModifiers);

            unsafeCode |= modifiers.ContainsKey(CsTokenType.Unsafe);

            // Get the event keyword.
            this.tokens.Add(this.GetToken(CsTokenType.Event, SymbolType.Event, elementReference));

            // Get the event type.
            TypeToken eventHandlerType = this.GetTypeToken(elementReference, unsafeCode, true);
            this.tokens.Add(eventHandlerType);

            List<EventDeclaratorExpression> declarators = new List<EventDeclaratorExpression>();
            string firstEventName = null;

            while (true)
            {
                Symbol symbol = this.GetNextSymbol(SymbolType.Other, elementReference);

                var declaratorExpressionReference = new Reference<ICodePart>();

                // Get the identifier.
                LiteralExpression identifier = this.GetTypeTokenExpression(declaratorExpressionReference, unsafeCode, false);
                if (identifier == null || identifier.Tokens.First == null)
                {
                    throw new SyntaxException(this.document.SourceCode, symbol.LineNumber);
                }

                if (firstEventName == null)
                {
                    firstEventName = identifier.Token.Text;
                }

                // Get the initializer if it exists.
                Expression initializer = null;

                symbol = this.GetNextSymbol(declaratorExpressionReference);
                if (symbol.SymbolType == SymbolType.Equals)
                {
                    // Add the equals token.
                    this.tokens.Add(this.GetOperatorToken(OperatorType.Equals, declaratorExpressionReference));

                    initializer = this.GetNextExpression(ExpressionPrecedence.None, declaratorExpressionReference, unsafeCode);
                }

                // Create the token list for the declarator.
                CsTokenList partialTokens = new CsTokenList(
                    this.tokens, identifier.Tokens.First, this.tokens.Last);

                // Create and add the declarator.
                var declaratorExpression = new EventDeclaratorExpression(partialTokens, identifier, initializer);

                declaratorExpressionReference.Target = declaratorExpression;
                declarators.Add(declaratorExpression);

                // Now check if the next character is a comma. If so there is another declarator.
                symbol = this.GetNextSymbol(elementReference);
                if (symbol.SymbolType != SymbolType.Comma)
                {
                    // There are no more declarators.
                    break;
                }

                // Add the comma.
                this.tokens.Add(this.GetToken(CsTokenType.Comma, SymbolType.Comma, elementReference));
            }

            // Create the declaration.
            Node<CsToken> firstTokenNode = previousTokenNode == null ? this.tokens.First : previousTokenNode.Next;
            CsTokenList declarationTokens = new CsTokenList(this.tokens, firstTokenNode, this.tokens.Last);
            Declaration declaration = new Declaration(
                declarationTokens, firstEventName, ElementType.Event, accessModifier, modifiers);

            Event @event = new Event(
                this.document, parent, xmlHeader, attributes, declaration, eventHandlerType, declarators.ToArray(), unsafeCode, generated);
            elementReference.Target = @event;

            Symbol s = this.GetNextSymbol(elementReference);

            if (s.SymbolType == SymbolType.Semicolon)
            {
                this.tokens.Add(this.GetToken(CsTokenType.Semicolon, SymbolType.Semicolon, elementReference));
            }
            else
            {
                // Parse the body of the event.
                this.ParseElementContainer(@event, elementReference, null, unsafeCode);
            }

            return @event;
        }
Ejemplo n.º 25
0
        /// <summary>
        /// Parses the contents of the document.
        /// </summary>
        internal void ParseDocument()
        {
            Debug.Assert(this.document == null, "A CodeParser instance may only be used once.");

            // Find the list of symbols in the document.
            List<Symbol> symbolList = this.lexer.GetSymbols(
                this.lexer.SourceCode, this.lexer.SourceCode.Project.Configuration);

            // Create the symbol manager class.
            this.symbols = new SymbolManager(symbolList);

            // Create the document object.
            this.document = new CsDocument(this.lexer.SourceCode, this.parser, this.tokens);

            var documentRootReference = new Reference<ICodePart>();

            // Get the file header if it exists.
            FileHeader fileHeader = this.GetFileHeader(documentRootReference);

            // Let the symbol manager know if this document contains generated code.
            if (fileHeader.Generated)
            {
                this.symbols.IncrementGeneratedCodeBlocks();
            }

            this.document.FileHeader = fileHeader;

            // Create a declaration for the root element.
            Declaration declaration = new Declaration(
                new CsTokenList(this.document.Tokens),
                Strings.Root,
                ElementType.Root,
                AccessModifierType.Public,
                new Dictionary<CsTokenType, CsToken>());

            // Create the root element for the document.
            DocumentRoot root = new DocumentRoot(this.document, declaration, fileHeader.Generated);
            documentRootReference.Target = root;

            // Parse the contents of the document.
            this.ParseElementContainerBody(root, documentRootReference, this.parser.PartialElements, false);

            // Check if there are any tokens in the document.
            if (this.document.Tokens.Count > 0)
            {
                // Fill in the token list for the root element.
                root.Tokens = new CsTokenList(
                    this.document.Tokens, this.document.Tokens.First, this.document.Tokens.Last);

                // Fill in the location for the element.
                root.Location = CsToken.JoinLocations(this.document.Tokens.First, this.document.Tokens.Last);
            }

            // Add the root element to the document.
            this.document.RootElement = root;

            // When in debug mode, ensure that all tokens are correctly mapped to a parent element.
            this.DebugValidateParentReferences();
        }
Ejemplo n.º 26
0
        /// <summary>
        /// Parses and returns a extern alias directive.
        /// </summary>
        /// <param name="parent">The parent of the namespace.</param>
        /// <param name="elementReference">A reference to the element being created.</param>
        /// <param name="generated">Indicates whether the code is marked as generated code.</param>
        /// <returns>Returns the element.</returns>
        private ExternAliasDirective ParseExternAliasDirective(CsElement parent, Reference<ICodePart> elementReference, bool generated)
        {
            Param.AssertNotNull(parent, "parent");
            Param.AssertNotNull(elementReference, "elementReference");
            Param.Ignore(generated);

            // Add the extern token.
            Node<CsToken> firstToken = this.tokens.InsertLast(this.GetToken(CsTokenType.Extern, SymbolType.Extern, elementReference));

            // Add the alias token.
            this.tokens.Add(this.GetToken(CsTokenType.Alias, SymbolType.Other, elementReference));

            // Add the identifier token.
            CsToken identifier = this.GetToken(CsTokenType.Other, SymbolType.Other, elementReference);
            this.tokens.Add(identifier);

            // Create the declaration.
            CsTokenList declarationTokens = new CsTokenList(this.tokens, firstToken, this.tokens.Last);
            Declaration declaration = new Declaration(declarationTokens, identifier.Text, ElementType.ExternAliasDirective, AccessModifierType.Public);

            // Get the closing semicolon.
            this.tokens.Add(this.GetToken(CsTokenType.Semicolon, SymbolType.Semicolon, elementReference));

            // Create the extern alias directive.
            var element = new ExternAliasDirective(this.document, parent, declaration, generated);
            elementReference.Target = element;

            return element;
        }
Ejemplo n.º 27
0
        /// <summary>
        /// Parses and returns a method.
        /// </summary>
        /// <param name="parent">The parent of the element.</param>
        /// <param name="elementReference">A reference to the element being created.</param>
        /// <param name="unsafeCode">Indicates whether the code is marked as unsafe.</param>
        /// <param name="generated">Indicates whether the code is marked as generated code.</param>
        /// <param name="xmlHeader">The element's documentation header.</param>
        /// <param name="attributes">The attributes on the element.</param>
        /// <returns>Returns the element.</returns>
        private Method ParseMethod(
            CsElement parent, 
            Reference<ICodePart> elementReference,
            bool unsafeCode, 
            bool generated, 
            XmlHeader xmlHeader, 
            ICollection<Attribute> attributes)
        {
            Param.AssertNotNull(parent, "parent");
            Param.AssertNotNull(elementReference, "elementReference");
            Param.Ignore(unsafeCode);
            Param.Ignore(generated);
            Param.Ignore(xmlHeader);
            Param.Ignore(attributes);

            Node<CsToken> previousTokenNode = this.tokens.Last;

            // Get the modifiers and access.
            AccessModifierType accessModifier = AccessModifierType.Private;

            // Methods within interfaces always have the access of the parent interface.
            Interface parentInterface = parent as Interface;
            if (parentInterface != null)
            {
                accessModifier = parentInterface.AccessModifier;
            }

            // Get the declared modifiers for the method.
            Dictionary<CsTokenType, CsToken> modifiers = this.GetElementModifiers(elementReference, ref accessModifier, MethodModifiers);

            unsafeCode |= modifiers.ContainsKey(CsTokenType.Unsafe);

            TypeToken returnType = null;
            if (!modifiers.ContainsKey(CsTokenType.Implicit) && !modifiers.ContainsKey(CsTokenType.Explicit))
            {
                // Get the return type.
                returnType = this.GetTypeToken(elementReference, unsafeCode, true);
                this.tokens.Add(returnType);
            }

            // Get the name of the method.
            string methodName = null;

            Symbol symbol = this.GetNextSymbol(elementReference);
            if (symbol.SymbolType == SymbolType.Operator)
            {
                this.tokens.Add(this.GetToken(CsTokenType.Operator, SymbolType.Operator, elementReference));

                // Advance up to the next symbol.
                this.AdvanceToNextCodeSymbol(elementReference);

                // The overloaded item will either be a type or a symbol.
                int endIndex = -1;
                CsToken operatorType = null;

                if (this.HasTypeSignature(1, unsafeCode, out endIndex))
                {
                    // The overloaded item is a type.
                    operatorType = this.GetTypeToken(elementReference, unsafeCode, true);
                }
                else
                {
                    // The overloaded item is a symbol.
                    operatorType = this.ConvertOperatorOverloadSymbol(elementReference);
                }

                this.tokens.Add(operatorType);
                methodName = "operator " + operatorType.Text;
            }
            else
            {
                CsToken name = this.GetElementNameToken(elementReference, unsafeCode);
                methodName = name.Text;
                this.tokens.Add(name);
            }

            // Get the parameter list.
            IList<Parameter> parameters = this.ParseParameterList(
                elementReference, unsafeCode, SymbolType.OpenParenthesis, modifiers.ContainsKey(CsTokenType.Static));

            // Check whether there are any type constraint clauses.
            ICollection<TypeParameterConstraintClause> typeConstraints = null;
            symbol = this.GetNextSymbol(elementReference);
            if (symbol.Text == "where")
            {
                typeConstraints = this.ParseTypeConstraintClauses(elementReference, unsafeCode);
            }

            // Create the declaration.
            Node<CsToken> firstTokenNode = previousTokenNode == null ? this.tokens.First : previousTokenNode.Next;
            CsTokenList declarationTokens = new CsTokenList(this.tokens, firstTokenNode, this.tokens.Last);
            Declaration declaration = new Declaration(
                declarationTokens, methodName, ElementType.Method, accessModifier, modifiers);

            Method method = new Method(
                this.document,
                parent,
                xmlHeader,
                attributes,
                declaration,
                returnType,
                parameters,
                typeConstraints,
                unsafeCode,
                generated);

            elementReference.Target = method;

            // If the element is extern, abstract, or containing within an interface, it will not have a body.
            if (modifiers.ContainsKey(CsTokenType.Abstract) ||
                modifiers.ContainsKey(CsTokenType.Extern) ||
                parent.ElementType == ElementType.Interface)
            {
                // Get the closing semicolon.
                this.tokens.Add(this.GetToken(CsTokenType.Semicolon, SymbolType.Semicolon, elementReference));
            }
            else
            {
                // Get the method body.
                this.ParseStatementContainer(method, true, unsafeCode);
            }

            return method;
        }
Ejemplo n.º 28
0
        /// <summary>
        /// Parses and returns a using directive.
        /// </summary>
        /// <param name="parent">The parent of the namespace.</param>
        /// <param name="elementReference">A reference to the element being created.</param>
        /// <param name="unsafeCode">Indicates whether the code is marked as unsafe.</param>
        /// <param name="generated">Indicates whether the code is marked as generated code.</param>
        /// <returns>Returns the element.</returns>
        private UsingDirective ParseUsingDirective(CsElement parent, Reference<ICodePart> elementReference, bool unsafeCode, bool generated)
        {
            Param.AssertNotNull(parent, "parent");
            Param.AssertNotNull(elementReference, "elementReference");
            Param.Ignore(unsafeCode);
            Param.Ignore(generated);

            // Add the using token.
            Node<CsToken> firstToken = this.tokens.InsertLast(this.GetToken(CsTokenType.Using, SymbolType.Using, elementReference));

            // The next symbol will either be the namespace, or an alias. To determine this, look past this to see if there is an equals sign.
            Symbol peekAhead = this.GetNextSymbol(SymbolType.Other, elementReference);

            int index = this.GetNextCodeSymbolIndex(2);
            if (index == -1)
            {
                throw this.CreateSyntaxException();
            }

            CsToken alias = null;

            peekAhead = this.symbols.Peek(index);
            if (peekAhead.SymbolType == SymbolType.Equals)
            {
                // There is an alias. First collect the alias.
                alias = this.GetToken(CsTokenType.Other, SymbolType.Other, elementReference);
                this.tokens.Add(alias);

                // Next collect the equals sign.
                this.tokens.Add(this.GetOperatorToken(OperatorType.Equals, elementReference));
            }

            // Collect and add the namespace token.
            TypeToken @namespace = this.GetTypeToken(elementReference, unsafeCode, false);
            this.tokens.Add(@namespace);

            // Create the declaration.
            CsTokenList declarationTokens = new CsTokenList(this.tokens, firstToken, this.tokens.Last);
            Declaration declaration = new Declaration(
                declarationTokens,
                alias == null ? @namespace.Text : alias.Text,
                ElementType.UsingDirective,
                AccessModifierType.Public);

            // Get the closing semicolon.
            this.tokens.Add(this.GetToken(CsTokenType.Semicolon, SymbolType.Semicolon, elementReference));

            // Create the using directive.
            var element = new UsingDirective(this.document, parent, declaration, generated, @namespace.Text, alias == null ? null : alias.Text);
            elementReference.Target = element;

            return element;
        }
Ejemplo n.º 29
0
        /// <summary>
        /// Parses and returns a property.
        /// </summary>
        /// <param name="parent">The parent of the element.</param>
        /// <param name="elementReference">A reference to the element being created.</param>
        /// <param name="unsafeCode">Indicates whether the code is marked as unsafe.</param>
        /// <param name="generated">Indicates whether the code is marked as generated code.</param>
        /// <param name="xmlHeader">The element's documentation header.</param>
        /// <param name="attributes">The attributes on the element.</param>
        /// <returns>Returns the element.</returns>
        private Property ParseProperty(
            CsElement parent,
            Reference<ICodePart> elementReference,
            bool unsafeCode,
            bool generated,
            XmlHeader xmlHeader,
            ICollection<Attribute> attributes)
        {
            Param.AssertNotNull(parent, "parent");
            Param.AssertNotNull(elementReference, "elementReference");
            Param.Ignore(unsafeCode);
            Param.Ignore(generated);
            Param.Ignore(xmlHeader);
            Param.Ignore(attributes);

            Node<CsToken> previousTokenNode = this.tokens.Last;

            // Get the modifiers and access.
            AccessModifierType accessModifier = AccessModifierType.Private;

            // Properties within interfaces always have the access of the parent interface.
            Interface parentInterface = parent as Interface;
            if (parentInterface != null)
            {
                accessModifier = parentInterface.AccessModifier;
            }

            // Get declared modifiers.
            Dictionary<CsTokenType, CsToken> modifiers = this.GetElementModifiers(elementReference, ref accessModifier, PropertyModifiers);

            unsafeCode |= modifiers.ContainsKey(CsTokenType.Unsafe);

            // Get the return type.
            TypeToken returnType = this.GetTypeToken(elementReference, unsafeCode, true);
            this.tokens.Add(returnType);

            // Get the name of the property.
            CsToken name = this.GetElementNameToken(elementReference, unsafeCode);
            this.tokens.Add(name);

            // Create the declaration.
            Node<CsToken> firstTokenNode = previousTokenNode == null ? this.tokens.First : previousTokenNode.Next;
            CsTokenList declarationTokens = new CsTokenList(this.tokens, firstTokenNode, this.tokens.Last);
            Declaration declaration = new Declaration(
                declarationTokens, name.Text, ElementType.Property, accessModifier, modifiers);

            Property property = new Property(
                this.document, parent, xmlHeader, attributes, declaration, returnType, unsafeCode, generated);
            elementReference.Target = property;

            // Parse the body of the property.
            this.ParseElementContainer(property, elementReference, null, unsafeCode);

            return property;
        }
Ejemplo n.º 30
0
        /// <summary>
        /// Parses and returns a namespace.
        /// </summary>
        /// <param name="parent">The parent of the namespace.</param>
        /// <param name="elementReference">A reference to the element being created.</param>
        /// <param name="partialElements">The collection of partial elements found while parsing the files.</param>
        /// <param name="unsafeCode">Indicates whether the code is marked as unsafe.</param>
        /// <param name="generated">Indicates whether the code is marked as generated code.</param>
        /// <param name="xmlHeader">The element's documentation header.</param>
        /// <param name="attributes">The attributes on the element.</param>
        /// <returns>Returns the element.</returns>
        private Namespace ParseNamespace(
            CsElement parent,
            Reference<ICodePart> elementReference,
            Dictionary<string, List<CsElement>> partialElements,
            bool unsafeCode,
            bool generated,
            XmlHeader xmlHeader,
            ICollection<Attribute> attributes)
        {
            Param.AssertNotNull(parent, "parent");
            Param.AssertNotNull(elementReference, "elementReference");
            Param.AssertNotNull(partialElements, "partialElements");
            Param.Ignore(unsafeCode);
            Param.Ignore(generated);
            Param.Ignore(xmlHeader);
            Param.Ignore(attributes);

            // Add the namespace token.
            Node<CsToken> firstToken = this.tokens.InsertLast(this.GetToken(CsTokenType.Namespace, SymbolType.Namespace, elementReference));

            // Add the namespace name token.
            CsToken name = this.GetElementNameToken(elementReference, unsafeCode);
            this.tokens.Add(name);

            // Create the declaration.
            CsTokenList declarationTokens = new CsTokenList(this.tokens, firstToken, this.tokens.Last);
            Declaration declaration = new Declaration(declarationTokens, name.Text, ElementType.Namespace, AccessModifierType.Public);

            // Create the namespace.
            Namespace @namespace = new Namespace(this.document, parent, xmlHeader, attributes, declaration, unsafeCode, generated);
            elementReference.Target = @namespace;

            // Parse the body of the namespace.
            this.ParseElementContainer(@namespace, elementReference, partialElements, unsafeCode);

            return @namespace;
        }