Ejemplo n.º 1
0
        public static IDataWriter CreateWriter <T>(T obj, bool throwException = true)
        {
            var auxiliary = new AuxiliaryValueRW();

            try
            {
                ValueInterface <T> .WriteValue(auxiliary, obj);
            }
            catch (Exception)
            {
            }

            var writer = auxiliary.GetDataWriter();

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

            ValueInterface <T> .ReadValue(auxiliary);

            writer = auxiliary.GetDataWriter();

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

            SetContent(writer, obj);

            return(writer);
        }
Ejemplo n.º 2
0
        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);
        }
Ejemplo n.º 3
0
        public static IDataWriter CreateWriter <T>(T obj)
        {
            var auxiliary = new AuxiliaryValueRW();

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

            var writer = auxiliary.GetDataWriter();

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

            ValueInterface <T> .ReadValue(auxiliary);

            writer = auxiliary.GetDataWriter();

            if (writer == null)
            {
                return(auxiliary.GetDataWriter() ?? throw new NotSupportedException($"Unable create data writer of  '{typeof(T)}'."));
            }

            SetContent(writer, obj);

            return(writer);
        }
Ejemplo n.º 4
0
        public static IDataWriter CreateWriter <T>(bool throwException = true)
        {
            var auxiliary = new AuxiliaryValueRW();

            ValueInterface <T> .ReadValue(auxiliary);

            return(auxiliary.GetDataWriter() ?? (throwException ? throw new NotSupportedException($"Unable create data writer of '{typeof(T)}'.") : default(IDataWriter)));
        }
Ejemplo n.º 5
0
        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)));
        }