Ejemplo n.º 1
0
        /// <summary>
        /// Writes the current configuration information to an
        /// XML string. String is in .NET XML Serialization format.
        /// </summary>
        /// <returns></returns>
        public virtual string WriteAsString()
        {
            Initialize();

            string xml = string.Empty;

            Provider.EncryptFields(this);

            SerializationUtils.SerializeObject(this, out xml);

            if (!string.IsNullOrEmpty(xml))
            {
                Provider.DecryptFields(this);
            }

            return(xml);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Creates a new instance of the config object and retrieves
        /// configuration information from the provided string. String
        /// should be in XML Serialization format or created by the
        /// <seealso cref="WriteAsString"/> method.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="xml"></param>
        /// <param name="provider">Required if encryption decryption is desired</param>
        /// <returns>config instance or null on failure</returns>
        public static T Read <T>(string xml, IConfigurationProvider provider)
            where T : AppConfiguration, new()
        {
            T result = SerializationUtils.DeSerializeObject(xml, typeof(T)) as T;

            if (result != null && provider != null)
            {
                provider.DecryptFields(result);
            }

            return(result);
        }