/// <summary> /// Converts a JSON object to an Attribute object /// </summary> public static CdmAttributeItem CreateAttribute(CdmCorpusContext ctx, dynamic obj, string entityName = null) { if (obj == null) { return(null); } if (obj is JValue) { return(AttributeGroupReferencePersistence.FromData(ctx, obj)); } else { if (obj["attributeGroupReference"] != null) { return(AttributeGroupReferencePersistence.FromData(ctx, obj, entityName)); } else if (obj["entity"] != null) { return(EntityAttributePersistence.FromData(ctx, obj)); } else if (obj["name"] != null) { return(TypeAttributePersistence.FromData(ctx, obj, entityName)); } } return(null); }
/// <summary> /// Creates a CDM object from a JSON object /// </summary> public static dynamic CreateConstant(CdmCorpusContext ctx, dynamic obj) { if (obj == null) { return(null); } if (obj is JValue) { return(obj.Value); } else if (obj is JObject) { if (obj["purpose"] != null || obj["dataType"] != null || obj["entity"] != null) { if (obj["dataType"] != null) { return(TypeAttributePersistence.FromData(ctx, obj)); } else if (obj["entity"] != null) { return(EntityAttributePersistence.FromData(ctx, obj)); } else { return(null); } } else if (obj["purposeReference"] != null) { return(PurposeReferencePersistence.FromData(ctx, obj)); } else if (obj["traitReference"] != null) { return(TraitReferencePersistence.FromData(ctx, obj)); } else if (obj["dataTypeReference"] != null) { return(DataTypeReferencePersistence.FromData(ctx, obj)); } else if (obj["entityReference"] != null) { return(EntityReferencePersistence.FromData(ctx, obj)); } else if (obj["attributeGroupReference"] != null) { return(AttributeGroupReferencePersistence.FromData(ctx, obj)); } else { return(obj); } } else { return(obj); } }
public static CdmAttributeContext FromData(CdmCorpusContext ctx, dynamic obj) { if (obj == null) { return(null); } CdmAttributeContext attributeContext = ctx.Corpus.MakeObject <CdmAttributeContext>(CdmObjectType.AttributeContextDef, obj.Value <string>("name"), false); attributeContext.Type = MapTypeNameToEnum(obj.Value <string>("type")); if (obj.Value <string>("parent") != null) { attributeContext.Parent = AttributeContextReferencePersistence.FromData(ctx, obj.Value <string>("parent")); } string explanation = obj.Value <string>("explanation"); if (!string.IsNullOrEmpty(explanation)) { attributeContext.Explanation = explanation; } if (obj.Value <string>("definition") != null) { switch (attributeContext.Type) { case CdmAttributeContextType.Entity: case CdmAttributeContextType.EntityReferenceExtends: attributeContext.Definition = EntityReferencePersistence.FromData(ctx, obj.Value <string>("definition")); break; case CdmAttributeContextType.AttributeGroup: attributeContext.Definition = AttributeGroupReferencePersistence.FromData(ctx, obj.Value <string>("definition")); break; case CdmAttributeContextType.AddedAttributeSupporting: case CdmAttributeContextType.AddedAttributeIdentity: case CdmAttributeContextType.AddedAttributeExpansionTotal: case CdmAttributeContextType.AddedAttributeSelectedType: case CdmAttributeContextType.AttributeDefinition: attributeContext.Definition = AttributeReferencePersistence.FromData(ctx, obj.Value <string>("definition")); break; } } // i know the trait collection names look wrong. but I wanted to use the def baseclass Utils.AddListToCdmCollection(attributeContext.ExhibitsTraits, Utils.CreateTraitReferenceList(ctx, obj.Value <JToken>("appliedTraits"))); if (obj.Value <JToken>("contents") != null) { for (int i = 0; i < obj.Value <JToken>("contents").Count; i++) { JToken ct = obj.Value <JToken>("contents")[i]; if (ct is JValue) { attributeContext.Contents.Add(AttributeReferencePersistence.FromData(ctx, (string)ct)); } else { attributeContext.Contents.Add(FromData(ctx, ct)); } } } return(attributeContext); }