Custom configuration section provider for default aspect collection.
Inheritance: System.Configuration.ConfigurationSection
Ejemplo n.º 1
0
 public static DefaultAspectsConfigSection LoadConfigSection()
 {
     try
     {
         DefaultAspectsConfigSection config = (DefaultAspectsConfigSection)ConfigurationManager.GetSection("defaultAspects");
         return(config);
     }
     catch (ConfigurationException)
     {
         // <defaultAspects> section missing in the .config file leads to this exception.
         return(null);
     }
 }
Ejemplo n.º 2
0
        /// <summary>
        ///     Load default aspects from the .config custom section.
        /// </summary>
        /// <returns>Collection of fast aspect rawActivator delegates.</returns>
        public static List <Func <Aspect> > LoadDefaultAspectConfig()
        {
            DefaultAspectsConfigSection config = LoadConfigSection();

            var initializators = new List <Func <Aspect> >();

            if (config != null && !config.DefaultAspects.IsNullOrEmpty())
            {
                foreach (DefaultAspect defaultAspectInfo in config.DefaultAspects)
                {
                    Type   aspectType        = defaultAspectInfo.Type;
                    string constructorParams = defaultAspectInfo.ConstructorParameters;

                    List <string> parms = new List <string>();

                    if (!constructorParams.IsBlank())
                    {
                        parms.Add(constructorParams);
                    }

                    try
                    {
                        object[] constructorArgs = parms.Cast <object>().ToArray();

                        Func <object> rawActivator = aspectType.GetFastActivatorWithEmbeddedArgs(constructorArgs);
                        Func <Aspect> activator    = () => (Aspect)rawActivator();
                        initializators.Add(activator);
                    }
                    catch (Exception ex)
                    {
                        throw new Exception("Failed to create activators for the default set of aspects from .config file. See inner exception information.", ex);
                    }
                }
            }

            return(initializators);
        }