示例#1
0
        public void Generate(CSharpWriter stream, Nodes.UmlEnumerationNode enumNode)
        {
            stream.WriteSummary(enumNode.Documentation);
            if (enumNode.Tags.Any(r => r.Name == "Flags"))
            {
                stream.WriteCodeLine("[Flags]");
            }
            stream.WriteCodeLine($"{CSharpHelper.ConvertVisibility(enumNode.Visibility)} enum {enumNode.Name}");
            using (var enumScope = stream.CreateIndentScope())
            {
                var litCount = enumNode.Literals.Count;
                for (var i = 0; i < litCount; i++)
                {
                    var lit          = enumNode.Literals[i];
                    var litDelimiter = litCount > i + 1 ? "," : string.Empty;

                    stream.WriteSummary(lit.Documentation);
                    var valueTag = lit.Tags.FirstOrDefault(r => r.Name == "Value");
                    if (valueTag != null)
                    {
                        stream.WriteCodeLine($"{lit.Name} = {valueTag.Value}{litDelimiter}");
                        stream.WriteLine(); // This is only for beauty output
                    }
                    else
                    {
                        stream.WriteCodeLine($"{lit.Name}{litDelimiter}");
                    }
                }
            }
        }
示例#2
0
 public void GenerateForInterface(CSharpWriter stream, Nodes.UmlAttributeNode attributeNode)
 {
     stream.WriteSummary(attributeNode.Documentation);
     if (attributeNode.IsReadOnly)
     {
         stream.WriteCodeLine($"{CSharpHelper.ResolveType(attributeNode)} {attributeNode.Name} {{ get; }}");
     }
     else
     {
         stream.WriteCodeLine($"{CSharpHelper.ResolveType(attributeNode)} {attributeNode.Name} {{ get; set; }}");
     }
 }
示例#3
0
        internal void GenerateForClass(CSharpWriter stream, UmlAssociationEndNode associationEndNode)
        {
            stream.WriteSummary(associationEndNode.Documentation);
            var visibility  = CSharpHelper.ConvertVisibility(associationEndNode.Visibility, true, true);
            var opositeType = CSharpHelper.ResolveType(associationEndNode.OpositeEnd);

            if (associationEndNode.IsReadOnly)
            {
                stream.WriteCodeLine($"{visibility} IEnumerable<{opositeType}> {associationEndNode.Name} {{ get; private set; }}");
            }
            else
            {
                stream.WriteCodeLine($"{visibility} IEnumerable<{opositeType}> {associationEndNode.Name} {{ get; set; }}");
            }
        }
示例#4
0
        internal void GenerateForClass(CSharpWriter stream, UmlAttributeNode attributeNode)
        {
            stream.WriteSummary(attributeNode.Documentation);
            var visibility = CSharpHelper.ConvertVisibility(attributeNode.Visibility, true, true);
            var attrType   = CSharpHelper.ResolveType(attributeNode);

            if (attributeNode.IsReadOnly)
            {
                stream.WriteCodeLine($"{visibility} {attrType} {attributeNode.Name} {{ get; private set; }}");
            }
            else
            {
                stream.WriteCodeLine($"{visibility} {attrType} {attributeNode.Name} {{ get; set; }}");
            }
        }
示例#5
0
        public void Generate(CSharpWriter stream, Nodes.UmlInterfaceNode interfaceNode)
        {
            stream.WriteSummary(interfaceNode.Documentation);
            var baseNames       = interfaceNode.GetGeneralBaseNodes().Select(r => r.Name).ToArray();
            var baseDeclaration = baseNames.Length == 0 ? string.Empty : $" : {string.Join(", ", baseNames)}";

            stream.WriteCodeLine($"{CSharpHelper.ConvertVisibility(interfaceNode.Visibility)} interface {interfaceNode.Name}{baseDeclaration}");
            using (var interScope = stream.CreateIndentScope())
            {
                if (interfaceNode.Attributes != null)
                {
                    for (var attrIndex = 0; attrIndex < interfaceNode.Attributes.Count; attrIndex++)
                    {
                        if (attrIndex > 0)
                        {
                            stream.WriteLine();
                        }
                        WriteAttributeAsProperty(stream, interfaceNode.Attributes[attrIndex]);
                    }
                }
            }
        }
示例#6
0
        public void Generate(CSharpWriter stream, Nodes.UmlClassNode classNode, bool asPartial = true)
        {
            stream.WriteSummary(classNode.Documentation);
            var baseClass      = classNode.BaseClass;
            var implInterfaces = classNode.GetInterfaceRealizationNodes().ToList();

            var baseNames = new List <string>();

            if (baseClass != null)
            {
                baseNames.Add(baseClass.Name);
            }
            baseNames.AddRange(implInterfaces.Select(r => r.Name));

            var baseDeclaration = baseNames.Count == 0 ? string.Empty : $" : {string.Join(", ", baseNames)}";

            var partialDefinition = asPartial ? " partial" : string.Empty;

            stream.WriteCodeLine($"{CSharpHelper.ConvertVisibility(classNode.Visibility)}{partialDefinition} class {classNode.Name}{baseDeclaration}");
            using (var interScope = stream.CreateIndentScope())
            {
                var autoInitializeConstructorNodes = new List <INode>();

                if (classNode.Attributes != null)
                {
                    for (var attrIndex = 0; attrIndex < classNode.Attributes.Count; attrIndex++)
                    {
                        if (attrIndex > 0)
                        {
                            stream.WriteLine();
                        }
                        var attr = classNode.Attributes[attrIndex];
                        WriteAttributeAsProperty(stream, attr);
                        if (attr.IsReadOnly)
                        {
                            autoInitializeConstructorNodes.Add(attr);
                        }
                    }

                    foreach (var assocEndNode in classNode.GetAssociationEnds(false, true))
                    {
                        stream.WriteLine();
                        WriteAssociationEndProperty(stream, assocEndNode);
                        if (assocEndNode.IsReadOnly)
                        {
                            autoInitializeConstructorNodes.Add(assocEndNode);
                        }
                    }
                }
                if (autoInitializeConstructorNodes.Any())
                {
                    stream.WriteLine();
                    stream.WriteCodeLine($"public {classNode.Name}()");
                    using (var ctorScope = stream.CreateIndentScope())
                    {
                        foreach (var autoNode in autoInitializeConstructorNodes)
                        {
                            stream.WriteCodeLine($"{autoNode.Name} = default;");
                        }
                    }
                }
            }
        }