private static ConfigurationElementTypeAttribute GetAttribute(
            Type databaseType)
        {
            ConfigurationElementTypeAttribute customAttribute = (ConfigurationElementTypeAttribute)Attribute.GetCustomAttribute((MemberInfo)databaseType, typeof(ConfigurationElementTypeAttribute), false);

            if (customAttribute == null)
            {
                throw new InvalidOperationException(string.Format((IFormatProvider)CultureInfo.CurrentCulture, Resources.ExceptionNoConfigurationElementTypeAttribute, (object)databaseType.Name));
            }
            return(customAttribute);
        }
コード例 #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="selectedType"></param>
        /// <returns></returns>
        public bool IsTypeValid(Type selectedType)
        {
            bool valid = false;

            if (includeAllInterfaces && selectedType.IsInterface)
            {
                valid = true;
            }
            else if (selectedType == baseType_)
            {
                valid = includeBaseType;
            }
            else
            {
                valid = baseType_.IsAssignableFrom(selectedType);

                if (valid)
                {
                    if ((!includeAbstractTypes) && (selectedType.IsAbstract || selectedType.IsInterface))
                    {
                        valid = false;
                    }
                }

                if (valid)
                {
                    if (!(selectedType.IsPublic) && !(selectedType.IsNestedPublic) && (!includeNonPublicTypes))
                    {
                        valid = false;
                    }
                }

                if (valid && configurationType != null)
                {
                    object[] configurationElementTypeAttributes = selectedType.GetCustomAttributes(typeof(ConfigurationElementTypeAttribute), true);
                    if (configurationElementTypeAttributes.Length == 0)
                    {
                        valid = false;
                    }
                    else
                    {
                        ConfigurationElementTypeAttribute configElementTypeAttribute = (ConfigurationElementTypeAttribute)configurationElementTypeAttributes[0];
                        if (configurationType != configElementTypeAttribute.ConfigurationType)
                        {
                            valid = false;
                        }
                    }
                }
            }
            return(valid);
        }
コード例 #3
0
        /// <summary>
        /// Adds a new trace listener associated with an unique name and a type containing the implementation.
        /// </summary>
        /// <param name="name">The unique name under which a new trace listener will be added to the collection.</param>
        /// <param name="listenerType">The type implementing the new trace listener.</param>
        public void AddTraceListener(string name, Type listenerType)
        {
            Guard.ArgumentNotNullOrEmptyString(name, "name");
            Guard.ArgumentNotNull(listenerType, "listenerType");

            ConfigurationElementTypeAttribute configElementTypeAttr = FrameworkUtility.GetDeclarativeAttribute <ConfigurationElementTypeAttribute>(listenerType);

            if (configElementTypeAttr != null)
            {
                TraceListenerData listenerData = Activator.CreateInstance(configElementTypeAttr.ConfigurationType) as TraceListenerData;

                if (listenerData != null)
                {
                    listenerData.ListenerDataType = configElementTypeAttr.ConfigurationType;
                    listenerData.Name             = name;
                    listenerData.Type             = listenerType;

                    this.loggingSettings.TraceListeners.Add(listenerData);
                }
            }
        }