Ejemplo n.º 1
0
        /// <summary>
        /// Converts a JSON object to a CdmCollection of TraitReferences and TraitGroupReferences
        /// </summary>
        public static List <CdmTraitReferenceBase> CreateTraitReferenceList(CdmCorpusContext ctx, dynamic obj)
        {
            if (obj == null)
            {
                return(null);
            }

            List <CdmTraitReferenceBase> result = new List <CdmTraitReferenceBase>();
            JArray traitRefObj = null;

            if (obj.GetType() == typeof(List <JToken>))
            {
                traitRefObj = JArray.FromObject(obj);
            }
            else if (obj.GetType() != typeof(JArray) && obj["value"] != null && obj["value"].GetType() == typeof(JArray))
            {
                traitRefObj = obj["value"];
            }
            else
            {
                traitRefObj = obj;
            }

            if (traitRefObj != null)
            {
                for (int i = 0; i < traitRefObj.Count; i++)
                {
                    dynamic tr = traitRefObj[i];

                    if (!(tr is JValue) && tr["traitGroupReference"] != null)
                    {
                        result.Add(TraitGroupReferencePersistence.FromData(ctx, tr));
                    }
                    else
                    {
                        result.Add(TraitReferencePersistence.FromData(ctx, tr));
                    }
                }
            }

            return(result);
        }
Ejemplo n.º 2
0
 /// <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["traitGroupReference"] != null)
         {
             return(TraitGroupReferencePersistence.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);
     }
 }