/// <summary> /// Override to filter-out some fields from serialization to JSON, or change field values. /// Return name null to indicate that field should be filtered-out(excluded from serialization to JSON) /// </summary> protected virtual object FilterJsonSerializerField(Schema.FieldDef def, JsonWritingOptions options, out string name) { var tname = options != null ? options.RowMapTargetName : null; if (tname.IsNotNullOrWhiteSpace()) { FieldAttribute attr; name = def.GetBackendNameForTarget(tname, out attr); if (attr != null) { if (attr.StoreFlag == StoreFlag.None || attr.StoreFlag == StoreFlag.OnlyLoad) { name = null; return(null); } var dflt = attr.Default; if (dflt != null) { var value = GetFieldValue(def); if (dflt.Equals(value)) { name = null; return(null); } return(value); } } } else { name = def.Name; } return(name.IsNotNullOrWhiteSpace() ? GetFieldValue(def) : null); }
private void field(string targetName, Schema.FieldDef def, IMetadataGenerator context, ConfigSectionNode data, TypedDoc doc) { var fname = def.GetBackendNameForTarget(targetName, out var fatr); if (fatr == null) { return; } if (context.DetailLevel > MetadataDetailLevel.Public) { data.AddAttributeNode("prop-name", def.Name); data.AddAttributeNode("prop-type", def.Type.AssemblyQualifiedName); data.AddAttributeNode("non-ui", fatr.NonUI); data.AddAttributeNode("is-arow", fatr.IsArow); data.AddAttributeNode("store-flag", fatr.StoreFlag); data.AddAttributeNode("backend-type", fatr.BackendType); //try to disclose ALL metadata (as we are above PUBLIC) if (fatr.Metadata != null && fatr.Metadata.Exists) { var metad = data.AddChildNode("meta"); metad.MergeSections(fatr.Metadata); metad.MergeAttributes(fatr.Metadata); } } else //try to disclose pub-only metadata { var pubSection = context.PublicMetadataSection; if (fatr.Metadata != null && pubSection.IsNotNullOrWhiteSpace()) { var metasrc = fatr.Metadata[pubSection];//<-- pub metadata only if (metasrc.Exists) { var metad = data.AddChildNode("meta"); metad.MergeSections(metasrc); metad.MergeAttributes(metasrc); } } } data.AddAttributeNode("name", fname); data.AddAttributeNode("type", context.AddTypeToDescribe(def.Type)); data.AddAttributeNode("order", def.Order); if (fatr.Description.IsNotNullOrWhiteSpace()) { data.AddAttributeNode("description", fatr.Description); } data.AddAttributeNode("key", fatr.Key); data.AddAttributeNode("kind", fatr.Kind); data.AddAttributeNode("required", fatr.Required); data.AddAttributeNode("visible", fatr.Required); data.AddAttributeNode("case", fatr.CharCase); if (fatr.Default != null) { data.AddAttributeNode("default", fatr.Default); } if (fatr.DisplayFormat.IsNotNullOrWhiteSpace()) { data.AddAttributeNode("display-format", fatr.DisplayFormat); } if (fatr.FormatRegExp.IsNotNullOrWhiteSpace()) { data.AddAttributeNode("format-reg-exp", fatr.FormatRegExp); } if (fatr.FormatDescription.IsNotNullOrWhiteSpace()) { data.AddAttributeNode("format-description", fatr.FormatDescription); } if (fatr.Max != null) { data.AddAttributeNode("max", fatr.Max); } if (fatr.Min != null) { data.AddAttributeNode("min", fatr.Min); } if (fatr.MinLength > 0 || fatr.MaxLength > 0) { data.AddAttributeNode("min-len", fatr.MinLength); } if (fatr.MinLength > 0 || fatr.MaxLength > 0) { data.AddAttributeNode("max-len", fatr.MaxLength); } //add values from field attribute .ValueList property var nvlist = new Lazy <ConfigSectionNode>(() => data.AddChildNode("value-list")); if (fatr.HasValueList) { fatr.ParseValueList().ForEach(item => nvlist.Value.AddAttributeNode(item.Key, item.Value)); } //if doc!=null call doc.GetClientFieldValueList on the instance to get values from Database lookups etc... if (doc != null) { var lookup = doc.GetDynamicFieldValueList(def, targetName, null); if (lookup != null)//non-null blank lookup is treated as blank lookup overshadowing the hard-coded choices from .ValueList { if (nvlist.IsValueCreated) { nvlist.Value.DeleteAllAttributes(); } lookup.ForEach(item => nvlist.Value.AddAttributeNode(item.Key, item.Value)); } } }
private void field(Schema.FieldDef def, IMetadataGenerator context, ConfigSectionNode data, TypedDoc doc) { var fname = def.GetBackendNameForTarget(context.DataTargetName, out var fatr); if (fatr == null) { return; } if (context.DetailLevel > MetadataDetailLevel.Public) { data.AddAttributeNode("prop-name", def.Name); data.AddAttributeNode("prop-type", def.Type.AssemblyQualifiedName); data.AddAttributeNode("non-ui", fatr.NonUI); data.AddAttributeNode("is-arow", fatr.IsArow); data.AddAttributeNode("store-flag", fatr.StoreFlag); data.AddAttributeNode("backend-type", fatr.BackendType); if (fatr.Metadata != null) { data.AddChildNode(fatr.Metadata); } } data.AddAttributeNode("name", fname); data.AddAttributeNode("type", context.AddTypeToDescribe(def.Type)); data.AddAttributeNode("order", def.Order); if (fatr.Description.IsNotNullOrWhiteSpace()) { data.AddAttributeNode("description", fatr.Description); } data.AddAttributeNode("key", fatr.Key); if (def.Type == typeof(string)) { data.AddAttributeNode("kind", fatr.Kind); } data.AddAttributeNode("required", fatr.Required); data.AddAttributeNode("visible", fatr.Required); data.AddAttributeNode("case", fatr.CharCase); if (fatr.Default != null) { data.AddAttributeNode("default", fatr.Default); } if (fatr.DisplayFormat.IsNotNullOrWhiteSpace()) { data.AddAttributeNode("display-format", fatr.DisplayFormat); } if (fatr.FormatRegExp.IsNotNullOrWhiteSpace()) { data.AddAttributeNode("format-reg-exp", fatr.FormatRegExp); } if (fatr.FormatDescription.IsNotNullOrWhiteSpace()) { data.AddAttributeNode("format-description", fatr.FormatDescription); } if (fatr.Max != null) { data.AddAttributeNode("max", fatr.Max); } if (fatr.Min != null) { data.AddAttributeNode("min", fatr.Min); } if (fatr.MinLength > 0 || fatr.MaxLength > 0) { data.AddAttributeNode("min-len", fatr.MinLength); } if (fatr.MinLength > 0 || fatr.MaxLength > 0) { data.AddAttributeNode("max-len", fatr.MaxLength); } //add values from field attribute .ValueList property var nvlist = new Lazy <ConfigSectionNode>(() => data.AddChildNode("value-list")); if (fatr.HasValueList) { fatr.ParseValueList().ForEach(item => nvlist.Value.AddAttributeNode(item.Key, item.Value)); } //if doc!=null call doc.GetClientFieldValueList on the instance to get values from Database lookups etc... if (doc != null) { var lookup = doc.GetClientFieldValueList(def, context.DataTargetName, null); if (lookup != null) { lookup.ForEach(item => nvlist.Value.AddAttributeNode(item.Key, item.Value)); } } }