Beispiel #1
0
        private void SetDictionaryData(object model, object data, JSONFieldSpecs specs)
        {
            if (!JSONHelper.IsJSONObject(data))
            {
                UnityEngine.Debug.LogWarningFormat("Data [{0}] is not an objec", specs.Name);
                return;
            }

            var objectData   = JSONHelper.AsObject(data);
            var elementType  = specs.Property.PropertyType.GetGenericArguments();
            var propertyData = Activator.CreateInstance(specs.Property.PropertyType) as IDictionary;

            foreach (var element in objectData)
            {
                var createdModel = CreateModel(elementType[1], element.Value);
                propertyData.Add(element.Key, createdModel);
            }
            specs.Property.SetValue(model, propertyData, null);
        }
Beispiel #2
0
        /// <summary>
        /// Sets the model data.
        /// </summary>
        /// <param name="model">Model.</param>
        /// <param name="data">Data.</param>
        private void SetModelData(object model, object data, IEnumerator <JSONFieldSpecs> typeSpecs)
        {
            var dict = JSONHelper.AsObject(data);

            while (typeSpecs.MoveNext())
            {
                var specs = typeSpecs.Current;
                if (dict.ContainsKey(specs.Name))
                {
                    SetData(model, dict [specs.Name], specs);
                    continue;
                }
                if (!specs.ShortNameAvailable)
                {
                    continue;
                }

                if (dict.ContainsKey(specs.ShortName))
                {
                    SetData(model, dict [specs.ShortName], specs);
                }
            }
        }