private static void RenderClass(StringBuilder stringBuilder, TypeDescription type)
        {
            #region awesomesauce
            var        stereotype = "entity";
            CustomSpot?customSpot = null;

            if (type.IsClass() && type.Namespace.Split('.').Contains("ValueObjects"))
            {
                stereotype = "value object";
                customSpot = new CustomSpot('O', "LightBlue");
            }
            else if (type.IsClass() && type.ImplementsTypeStartsWith("Pitstop.WorkshopManagementAPI.Domain.Core.AggregateRoot<"))
            {
                stereotype = "root";
                customSpot = new CustomSpot('R', "LightGreen");
            }
            #endregion

            stringBuilder.ClassStart(type.Name, displayName: type.Name.ToSentenceCase(), stereotype: stereotype, customSpot: customSpot);

            foreach (var property in type.Properties.Where(p => !p.IsPrivate()).OrderBy(p => p.Name))
            {
                stringBuilder.ClassMember($"{property.Name.ToSentenceCase()}: {property.Type.ForDiagram()}", property.IsStatic(), visibility: property.ToUmlVisibility());
            }

            foreach (var method in type.Methods.Where(m => !m.IsPrivate() && !m.IsOverride()))
            {
                var parameterList = method.Parameters.Select(p => p.Name.ToSentenceCase()).Aggregate("", (s, a) => a + ", " + s, s => s.Trim(',', ' '));
                stringBuilder.ClassMember($"{method.Name} ({parameterList})", method.IsStatic(), visibility: method.ToUmlVisibility());
            }

            stringBuilder.ClassEnd();


            foreach (var propertyDescription in type.Properties)
            {
                var property = Types.FirstOrDefault(t => string.Equals(t.FullName, propertyDescription.Type) || (propertyDescription.Type.IsEnumerable() && string.Equals(t.FullName, propertyDescription.Type.GenericTypes().First())));
                if (property != null)
                {
                    RenderClass(stringBuilder, property);

                    // Relation
                    stringBuilder.Append($"{type.Name} -- {property.Name}");
                    if (propertyDescription.Type.IsEnumerable())
                    {
                        stringBuilder.Append(" : 1..*");
                    }
                    stringBuilder.AppendLine();
                }
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Renders the beginning of a class.
        /// </summary>
        /// <param name="name">The name of the class. The name can't contain spaces.</param>
        /// <param name="displayName">Optional display name. The display name can contain spaces.</param>
        /// <param name="visibility">Optional visibility.</param>
        /// <param name="isAbstract">Indicates wheter the class is abstract. Default <c>false</c>.</param>
        /// <param name="generics">Optional class extension.</param>
        /// <param name="stereotype">Optional stereo type.</param>
        /// <param name="customSpot">Optional custom spot.</param>
        /// <param name="tag">Optional tag.</param>
        /// <param name="url">Optional URL.</param>
        /// <param name="backgroundColor">Optional background color.</param>
        /// <param name="lineColor">Optional line color.</param>
        /// <param name="lineStyle">Optional line style.</param>
        /// <param name="extends">Optional extends.</param>
        /// <param name="implements">Optional implements.</param>
        /// <exception cref="ArgumentNullException">Thrown when <paramref name="stringBuilder"/> is <c>null</c>.</exception>
        /// <exception cref="ArgumentException">Thrown when <paramref name="name"/> is <c>null</c>, empty of only white space.</exception>
        public static void ClassStart(this StringBuilder stringBuilder, string name, string displayName = default, VisibilityModifier visibility = VisibilityModifier.None, bool isAbstract = false, string generics = default, string stereotype = default, CustomSpot customSpot = default, string tag = default, Uri url = default, Color backgroundColor = default, Color lineColor = default, LineStyle lineStyle = LineStyle.None, string[] extends = default, string[] implements = default)
        {
            if (stringBuilder is null)
            {
                throw new ArgumentNullException(nameof(stringBuilder));
            }

            stringBuilder.VisibilityChar(visibility);
            stringBuilder.Class(name, displayName, isAbstract, generics, stereotype, customSpot, tag, url, backgroundColor, lineColor, lineStyle, extends, implements);
            stringBuilder.TrimEnd();
            stringBuilder.ClassBaseStart();
        }
Exemplo n.º 3
0
        /// <summary>
        /// Renders a class.
        /// </summary>
        /// <param name="name">The name of the class. The name can't contain spaces.</param>
        /// <param name="displayName">Optional display name. The display name can contain spaces.</param>
        /// <param name="isAbstract">Indicates wheter the class is abstract. Default <c>false</c>.</param>
        /// <param name="generics">Optional class extension.</param>
        /// <param name="stereotype">Optional stereo type.</param>
        /// <param name="customSpot">Optional custom spot.</param>
        /// <param name="tag">Optional tag.</param>
        /// <param name="url">Optional URL.</param>
        /// <param name="backgroundColor">Optional background color.</param>
        /// <param name="lineColor">Optional line color.</param>
        /// <param name="lineStyle">Optional line style.</param>
        /// <param name="extends">Optional extends.</param>
        /// <param name="implements">Optional implementations.</param>
        /// <exception cref="ArgumentNullException">Thrown when <paramref name="stringBuilder"/> is <c>null</c>.</exception>
        /// <exception cref="ArgumentException">Thrown when <paramref name="name"/> is <c>null</c>, empty of only white space.</exception>
        public static void Class(this StringBuilder stringBuilder, string name, string displayName = default, bool isAbstract = false, string generics = default, string stereotype = default, CustomSpot customSpot = default, string tag = default, Uri url = default, Color backgroundColor = default, Color lineColor = default, LineStyle lineStyle = LineStyle.None, string[] extends = default, string[] implements = default)
        {
            if (stringBuilder is null)
            {
                throw new ArgumentNullException(nameof(stringBuilder));
            }

            if (isAbstract)
            {
                stringBuilder.Append(Constant.Abstract);
                stringBuilder.Append(Constant.Space);
            }

            stringBuilder.ClassBase(ClassType.Class, name, displayName, generics, stereotype, customSpot, tag, url, backgroundColor, lineColor, lineStyle, extends, implements);
            stringBuilder.AppendNewLine();
        }
Exemplo n.º 4
0
        /// <summary>
        /// Base for rendering a class.
        /// </summary>
        /// <param name="name">The name of the namespace. The name can't contain spaces.</param>
        /// <param name="displayName">Optional display name. The display name can contain spaces.</param>
        /// <param name="generics">Optional class extension.</param>
        /// <param name="stereotype">Optional stereo type.</param>
        /// <param name="customSpot">Optional custom spot.</param>
        /// <param name="tag">Optional tag.</param>
        /// <param name="url">Optional URL.</param>
        /// <param name="backgroundColor">Optional background color.</param>
        /// <param name="lineColor">Optional line color.</param>
        /// <param name="lineStyle">Optional line style.</param>
        /// <param name="extends">Optional extends.</param>
        /// <param name="implements">Optional implementations.</param>
        /// <exception cref="ArgumentException">Thrown when <paramref name="name"/> is <c>null</c>, empty of only white space.</exception>
        internal static void ClassBase(this StringBuilder stringBuilder, ClassType type, string name, string displayName, string generics, string stereotype, CustomSpot customSpot, string tag, Uri url, Color backgroundColor, Color lineColor, LineStyle lineStyle, string[] extends, string[] implements)
        {
            if (string.IsNullOrWhiteSpace(name))
            {
                throw new ArgumentException("A non-empty value should be provided", nameof(name));
            }

            stringBuilder.Append(type.ToString().ToLowerInvariant());
            stringBuilder.Append(Constant.Space);

            if (!(displayName is null))
            {
                stringBuilder.Append(Constant.Quote);
                stringBuilder.Append(displayName);
                stringBuilder.Append(Constant.Quote);
                stringBuilder.Append(Constant.Space);
                stringBuilder.Append(Constant.As);
                stringBuilder.Append(Constant.Space);
            }

            stringBuilder.Append(name);

            if (!(generics is null))
            {
                stringBuilder.Append(Constant.GenericsStart);
                stringBuilder.Append(generics);
                stringBuilder.Append(Constant.GenericsEnd);
            }

            if (!(stereotype is null))
            {
                stringBuilder.Append(Constant.Space);
                stringBuilder.StereoType(stereotype, customSpot);
            }

            if (!(tag is null))
            {
                stringBuilder.Append(Constant.Space);
                stringBuilder.Append(Constant.TagPrefix);
                stringBuilder.Append(tag);
            }

            if (!(url is null))
            {
                stringBuilder.Append(Constant.Space);
                stringBuilder.Append(Constant.UrlStart);
                stringBuilder.Append(url);
                stringBuilder.Append(Constant.UrlEnd);
            }

            if (!(backgroundColor is null))
            {
                stringBuilder.Append(Constant.Space);
                stringBuilder.Append(backgroundColor);
            }

            if (!(lineColor is null) || lineStyle != LineStyle.None)
            {
                stringBuilder.Append(Constant.Space);
                stringBuilder.Append(Constant.ColorPrefix);
                stringBuilder.Append(Constant.ColorPrefix);

                if (lineStyle > LineStyle.None)
                {
                    stringBuilder.Append(Constant.BorderStyleStart);
                    stringBuilder.Append(lineStyle.ToString().ToLowerInvariant());
                    stringBuilder.Append(Constant.BorderStyleEnd);
                }

                if (!(lineColor is null))
                {
                    stringBuilder.Append(lineColor.ToString().TrimStart(Constant.ColorPrefix));
                }
            }

            if (!(extends is null) && extends.Length > 0)
            {
                stringBuilder.Append(Constant.Space);
                stringBuilder.Append(Constant.Extends);
                stringBuilder.Append(Constant.Space);
                stringBuilder.AppendJoin(',', extends);
            }

            if (!(implements is null) && implements.Length > 0)
            {
                stringBuilder.Append(Constant.Space);
                stringBuilder.Append(Constant.Implements);
                stringBuilder.Append(Constant.Space);
                stringBuilder.AppendJoin(',', implements);
            }
        }