예제 #1
0
        public void ReadObjectElement(ObjectElementAttribute attribute, object reader, object receiver,
                                      ReadSettings settings, ObjectPropertyInfo info, object serializerData)
        {
            DataTable table = serializerData.Convert <DataTable>();

            if (table.Rows.Count == 0)
            {
                return;
            }

            Type objectType = info.ObjectType;
            IObjectSerializer rowSerializer = ObjectExtension.CreateSerializer("DataRow");

            if (attribute.IsMultiple)
            {
                IList list = attribute.GetList(receiver, info);
                foreach (DataRow row in table.Rows)
                {
                    object subObject = ReadObject(attribute.UseConstructor, settings, row, objectType,
                                                  receiver, rowSerializer, info.ModelName);
                    list.Add(subObject);
                }
            }
            else
            {
                object subObject = ReadObject(attribute.UseConstructor, settings, table.Rows[0],
                                              objectType, receiver, rowSerializer, info.ModelName);
                info.SetValue(receiver, subObject);
            }
        }
예제 #2
0
        public static void AddToDataRow(this object receiver, DataRow row,
                                        string modelName, WriteSettings settings)
        {
            TkDebug.AssertArgumentNull(receiver, "receiver", null);
            TkDebug.AssertArgumentNull(row, "row", null);
            TkDebug.AssertArgumentNull(settings, "settings", null);

            IObjectSerializer serializer = ObjectExtension.CreateSerializer("DataRow");
            object            writer     = serializer.CreateCustomWriter(row);

            serializer.WriteObject(writer, receiver, modelName, settings, QName.Toolkit, null);
        }
예제 #3
0
        public static void ReadFromDataRow(this object receiver, DataRow row, string modelName,
                                           ReadSettings settings)
        {
            TkDebug.AssertArgumentNull(receiver, "receiver", null);
            TkDebug.AssertArgumentNull(row, "row", null);
            TkDebug.AssertArgumentNull(settings, "settings", null);

            IObjectSerializer serializer = ObjectExtension.CreateSerializer("DataRow");
            object            reader     = serializer.CreateCustomReader(row);

            serializer.ReadObject(reader, receiver, modelName, settings, QName.Toolkit, null);
            SerializerUtil.ReadObjectCallBack(receiver);
        }
예제 #4
0
        public static void ReadDictionaryFromDataRow(this IDictionary dictionary,
                                                     DataRow row, ReadSettings settings)
        {
            TkDebug.AssertArgumentNull(dictionary, "dictionary", null);
            TkDebug.AssertArgumentNull(row, "row", null);
            TkDebug.AssertArgumentNull(settings, "settings", null);

            IObjectSerializer   serializer = ObjectExtension.CreateSerializer("DataRow");
            object              reader     = serializer.CreateCustomReader(row);
            DictionaryAttribute attr       = new DictionaryAttribute {
                AutoTrim = true
            };

            serializer.ReadDictionary(reader, dictionary, attr, null, settings, null, null);
        }
예제 #5
0
        public static Dictionary <string, Object> WriteDictionary(this object receiver,
                                                                  string modelName, DictionaryOutput output)
        {
            if (receiver == null)
            {
                return(null);
            }

            IObjectSerializer serializer = ObjectExtension.CreateSerializer("Dictionary");
            DictionaryBuilder builder    = new DictionaryBuilder(output);
            object            writer     = serializer.CreateCustomWriter(builder);

            SerializerUtil.WriteSerializer(serializer, writer, receiver, modelName, ObjectUtil.WriteSettings, QName.Toolkit, null);

            return(builder.Data);
        }
예제 #6
0
        public static string WriteQueryString(this object receiver,
                                              string modelName, QueryStringOutput output)
        {
            if (receiver == null)
            {
                return(null);
            }

            IObjectSerializer  serializer = ObjectExtension.CreateSerializer("QueryString");
            QueryStringBuilder builder    = new QueryStringBuilder(output);
            object             writer     = serializer.CreateCustomWriter(builder);

            SerializerUtil.WriteSerializer(serializer, writer, receiver, modelName, ObjectUtil.WriteSettings, QName.Toolkit, null);

            return(builder.ToString());
        }
예제 #7
0
        public static void AddToDataSet(this object receiver, DataSet dataSet,
                                        string modelName, WriteSettings settings)
        {
            if (receiver == null)
            {
                return;
            }

            TkDebug.AssertArgumentNull(dataSet, "dataSet", null);
            TkDebug.AssertArgumentNull(settings, "settings", null);

            IObjectSerializer serializer = ObjectExtension.CreateSerializer("DataSet");
            object            writer     = serializer.CreateCustomWriter(dataSet);

            serializer.WriteObject(writer, receiver, modelName, settings, QName.Toolkit, null);
        }
예제 #8
0
        public static List <T> CreateListFromTable <T>(this DataTable table, string modelName,
                                                       ReadSettings settings, Func <T> createFunc)
        {
            if (table == null)
            {
                return(null);
            }
            TkDebug.AssertArgumentNull(settings, "settings", null);
            TkDebug.AssertArgumentNull(createFunc, "createFunc", null);

            List <T> result = new List <T>(table.Rows.Count);

            IObjectSerializer serializer = ObjectExtension.CreateSerializer("DataRow");

            foreach (DataRow row in table.Rows)
            {
                T      obj    = createFunc();
                object reader = serializer.CreateCustomReader(row);
                serializer.ReadObject(reader, obj, modelName, settings, QName.Toolkit, null);
                result.Add(obj);
            }
            return(result);
        }
예제 #9
0
        public static DataTable CreateTable(this IEnumerable list, string tableName,
                                            string modelName, WriteSettings settings)
        {
            TkDebug.AssertArgumentNullOrEmpty(tableName, "tableName", null);
            TkDebug.AssertArgumentNull(settings, "settings", null);

            if (list == null)
            {
                return(null);
            }

            object value = list.Cast <object>().FirstOrDefault();

            if (value == null)
            {
                return(null);
            }

            ObjectInfo info  = ObjectInfo.Create(value, modelName);
            DataTable  table = new DataTable(tableName)
            {
                Locale = ObjectUtil.SysCulture
            };

            CreateTableStructure(info, table);
            IObjectSerializer serializer = ObjectExtension.CreateSerializer("DataRow");

            foreach (var item in list)
            {
                DataRow row    = table.NewRow();
                object  writer = serializer.CreateCustomWriter(row);
                serializer.WriteObject(writer, item, null, settings, QName.Toolkit, null);
                table.Rows.Add(row);
            }
            return(table);
        }