Пример #1
0
            void InternalDeserializer(Dictionary <string, object> upContext, Dictionary <int, object> pkContext, DbDataReader reader, DynDeserializerItem o)
            {
                Dictionary <string, object> values;

                foreach (KeyValuePair <string, int> kv in o.Fields)
                {
                    upContext[kv.Key] = reader.GetValue(kv.Value);
                }

                List <object> list = new List <object>(); object a;

                foreach (KeyValuePair <string, DynDeserializerItem> kv in o.Collections)
                {
                    if (kv.Value.Index != -1)
                    {
                        if (reader.IsDBNull(kv.Value.Index))
                        {
                            if (!upContext.ContainsKey(kv.Key))
                            {
                                upContext.Add(kv.Key, (dynamic)null);
                            }
                            continue;
                        }

                        object pk = reader.GetValue(kv.Value.Index);
                        if (pkContext.ContainsKey(kv.Value.Index))
                        {
                            if ((pkContext[kv.Value.Index] as IComparable).CompareTo(pk) > 0)
                            {
                                if (!upContext.ContainsKey(kv.Key))
                                {
                                    upContext.Add(kv.Key, (dynamic)null);
                                }
                                continue;
                            }
                        }

                        pkContext[kv.Value.Index] = pk;
                    }

                    values = new Dictionary <string, object>(StringComparer.InvariantCultureIgnoreCase);
                    if (kv.Value.Single)
                    {
                        upContext.Add(kv.Key, (dynamic)DynObj.Create(values));
                    }
                    else
                    {
                        upContext.TryGetValue(kv.Key, out a);
                        if (null == (list = a as List <object>))
                        {
                            list = new List <object>();
                            upContext[kv.Key] = list;
                        }

                        list.Add((dynamic)DynObj.Create(values));
                    }

                    InternalDeserializer(values, pkContext, reader, kv.Value);
                }
            }
Пример #2
0
            public T Deserializer <T>(DbDataReader reader, out bool more) where T : class
            {
                more = false;
                Dictionary <int, object> _pkContext = new Dictionary <int, object>();

                object index_value_1 = reader.GetValue(_dynObjItem.Index);
                object index_value_2;

                Dictionary <string, object> values = new Dictionary <string, object>(StringComparer.InvariantCultureIgnoreCase);

                do
                {
                    InternalDeserializer(values, _pkContext, reader, _dynObjItem);

                    if (reader.Read())
                    {
                        index_value_2 = reader.GetValue(_dynObjItem.Index);
                        if ((index_value_2 as IComparable).CompareTo(index_value_1) != 0)
                        {
                            more = true;
                            break;
                        }
                    }
                    else
                    {
                        break;
                    }
                } while (true);

                return(DynObj.Create(values) as T);
            }