Example #1
0
        protected virtual Enum ParseEnum(Type type)
        {
            var enumNames = type.GetEnumNames();
            //TODO: support for enums other than int
            var enumValues = type.GetEnumValues().Cast <int>().Select(x => x.ToString()).ToArray();

            var zipped = enumNames.Zip(enumValues);

            IDictionary <string, string> values = zipped
                                                  .ToDictionary <(string, string), string, string>(pair => pair.Item1, pair => pair.Item2);

            AccessModifier accessModifier = ReflectionUtility.GetAccessModifier(type);

            var parameters = new EnumParameters
            {
                Name           = type.Name,
                Values         = values,
                AccessModifier = accessModifier,
                FullName       = type.FullName,
                RawType        = type
            };

            var @enum = new Enum(parameters);

            return(@enum);
        }
Example #2
0
        public void WriteToFile(string filePath)
        {
            File.WriteAllText(filePath, $"# Cool file {Environment.NewLine}");

            foreach (TopLevelType type in Types)
            {
                string section = type switch
                {
                    Class @class => DocumentClass(@class),
                    Enum @enum => DocumentEnum(@enum),
                    Interface @interface => DocumentInterface(@interface),
                    Structure structure => DocumentStructure(structure),
                    _ => throw new NotSupportedException(
                              $"Type `{type.GetType().FullName}` is not supported with {nameof(MarkdownFrontend)}")
                };

                File.AppendAllText(filePath, section + Environment.NewLine);
            }
        }
Example #3
0
        private string DocumentEnum(Enum @enum)
        {
            var sb = new StringBuilder();

            sb.AppendLine($"## {@enum.Name}");

            // Summary
            sb.AppendLine("Overview");
            sb.AppendLine("```csharp");
            sb.AppendLine($"{PrintAccessModifier(@enum.AccessModifier)} enum {@enum.Name}");
            sb.AppendLine("{");

            foreach ((string name, string value) in @enum.Values)
            {
                sb.AppendLine($"    {name} = {value},");
            }

            sb.AppendLine("}");
            sb.AppendLine("```");
            sb.AppendLine();

            return(sb.ToString());
        }