Exemplo n.º 1
0
        public static IDataRW CreateRW(object obj)
        {
            if (obj == null)
            {
                throw new ArgumentNullException(nameof(obj));
            }

            var auxiliary = new AuxiliaryValueRW();

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

            return(auxiliary.GetDataRW() ?? throw new NotSupportedException($"Unable create data reader-writer of '{obj.GetType()}'."));
        }
Exemplo n.º 2
0
        public static IDataReader CreateReader(object obj, bool throwException = true)
        {
            if (obj is null)
            {
                throw new ArgumentNullException(nameof(obj));
            }

            var auxiliary = new AuxiliaryValueRW();

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

            return(auxiliary.GetDataReader() ??
                   (throwException ? throw new NotSupportedException($"Unable create data reader of '{obj.GetType()}'.") : default(IDataReader)));
        }
Exemplo n.º 3
0
        /// <summary>
        /// 获取数据写入器中指定键的值的类型。
        /// </summary>
        /// <typeparam name="TKey">键类型</typeparam>
        /// <param name="dataWriter">数据写入器</param>
        /// <param name="key">指定键</param>
        /// <returns>返回一个类型</returns>
        public static Type GetItemType <TKey>(IDataWriter <TKey> dataWriter, TKey key)
        {
            var auxiliary = new AuxiliaryValueRW();

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

            return(auxiliary.GetType());
        }
Exemplo n.º 4
0
        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)));
        }
Exemplo n.º 5
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);
        }
Exemplo n.º 6
0
        public static IDataWriter CreateWriter <T>()
        {
            var auxiliaryValueRW = new AuxiliaryValueRW();

            ValueInterface <T> .Content.ReadValue(auxiliaryValueRW);

            var value = auxiliaryValueRW.read_writer;

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

            return((IDataWriter)value);
        }
Exemplo n.º 7
0
        public static IDataRW CreateRW <T>(T obj)
        {
            var auxiliaryValueRW = new AuxiliaryValueRW();

            ValueInterface <T> .Content.WriteValue(auxiliaryValueRW, obj);

            var value = auxiliaryValueRW.read_writer;

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

            return((IDataRW)value);
        }
Exemplo n.º 8
0
        public static IDataRW CreateItemRW <TKey>(IDataReader <TKey> dataReader, TKey key)
        {
            var auxiliaryValueRW = new AuxiliaryValueRW();

            dataReader.OnReadValue(key, auxiliaryValueRW);

            var value = auxiliaryValueRW.read_writer;

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

            return((IDataRW)value);
        }
Exemplo n.º 9
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);
        }