Ejemplo n.º 1
0
        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)));
        }
Ejemplo n.º 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)));
        }
Ejemplo n.º 3
0
        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)));
        }
Ejemplo 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)));
        }