예제 #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 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]);
                    }
                }
            }
        }
예제 #3
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;");
                        }
                    }
                }
            }
        }