예제 #1
0
        /// <summary>
        /// Converts a JSON object to a CdmCollection of TraitReferences
        /// </summary>
        public static List <CdmTraitReference> CreateTraitReferenceList(CdmCorpusContext ctx, dynamic obj)
        {
            if (obj == null)
            {
                return(null);
            }

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

            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];
                    result.Add(TraitReferencePersistence.FromData(ctx, tr));
                }
            }

            return(result);
        }
예제 #2
0
        public static CdmTraitDefinition FromData(CdmCorpusContext ctx, JToken obj)
        {
            CdmTraitDefinition trait = ctx.Corpus.MakeObject <CdmTraitDefinition>(CdmObjectType.TraitDef, (string)obj["traitName"]);

            trait.ExtendsTrait = TraitReferencePersistence.FromData(ctx, obj["extendsTrait"]);

            if (obj["explanation"] != null)
            {
                trait.Explanation = (string)obj["explanation"];
            }

            if (obj["hasParameters"] != null)
            {
                foreach (JToken ap in obj["hasParameters"])
                {
                    trait.Parameters.Add(ParameterPersistence.FromData(ctx, ap));
                }
            }

            if (obj["elevated"] != null)
            {
                trait.Elevated = (bool)obj["elevated"];
            }
            if (obj["ugly"] != null)
            {
                trait.Ugly = (bool)obj["ugly"];
            }
            if (obj["associatedProperties"] != null)
            {
                trait.AssociatedProperties = obj["associatedProperties"].ToObject <List <string> >();
            }
            return(trait);
        }
예제 #3
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["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);
     }
 }