Exemple #1
0
        public override object Insert(
            DataManager dataManager,
            IDynamicMetaObjectProvider data,
            string tableName = null,
            Query query      = null,
            int position     = 0)
        {
            IEnumerable enumerable = (IEnumerable)(this.DataManager.Json ?? (IEnumerable <object>)Enumerable.Empty <object>().ToList <object>());
            IDictionary <string, Type> columnType = DataUtil.GetColumnType(enumerable, false);
            bool flag = typeof(DynamicObject).IsAssignableFrom(enumerable.Cast <object>().ToList <object>().FirstOrDefault <object>()?.GetType());

            if ((enumerable as IEnumerable <object>).Count <object>() != 0)
            {
                if (flag)
                {
                    foreach (string name in (data as DynamicObject).GetDynamicMemberNames().ToArray <string>())
                    {
                        object obj           = enumerable.Cast <object>().ToList <object>().FirstOrDefault <object>();
                        object dynamicValue1 = DataUtil.GetDynamicValue(data as DynamicObject, name);
                        object dynamicValue2 = DataUtil.GetDynamicValue(obj as DynamicObject, name);
                        if (dynamicValue1 != null && dynamicValue2 != null)
                        {
                            (data as DynamicObject).TrySetMember((SetMemberBinder) new DataSetMemberBinder(name, false), SfBaseUtils.ChangeType(dynamicValue1, dynamicValue2.GetType()));
                        }
                        else
                        {
                            (data as DynamicObject).TrySetMember((SetMemberBinder) new DataSetMemberBinder(name, false), dynamicValue1);
                        }
                    }
                }
                else
                {
                    IDictionary <string, object> dictionary = (IDictionary <string, object>)data;
                    foreach (string key in dictionary.Keys.ToList <string>())
                    {
                        Type conversionType = columnType[key];
                        if (dictionary[key] != null)
                        {
                            ((IDictionary <string, object>)data)[key] = SfBaseUtils.ChangeType(dictionary[key], conversionType);
                        }
                        else
                        {
                            ((IDictionary <string, object>)data)[key] = dictionary[key];
                        }
                    }
                }
            }
            ((IList)enumerable).Insert(position, (object)data);
            return((object)data.ToString());
        }