Click here to Skip to main content
Click here to Skip to main content
Add your own
alternative version
Go to top

WPF Persistency

, 3 Jan 2013
This article describes how to persist WPF dependency properties
using System;
using System.Reflection;
using System.Diagnostics;

namespace WpfPersist.Demo
{

    /// <summary>
    /// provides access to the configuration system internals. 
    /// implementation has been tested with .NET 2.0 & 4.0.
    /// </summary>
    public sealed class ConfigurationManager
    {
        #region public

        public static ConfigurationManager Instance
        {
            get
            {
                return instance;
            }
        }

		public string ApplicationConfigUri
		{
			get
			{
				return (string)GetProperty();
			}
		}

		public string ExeLocalConfigDirectory
		{
			get
			{
				return (string)GetProperty();
			}
		}

		public string ExeLocalConfigPath
		{
			get
			{
				return (string)GetProperty();
			}
		}

		public string ExeProductName
		{
			get
			{
				return (string)GetProperty();
			}
		}

		public string ExeProductVersion
		{
			get
			{
				return (string)GetProperty();
			}
		}

		public string ExeRoamingConfigDirectory
		{
			get
			{
				return (string)GetProperty();
			}
		}

		public string ExeRoamingConfigPath
		{
			get
			{
				return (string)GetProperty();
			}
		}

		public string MachineConfigPath
		{
			get
			{
				return (string)GetProperty();
			}
		}

		public bool SetConfigurationSystemInProgress
		{
			get
			{
				return (bool)GetProperty();
			}
		}

		public bool SupportsUserConfig
		{
			get
			{
				return (bool)GetProperty();
			}
		}

		public string UserConfigFilename
		{
			get
			{
				return (string)GetProperty();
			}
		}

		#endregion

        #region private

        private ConfigurationManager()
        {
            Type configMgrType = Type.GetType("System.Configuration.Internal.ConfigurationManagerInternal, System.Configuration, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", true);
            configMgrItf = configMgrType.GetInterface("IConfigurationManagerInternal");
            configMgrInstance = Activator.CreateInstance(configMgrType, true);
        }

        private readonly Type configMgrItf;
        private readonly object configMgrInstance;

        private static readonly ConfigurationManager instance = new ConfigurationManager();

        private object GetProperty()
        {
            string propertyName = new StackFrame(1).GetMethod().Name.Substring(4);
            return configMgrItf.GetProperty(propertyName).GetValue(configMgrInstance, null);
        }

        #endregion
	}
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Reto Ravasio

Switzerland Switzerland
No Biography provided

| Advertise | Privacy | Mobile
Web02 | 2.8.140916.1 | Last Updated 3 Jan 2013
Article Copyright 2007 by Reto Ravasio
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid