예제 #1
0
            /// <summary>
            /// Attempts to deserialize an a byte array to an object of a given type.
            /// </summary>
            public static KnownException TryDeserialize <T>(byte[] dataIn, out T obj)
            {
                KnownException exception = null;

                obj = default(T);

                try
                {
                    obj = MyAPIGateway.Utilities.SerializeFromBinary <T>(dataIn);
                }
                catch (Exception e)
                {
                    exception = new KnownException($"IO Error. Failed to deserialize to {typeof(T).Name}.", e);
                }

                return(exception);
            }
예제 #2
0
            /// <summary>
            /// Attempts to deserialize an Xml string to an object of a given type.
            /// </summary>
            public static KnownException TryDeserialize <T>(string xmlIn, out T obj)
            {
                KnownException exception = null;

                obj = default(T);

                try
                {
                    obj = MyAPIGateway.Utilities.SerializeFromXML <T>(xmlIn);
                }
                catch (Exception e)
                {
                    exception = new KnownException("IO Error. Unable to interpret XML.", e);
                }

                return(exception);
            }
예제 #3
0
            /// <summary>
            /// Attempts to serialize an object to a byte array.
            /// </summary>
            public static KnownException TrySerialize <T>(T obj, out byte[] dataOut)
            {
                KnownException exception = null;

                dataOut = null;

                try
                {
                    dataOut = MyAPIGateway.Utilities.SerializeToBinary(obj);
                }
                catch (Exception e)
                {
                    exception = new KnownException($"IO Error. Failed to generate binary from {typeof(T).Name}.", e);
                }

                return(exception);
            }
예제 #4
0
            /// <summary>
            /// Attempts to serialize an object to an Xml string.
            /// </summary>
            public static KnownException TrySerialize <T>(T obj, out string xmlOut)
            {
                KnownException exception = null;

                xmlOut = null;

                try
                {
                    xmlOut = MyAPIGateway.Utilities.SerializeToXML(obj);
                }
                catch (Exception e)
                {
                    exception = new KnownException("IO Error. Failed to generate XML.", e);
                }

                return(exception);
            }