コード例 #1
0
    public static ADAGEData Copy(ADAGEData data)
    {
        Type      type    = data.GetType();
        ADAGEData newData = (ADAGEData)Activator.CreateInstance(type);

        foreach (PropertyInfo sourcePropertyInfo in type.GetProperties())
        {
            PropertyInfo destPropertyInfo = type.GetProperty(sourcePropertyInfo.Name);

            destPropertyInfo.SetValue(
                newData,
                sourcePropertyInfo.GetValue(data, null),
                null);
        }

        foreach (FieldInfo sourceFieldInfo in type.GetFields())
        {
            FieldInfo destFieldInfo = type.GetField(sourceFieldInfo.Name);

            destFieldInfo.SetValue(
                newData,
                sourceFieldInfo.GetValue(data));
        }

        return(newData);
    }
コード例 #2
0
    public void Add(ADAGEData newData)
    {
        if (data == null)
        {
            data = new List <object>();
        }

        Add(newData.ToJson());
        //if(newData.GetType() == typeof(PollutionState))
        //	Debug.Log (data[data.Count - 1].ToString());
    }
コード例 #3
0
    public bool Validate(ADAGEData data)
    {
        string         type     = data.GetType().ToString();
        ADAGEEventInfo dataInfo = null;

        if (events != null && events.ContainsKey(type))
        {
            dataInfo = events[type];
        }
        else if (context != null && context.ContainsKey(type))
        {
            dataInfo = context[type];
        }

        if (dataInfo == null)
        {
            return(false);
        }

        FieldInfo    field;
        PropertyInfo property;

        foreach (KeyValuePair <string, ADAGEDataPropertyInfo> prop in dataInfo.properties)
        {
            field = data.GetType().GetField(prop.Key);
            if (field != null)
            {
                if (!prop.Value.IsValid(field.GetValue(data)))
                {
                    return(false);
                }
            }
            else
            {
                property = data.GetType().GetProperty(prop.Key);
                if (property == null)
                {
                    return(false);                    //it's neither and shouldn't be here
                }
                if (!prop.Value.IsValid(property.GetValue(data, null)))
                {
                    return(false);
                }
            }
        }

        return(true);
    }
コード例 #4
0
    public static ADAGEData CreateFromJSON(string json)
    {
        ADAGEData baseData = LitJson.JsonMapper.ToObject <ADAGEData>(json);

        if (baseData.key != null && baseData.key != "")
        {
            Type theType = ReflectionUtils.FindType(baseData.key);
            if (theType != null)
            {
                //ADAGEData output = Activator.CreateInstance(theType) as ADAGEData;
                //output.Copy(baseData);
                ADAGEData output = ADAGEData.Copy(baseData);

                output.InitFromJSON(json);
                return(output);
            }
        }

        return(null);
    }