Exemplo n.º 1
0
        /// <summary>
        /// Read object state from string.
        /// </summary>
        /// <param name="obj">Object for storing state.</param>
        /// <param name="str">String which contain state of object.</param>
        /// <param name="converter">Object converter which used for writing to string.</param>
        public static void ReadObjectStateFromString(object obj, string str, StiObjectStringConverter converter)
        {
            CultureInfo currentCulture = System.Threading.Thread.CurrentThread.CurrentCulture;

            try
            {
                System.Threading.Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US", false);

                using (StringReader reader = new StringReader(str))
                {
                    StiSerializing sr = new StiSerializing(converter);
                    sr.Deserialize(obj, reader, "State");
                }
            }
            finally
            {
                System.Threading.Thread.CurrentThread.CurrentCulture = currentCulture;
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Object which state will be save to string.
        /// </summary>
        /// <param name="obj">Object which state will be save to string.</param>
        /// <param name="converter">Object converter which used for writing to string.</param>
        /// <returns>String which contain string representation of object.</returns>
        public static string WriteObjectStateToString(object obj, StiObjectStringConverter converter)
        {
            CultureInfo currentCulture = System.Threading.Thread.CurrentThread.CurrentCulture;

            try
            {
                System.Threading.Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US", false);

                StringBuilder sb = new StringBuilder();
                using (StringWriter writer = new StringWriter(sb))
                {
                    StiSerializing sr = new StiSerializing(converter);
                    sr.SortProperties    = false;
                    sr.CheckSerializable = true;
                    sr.Serialize(obj, writer, "State", StiSerializeTypes.SerializeToAll);
                }
                return(sb.ToString());
            }
            finally
            {
                System.Threading.Thread.CurrentThread.CurrentCulture = currentCulture;
            }
        }