コード例 #1
0
ファイル: RWHelper.cs プロジェクト: zhusy09/Swifter.Json
        public static IDataRW CreateRW <T>(T obj, bool throwException = true)
        {
            var auxiliary = new AuxiliaryValueRW();

            ValueInterface <T> .WriteValue(auxiliary, obj);

            return(auxiliary.GetDataRW() ?? (throwException ? throw new NotSupportedException($"Unable create data reader-writer of '{typeof(T)}'.") : default(IDataRW)));
        }
コード例 #2
0
        public static IDataRW CreateItemRW <TKey>(IDataReader <TKey> dataReader, TKey key, bool throwException = true)
        {
            var auxiliary = new AuxiliaryValueRW();

            dataReader.OnReadValue(key, auxiliary);

            return(auxiliary.GetDataRW() ??
                   (throwException ? throw new NotSupportedException($"Failed to create data reader-writer of field : '{key}' in {dataReader}.") : default(IDataRW)));
        }
コード例 #3
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)));
        }
コード例 #4
0
ファイル: RWHelper.cs プロジェクト: zhusy09/Swifter.Json
        public static IDataRW CreateItemRW <TKey>(IDataReader <TKey> dataReader, TKey key, bool throwException = true)
        {
            var auxiliary = new AuxiliaryValueRW();

            if (typeof(TKey) == typeof(long) && ((dataReader as IAsDataReader)?.Content ?? dataReader) is IId64DataRW id64DataRW)
            {
                id64DataRW.OnReadValue(Unsafe.As <TKey, long>(ref key), auxiliary);
            }
            else
            {
                dataReader.OnReadValue(key, auxiliary);
            }

            return(auxiliary.GetDataRW() ?? (throwException ? throw new NotSupportedException($"Failed to create data reader-writer of field : '{key}' in {dataReader}.") : default(IDataRW)));
        }