Exemple #1
0
        public TypeDefinition Merge(TypeDefinition otherType)
        {
            if (null == otherType)
            {
                throw new ArgumentNullException("otherType");
            }
            TypeDefinition combinedType = Merge <TypeDefinition>(this, otherType);

            combinedType.Kind      = this.Kind;
            combinedType.IsPartial = this.IsPartial;
            TypeDefinition typeWithParents = null;

            if (this.ParentTypeNames.Count > 0)
            {
                typeWithParents = this;
            }
            else if (otherType.ParentTypeNames.Count > 0)
            {
                typeWithParents = otherType;
            }

            if (null != typeWithParents)
            {
                foreach (var parentType in typeWithParents.ParentTypeNames)
                {
                    combinedType.AddParentType(parentType);
                }
            }

            return(combinedType);
        }
        /// <summary>
        /// Parses an element corresponding to a type definition and creates a TypeDefinition object
        /// </summary>
        /// <param name="typeElement">The type element to parse. This must be one of the elements contained in TypeElementNames.</param>
        /// <param name="context">The parser context</param>
        /// <returns>A TypeDefinition parsed from the element</returns>
        protected override TypeDefinition ParseTypeElement(XElement typeElement, ParserContext context)
        {
            if (null == typeElement)
            {
                throw new ArgumentNullException("typeElement");
            }
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

            var typeDefinition = new TypeDefinition()
            {
                Accessibility       = GetAccessModifierForType(typeElement),
                Kind                = XNameMaps.GetKindForXElement(typeElement),
                Name                = GetNameForType(typeElement),
                ProgrammingLanguage = ParserLanguage
            };

            typeDefinition.AddLocation(context.CreateLocation(typeElement, ContainerIsReference(typeElement)));

            foreach (var parentTypeElement in GetParentTypeUseElements(typeElement))
            {
                var parentTypeUse = ParseTypeUseElement(parentTypeElement, context);
                typeDefinition.AddParentType(parentTypeUse);
            }

            var typeBlock = typeElement.Element(SRC.Block);

            if (typeBlock != null)
            {
                foreach (var child in typeBlock.Elements())
                {
                    if (child.Name == SRC.Private)
                    {
                        typeDefinition.AddChildStatements(ParseClassChildren(child, context, AccessModifier.Private));
                    }
                    else if (child.Name == SRC.Protected)
                    {
                        typeDefinition.AddChildStatements(ParseClassChildren(child, context, AccessModifier.Protected));
                    }
                    else if (child.Name == SRC.Public)
                    {
                        typeDefinition.AddChildStatements(ParseClassChildren(child, context, AccessModifier.Public));
                    }
                    else
                    {
                        typeDefinition.AddChildStatement(ParseStatement(child, context));
                    }
                }
            }


            return(typeDefinition);
        }
        /// <summary>
        /// Parses an element corresponding to a type definition and creates a TypeDefinition object 
        /// </summary>
        /// <param name="typeElement">The type element to parse. This must be one of the elements contained in TypeElementNames.</param>
        /// <param name="context">The parser context</param>
        /// <returns>A TypeDefinition parsed from the element</returns>
        protected override TypeDefinition ParseTypeElement(XElement typeElement, ParserContext context) {
            if(null == typeElement)
                throw new ArgumentNullException("typeElement");
            if(context == null)
                throw new ArgumentNullException("context");

            var typeDefinition = new TypeDefinition() {
                Accessibility = GetAccessModifierForType(typeElement),
                Kind = XNameMaps.GetKindForXElement(typeElement),
                Name = GetNameForType(typeElement),
                ProgrammingLanguage = ParserLanguage
            };
            typeDefinition.AddLocation(context.CreateLocation(typeElement, ContainerIsReference(typeElement)));

            foreach(var parentTypeElement in GetParentTypeUseElements(typeElement)) {
                var parentTypeUse = ParseTypeUseElement(parentTypeElement, context);
                typeDefinition.AddParentType(parentTypeUse);
            }

            var typeBlock = typeElement.Element(SRC.Block);
            if(typeBlock != null) {
                foreach(var child in typeBlock.Elements()) {
                    if(child.Name == SRC.Private) {
                        typeDefinition.AddChildStatements(ParseClassChildren(child, context, AccessModifier.Private));
                    } else if(child.Name == SRC.Protected) {
                        typeDefinition.AddChildStatements(ParseClassChildren(child, context, AccessModifier.Protected));
                    } else if(child.Name == SRC.Public) {
                        typeDefinition.AddChildStatements(ParseClassChildren(child, context, AccessModifier.Public));
                    } else {
                        typeDefinition.AddChildStatement(ParseStatement(child, context));
                    }
                }
            }


            return typeDefinition;
        }
        /// <summary>
        /// Parses a type element and pushes a it onto the <paramref name="context"/>.
        /// </summary>
        /// <param name="typeElement">the type element to parse</param>
        /// <param name="context">The parser context</param>
        public virtual void ParseTypeElement(XElement typeElement, ParserContext context) {
            if(null == typeElement) throw new ArgumentNullException("typeElement");

            var typeDefinition = new TypeDefinition() {
                Accessibility = GetAccessModifierForType(typeElement),
                Kind = XNameMaps.GetKindForXElement(typeElement),
                Name = GetNameForType(typeElement),
            };
            foreach(var parentTypeElement in GetParentTypeUseElements(typeElement)) {
                var parentTypeUse = ParseTypeUseElement(parentTypeElement, context);
                typeDefinition.AddParentType(parentTypeUse);
            }
            context.Push(typeDefinition);
        }