Ejemplo n.º 1
0
        public string GenerateDocumentation(ColumnDescriptor rootColumn)
        {
            StringWriter             stringWriter   = new StringWriter();
            var                      processedTypes = new HashSet <Type>();
            Queue <ColumnDescriptor> columnQueue    = new Queue <ColumnDescriptor>();

            columnQueue.Enqueue(rootColumn);
            while (columnQueue.Any())
            {
                ColumnDescriptor columnDescriptor = columnQueue.Dequeue();
                var rowType = DataSchema.GetWrappedValueType(columnDescriptor.PropertyType);
                if (processedTypes.Contains(rowType))
                {
                    continue;
                }
                if (!IsNestedColumn(columnDescriptor))
                {
                    processedTypes.Add(rowType);
                    if (null == DataSchema.GetCollectionInfo(rowType) && !IsScalar(rowType))
                    {
                        stringWriter.WriteLine("<div class=\"RowType\" id=\"" + rowType.FullName + "\">" + HtmlEncode(rowType.Name) + "</div>");
                        stringWriter.WriteLine(GetDocumentation(columnDescriptor));
                    }
                }
                foreach (var child in GetChildColumns(columnDescriptor))
                {
                    columnQueue.Enqueue(child);
                }
            }
            return(stringWriter.ToString());
        }
Ejemplo n.º 2
0
        private string GetHtmlForType(Type type)
        {
            var  collectionInfo = DataSchema.GetCollectionInfo(type);
            Type elementType;

            if (null == collectionInfo)
            {
                elementType = DataSchema.GetWrappedValueType(type);
            }
            else
            {
                elementType = collectionInfo.ElementType;
                if (collectionInfo.IsDictionary && elementType.IsGenericType &&
                    elementType.GetGenericTypeDefinition() == typeof(KeyValuePair <,>))
                {
                    elementType = elementType.GetGenericArguments()[1];
                }
            }
            bool   elementTypeIsScalar = IsScalar(elementType);
            string strElement;

            if (elementTypeIsScalar)
            {
                strElement = HtmlEncode(GetTypeName(elementType));
            }
            else
            {
                strElement = "<a href=\"#" + elementType.FullName + "\">" + HtmlEncode(GetTypeName(elementType)) + "</a>";
            }
            if (null == collectionInfo)
            {
                return(strElement);
            }
            if (collectionInfo.IsDictionary)
            {
                if (collectionInfo.ElementType.IsGenericType &&
                    collectionInfo.ElementType.GetGenericTypeDefinition() == typeof(KeyValuePair <,>))
                {
                    return(string.Format(Resources.DocumentationGenerator_GetHtmlForType_Map_of__0__to__1_,
                                         HtmlEncode(GetTypeName(collectionInfo.ElementType.GetGenericArguments()[0])),
                                         strElement));
                }
                return(string.Format(Resources.DocumentationGenerator_GetHtmlForType_Map_of__0_, strElement));
            }
            else
            {
                return(string.Format(Resources.DocumentationGenerator_GetHtmlForType_List_of__0_, strElement));
            }
        }
Ejemplo n.º 3
0
        public string GenerateDocumentation(ColumnDescriptor rootColumn)
        {
            StringWriter             stringWriter   = new StringWriter();
            var                      processedTypes = new HashSet <Type>();
            Queue <ColumnDescriptor> columnQueue    = new Queue <ColumnDescriptor>();

            columnQueue.Enqueue(rootColumn);
            while (columnQueue.Any())
            {
                ColumnDescriptor columnDescriptor = columnQueue.Dequeue();
                var rowType = DataSchema.GetWrappedValueType(columnDescriptor.PropertyType);
                if (processedTypes.Contains(rowType))
                {
                    continue;
                }
                if (!IsNestedColumn(columnDescriptor))
                {
                    processedTypes.Add(rowType);
                    var collectionInfo = DataSchema.GetCollectionInfo(rowType);
                    if (collectionInfo != null)
                    {
                        columnQueue.Enqueue(ColumnDescriptor.RootColumn(rootColumn.DataSchema, collectionInfo.ElementType, rootColumn.UiMode));
                    }
                    else if (!IsScalar(rowType))
                    {
                        stringWriter.WriteLine("<div id=\"" + HtmlEncode(rowType.FullName) + "\"><span class=\"RowType\">" +
                                               HtmlEncode(GetTypeName(rowType)) + "</span>");
                        string description = GetTypeDescription(rowType);
                        if (!string.IsNullOrEmpty(description))
                        {
                            stringWriter.WriteLine("<span class=\"Description\">" + HtmlEncode(description) + "</span>");
                        }
                        stringWriter.WriteLine("</div>");
                        stringWriter.WriteLine(GetDocumentation(columnDescriptor));
                    }
                }
                foreach (var child in GetChildColumns(columnDescriptor))
                {
                    if (!IncludeHidden && DataSchema.IsHidden(child))
                    {
                        continue;
                    }
                    columnQueue.Enqueue(child);
                }
            }
            return(stringWriter.ToString());
        }