コード例 #1
0
        private void SetListData(object model, object data, JSONFieldSpecs specs)
        {
            if (!JSONHelper.IsJSONArray(data))
            {
                UnityEngine.Debug.LogWarningFormat("Data [{0}] is not an array", specs.Name);
                return;
            }

            var arrayData    = JSONHelper.AsArray(data);
            var elementType  = specs.Property.PropertyType.GetGenericArguments()[0];
            var propertyData = Activator.CreateInstance(specs.Property.PropertyType) as IList;

            for (int i = 0; i < arrayData.Count; ++i)
            {
                var createdModel = CreateModel(elementType, arrayData[i]);
                propertyData.Add(createdModel);
            }
            specs.Property.SetValue(model, propertyData, null);
        }