示例#1
0
            /// <summary>
            /// Writes fielddef as JSON. Do not call this method directly, instead call rowset.ToJSON() or use JSONWriter class
            /// </summary>
            public void WriteAsJSON(System.IO.TextWriter wri, int nestingLevel, JSONWritingOptions options = null)
            {
                var attr = this[null];

                if (attr != null && attr.NonUI)
                {
                    wri.Write("{}");
                    return;  //nothing to write for NONUI
                }

                bool   typeIsNullable;
                string tp = JSONMappings.MapCLRTypeToJSON(m_Type, out typeIsNullable);

                var map = new Dictionary <string, object>
                {
                    { "Name", m_Name },
                    { "Order", m_Order },
                    { "Type", tp },
                    { "Nullable", typeIsNullable }
                };

                if (attr != null)
                {
                    map.Add("IsKey", attr.Key);
                    map.Add("IsRequired", attr.Required);
                    map.Add("Visible", attr.Visible);
                    if (attr.Default != null)
                    {
                        map.Add("Default", attr.Default);
                    }
                    if (attr.CharCase != CharCase.AsIs)
                    {
                        map.Add("CharCase", attr.CharCase);
                    }
                    if (attr.Kind != DataKind.Text)
                    {
                        map.Add("Kind", attr.Kind);
                    }
                    if (attr.MinLength != 0)
                    {
                        map.Add("MinLen", attr.MinLength);
                    }
                    if (attr.MaxLength != 0)
                    {
                        map.Add("MaxLen", attr.MaxLength);
                    }
                    if (attr.Min != null)
                    {
                        map.Add("Min", attr.Min);
                    }
                    if (attr.Max != null)
                    {
                        map.Add("Max", attr.Max);
                    }
                    if (attr.ValueList != null)
                    {
                        map.Add("ValueList", attr.ValueList);
                    }
                    if (attr.Description != null)
                    {
                        map.Add("Description", attr.Description);
                    }
                    //metadata content is in the internal format and not dumped
                }

                JSONWriter.WriteMap(wri, map, nestingLevel, options);
            }
示例#2
0
            /// <summary>
            /// Writes fielddef as JSON. Do not call this method directly, instead call rowset.ToJSON() or use JSONWriter class
            /// </summary>
            void IJsonWritable.WriteAsJson(System.IO.TextWriter wri, int nestingLevel, JsonWritingOptions options)
            {
                var attr = this[null];

                if (attr != null && attr.NonUI)
                {
                    wri.Write("{}");
                    return;//nothing to write for NONUI
                }

                bool   typeIsNullable;
                string tp = JSONMappings.MapCLRTypeToJSON(m_Type, out typeIsNullable);

                var map = new Dictionary <string, object>
                {
                    { "Name", m_Name },
                    { "Order", m_Order },
                    { "Type", tp },
                    { "Nullable", typeIsNullable }
                };

                //20190322 DKh inner schema
                if (typeof(Doc).IsAssignableFrom(this.NonNullableType))
                {
                    map["IsDataDoc"]   = true;
                    map["IsAmorphous"] = typeof(IAmorphousData).IsAssignableFrom(this.NonNullableType);
                    map["IsForm"]      = typeof(Form).IsAssignableFrom(this.NonNullableType);

                    if (typeof(TypedDoc).IsAssignableFrom(this.NonNullableType))
                    {
                        var innerSchema = Schema.GetForTypedDoc(this.NonNullableType);
                        if (innerSchema.Any(fd => typeof(TypedDoc).IsAssignableFrom(fd.Type)))
                        {
                            map["DataDocSchema"] = "@complex";
                        }
                        else
                        {
                            map["DataDocSchema"] = innerSchema;
                        }
                    }
                }

                if (attr != null)
                {
                    map.Add("IsKey", attr.Key);
                    map.Add("IsRequired", attr.Required);
                    map.Add("Visible", attr.Visible);
                    if (attr.Default != null)
                    {
                        map.Add("Default", attr.Default);
                    }
                    if (attr.CharCase != CharCase.AsIs)
                    {
                        map.Add("CharCase", attr.CharCase);
                    }
                    if (attr.Kind != DataKind.Text)
                    {
                        map.Add("Kind", attr.Kind);
                    }
                    if (attr.MinLength != 0)
                    {
                        map.Add("MinLen", attr.MinLength);
                    }
                    if (attr.MaxLength != 0)
                    {
                        map.Add("MaxLen", attr.MaxLength);
                    }
                    if (attr.Min != null)
                    {
                        map.Add("Min", attr.Min);
                    }
                    if (attr.Max != null)
                    {
                        map.Add("Max", attr.Max);
                    }
                    if (attr.ValueList != null)
                    {
                        map.Add("ValueList", attr.ValueList);
                    }
                    if (attr.Description != null)
                    {
                        map.Add("Description", attr.Description);
                    }
                    //metadata content is in the internal format and not dumped
                }

                JsonWriter.WriteMap(wri, map, nestingLevel, options);
            }