예제 #1
0
        public TextWriter AddCodeSnippet(string language)
        {
            var writer = new CodeSnippetMarkdownWriter(language);

            _subWriters.Add(writer);
            return(writer);
        }
예제 #2
0
        private static CodeSnippetMarkdownWriter CreateTypeDefinition(Type type)
        {
            var typeDefinitionWriter = new CodeSnippetMarkdownWriter("C#");
            var attributes           = type.GetCustomAttributes(false);

            foreach (var attribute in attributes)
            {
                var attributeType = attribute.GetType();
                var attributeName = attributeType.FullName;
                if (attributeName.EndsWith("Attribute"))
                {
                    attributeName = attributeName.Substring(0, attributeName.Length - 9);
                }
                typeDefinitionWriter.WriteLine("[{0}]", attributeName);
            }

            if (type.IsPublic)
            {
                typeDefinitionWriter.Write("public ");
            }

            if (type.IsSealed && !type.IsEnum)
            {
                typeDefinitionWriter.Write("sealed ");
            }
            else if (type.IsAbstract)
            {
                typeDefinitionWriter.Write("abstract ");
            }

            if (type.IsClass)
            {
                typeDefinitionWriter.Write("class ");
            }
            else if (type.IsEnum)
            {
                typeDefinitionWriter.Write("enum ");
            }
            else
            {
                typeDefinitionWriter.Write("struct ");
            }

            typeDefinitionWriter.Write("{0} ", type.Name);

            var @base = type.BaseType;

            if (type != typeof(Object))
            {
                typeDefinitionWriter.Write(": {0}", @base);
            }
            return(typeDefinitionWriter);
        }