コード例 #1
0
 public void OnWriteAll(IDataReader <string> dataReader)
 {
     foreach (DataColumn item in Content.Table.Columns)
     {
         Content[item.Ordinal] = ValueInterface.GetInterface(item.DataType).Read(dataReader[item.ColumnName]);
     }
 }
コード例 #2
0
 public void OnReadAll(IDataWriter <string> dataWriter)
 {
     foreach (DataColumn item in Content.Table.Columns)
     {
         ValueInterface.GetInterface(item.DataType).Write(dataWriter[item.ColumnName], Content[item.Ordinal]);
     }
 }
コード例 #3
0
ファイル: RWHelper.cs プロジェクト: zxbe/Swifter
        public static IDataRW CreateRW(object obj)
        {
            var helperValueRW = HelperValueRW;

            ValueInterface.GetInterface(obj).WriteValue(helperValueRW, obj);

            var value = helperValueRW.Content;

            if (value == null)
            {
                throw new NotSupportedException(StringHelper.Format("Failure to create IDataRW for BasicTypes '{0}'.", helperValueRW.GetBasicType().ToString()));
            }

            if (value is IAsDataReader)
            {
                value = ((IAsDataReader)value).Content;
            }

            if (value is IAsDataWriter)
            {
                value = ((IAsDataWriter)value).Content;
            }

            if (!(value is IDataRW))
            {
                throw new NotSupportedException(StringHelper.Format("Failure to create IDataRW for '{0}'.", obj.GetType().Name));
            }

            return((IDataRW)value);
        }
コード例 #4
0
        public void WriteValue(IValueWriter valueWriter, object value)
        {
            if (value == null)
            {
                valueWriter.DirectWrite(null);

                return;
            }

            if (valueWriter is IValueWriter <object> writer)
            {
                writer.WriteValue(value);

                return;
            }

            /* 父类引用,子类实例时使用 Type 获取写入器。 */

            if (TypeInfo <object> .Int64TypeHandle != (long)TypeHelper.GetTypeHandle(value))
            {
                ValueInterface.GetInterface(value).Write(valueWriter, value);

                return;
            }

            valueWriter.DirectWrite(value);
        }
コード例 #5
0
 public void WriteValue(IValueWriter valueWriter, T value)
 {
     if (value is null)
     {
         valueWriter.DirectWrite(null);
     }
     else if (valueWriter is IValueWriter <T> writer)
     {
         writer.WriteValue(value);
     }
     else if (value is IFormattable)
     {
         valueWriter.DirectWrite(value);
     }
     else if (value is string str)
     {
         valueWriter.WriteString(str);
     }
     else if (TypeHandle != TypeHelper.GetTypeHandle(value))
     {
         ValueInterface.GetInterface(value).Write(valueWriter, value);
     }
     else
     {
         valueWriter.DirectWrite(value);
     }
 }
コード例 #6
0
ファイル: RWHelper.cs プロジェクト: zhusy09/Swifter.Json
        public static IDataWriter CreateWriter(object obj, bool throwException = true)
        {
            if (obj == null)
            {
                throw new ArgumentNullException(nameof(obj));
            }

            var auxiliary = new AuxiliaryValueRW();

            var @interface = ValueInterface.GetInterface(obj);

            @interface.Write(auxiliary, obj);

            var writer = auxiliary.GetDataWriter();

            if (writer != null)
            {
                return(writer);
            }

            @interface.Read(auxiliary);

            writer = auxiliary.GetDataWriter();

            if (writer == null)
            {
                return(auxiliary.GetDataWriter() ?? (throwException ? throw new NotSupportedException($"Unable create data writer of  '{obj.GetType()}'.") : default(IDataWriter)));
            }

            SetContent(writer, obj);

            return(writer);
        }
コード例 #7
0
ファイル: DataRowRW.cs プロジェクト: zhusy09/Swifter.Json
        public void OnWriteValue(string key, IValueReader valueReader)
        {
            DataColumn column;

            if (DataRow != null && (column = DataRow.Table.Columns[key]) != null && column.DataType != typeof(object))
            {
                DataRow[column] = ValueInterface.GetInterface(column.DataType).Read(valueReader);

                return;
            }

            Items.Add(new KeyValuePair <string, object>(key, valueReader.DirectRead()));
        }
コード例 #8
0
        public static IDataReader CreateReader(object obj)
        {
            if (obj == null)
            {
                throw new ArgumentNullException(nameof(obj));
            }

            var auxiliary = new AuxiliaryValueRW();

            ValueInterface.GetInterface(obj).Write(auxiliary, obj);

            return(auxiliary.GetDataReader() ?? throw new NotSupportedException($"Unable create data reader of '{obj.GetType()}'."));
        }
コード例 #9
0
ファイル: RWHelper.cs プロジェクト: zhusy09/Swifter.Json
        public static IDataRW CreateRW(object obj, bool throwException = true)
        {
            if (obj == null)
            {
                throw new ArgumentNullException(nameof(obj));
            }

            var auxiliary = new AuxiliaryValueRW();

            ValueInterface.GetInterface(obj).Write(auxiliary, obj);

            return(auxiliary.GetDataRW() ?? (throwException ? throw new NotSupportedException($"Unable create data reader-writer of '{obj.GetType()}'.") : default(IDataRW)));
        }
コード例 #10
0
ファイル: RWHelper.cs プロジェクト: zhusy09/Swifter.Json
        public static IDataWriter CreateWriter(Type type, bool throwException = true)
        {
            if (type == null)
            {
                throw new ArgumentNullException(nameof(type));
            }

            var auxiliary = new AuxiliaryValueRW();

            ValueInterface.GetInterface(type).Read(auxiliary);

            return(auxiliary.GetDataWriter() ?? (throwException ? throw new NotSupportedException($"Unable create data writer of '{type}'.") : default(IDataRW)));
        }
コード例 #11
0
        public void WriteValue(IValueWriter valueWriter, T value)
        {
            if (value == null)
            {
                valueWriter.DirectWrite(null);

                return;
            }

            /* 父类引用,子类实例时使用 Type 获取写入器。 */
            if (CheckChildrenInstance && Int64TypeHandle != (long)TypeHelper.GetTypeHandle(value))
            {
                ValueInterface.GetInterface(value).Write(valueWriter, value);

                return;
            }

            if (valueWriter is ISingleThreadOptimize)
            {
                var current_cache = thread_cache;

                if (current_cache == null)
                {
                    InitializeInstance(ref current_cache);
                }

                if (current_cache.IsUsed)
                {
                    goto Default;
                }

                current_cache.IsUsed = true;

                current_cache.Instance.Initialize(value);

                valueWriter.WriteObject(current_cache.Instance);

                current_cache.IsUsed = false;

                return;
            }

Default:

            var fastObjectRW = FastObjectRW <T> .Create();

            fastObjectRW.Initialize(value);

            valueWriter.WriteObject(fastObjectRW);
        }
コード例 #12
0
        public static IDataWriter CreateWriter(Type type)
        {
            var auxiliaryValueRW = new AuxiliaryValueRW();

            ValueInterface.GetInterface(type).Read(auxiliaryValueRW);

            var value = auxiliaryValueRW.read_writer;

            if (value is IAsDataWriter @as)
            {
                return(@as.Content);
            }

            return((IDataWriter)value);
        }
コード例 #13
0
        public static IDataReader CreateReader(object obj)
        {
            var auxiliaryValueRW = new AuxiliaryValueRW();

            ValueInterface.GetInterface(obj).Write(auxiliaryValueRW, obj);

            var value = auxiliaryValueRW.read_writer;

            if (value is IAsDataReader @as)
            {
                return(@as.Content);
            }

            return((IDataReader)value);
        }
コード例 #14
0
        public void OnReadAll(IDataWriter <string> dataWriter, IValueFilter <string> valueFilter)
        {
            var valueInfo = new ValueFilterInfo <string>();

            foreach (DataColumn item in Content.Table.Columns)
            {
                ValueInterface.GetInterface(item.DataType).Write(valueInfo.ValueCopyer, Content[item.Ordinal]);

                valueInfo.Key  = item.ColumnName;
                valueInfo.Type = item.DataType;

                if (valueFilter.Filter(valueInfo))
                {
                    valueInfo.ValueCopyer.WriteTo(dataWriter[valueInfo.Key]);
                }
            }
        }
コード例 #15
0
        public void WriteValue(IValueWriter valueWriter, object value)
        {
            if (value is null)
            {
                valueWriter.DirectWrite(null);

                return;
            }

            /* 父类引用,子类实例时使用 Type 获取写入器。 */
            if (TypeHandle != TypeHelper.GetTypeHandle(value))
            {
                ValueInterface.GetInterface(value).Write(valueWriter, value);

                return;
            }

            valueWriter.DirectWrite(value);
        }
コード例 #16
0
        public void WriteValue(IValueWriter valueWriter, T value)
        {
            if (value == null)
            {
                valueWriter.DirectWrite(null);

                return;
            }

            if (valueWriter is IValueWriter <T> writer)
            {
                writer.WriteValue(value);

                return;
            }

            if (value is IFormattable)
            {
                valueWriter.DirectWrite(value);

                return;
            }

            if (value is string)
            {
                valueWriter.WriteString((string)(object)value);

                return;
            }

            /* 父类引用,子类实例时使用 Type 获取写入器。 */
            if (Int64TypeHandle != (long)TypeHelper.GetTypeHandle(value))
            {
                ValueInterface.GetInterface(value).Write(valueWriter, value);

                return;
            }

            valueWriter.DirectWrite(value);
        }
コード例 #17
0
        public void WriteValue(IValueWriter valueWriter, T value)
        {
            if (value is null)
            {
                valueWriter.DirectWrite(null);

                return;
            }

            /* 父类引用,子类实例时使用 Type 获取写入器。 */
            if (CheckDerivedInstance && TypeHandle != TypeHelper.GetTypeHandle(value))
            {
                ValueInterface.GetInterface(value).Write(valueWriter, value);

                return;
            }

            valueWriter.WriteObject(new NonPublicFastObjectRW <T>
            {
                content = value
            });
        }
コード例 #18
0
        public void WriteValue(IValueWriter valueWriter, T value)
        {
            if (value == null)
            {
                valueWriter.DirectWrite(null);

                return;
            }

            /* 父类引用,子类实例时使用 Type 获取写入器。 */
            if (CheckChildrenInstance && Int64TypeHandle != (long)TypeHelper.GetTypeHandle(value))
            {
                ValueInterface.GetInterface(value).Write(valueWriter, value);

                return;
            }

            var fastObjectRW = FastObjectRW <T> .Create();

            fastObjectRW.Initialize(value);

            valueWriter.WriteObject(fastObjectRW);
        }
コード例 #19
0
        public void WriteValue(IValueWriter valueWriter, T value)
        {
            if (value == null)
            {
                valueWriter.DirectWrite(null);

                return;
            }

            /* 父类引用,子类实例时使用 Type 获取写入器。 */
            if (CheckDerivedInstance && TypeHandle != TypeHelper.GetTypeHandle(value))
            {
                ValueInterface.GetInterface(value).Write(valueWriter, value);

                return;
            }

            var reader = FastObjectRW <T> .Create();

            reader.Initialize(value);

            valueWriter.WriteObject(reader);
        }
コード例 #20
0
        public void OnWriteValue(string key, IValueReader valueReader)
        {
            var dataColumn = Content.Table.Columns[key];

            if (dataColumn == null)
            {
                var type = typeof(object);

                var value = valueReader.DirectRead();

                if (value != null)
                {
                    type = value.GetType();
                }

                dataColumn = Content.Table.Columns.Add(key, type);

                Content[dataColumn.Ordinal] = value;

                return;
            }

            Content[dataColumn.Ordinal] = ValueInterface.GetInterface(dataColumn.DataType).Read(valueReader);
        }
コード例 #21
0
ファイル: DataRowRW.cs プロジェクト: zhusy09/Swifter.Json
        public void OnWriteValue(int key, IValueReader valueReader)
        {
            var type = Content.Table.Columns[key].DataType;

            Content[key] = type == typeof(object) ? valueReader.DirectRead() : ValueInterface.GetInterface(type).Read(valueReader);
        }
コード例 #22
0
        public void OnReadValue(string key, IValueWriter valueWriter)
        {
            var dataColumn = Content.Table.Columns[key];

            ValueInterface.GetInterface(dataColumn.DataType).Write(valueWriter, Content[dataColumn.Ordinal]);
        }