当前位置: 首页>>代码示例>>C#>>正文


C# ConfigurationElement.GetType方法代码示例

本文整理汇总了C#中System.Configuration.ConfigurationElement.GetType方法的典型用法代码示例。如果您正苦于以下问题:C# ConfigurationElement.GetType方法的具体用法?C# ConfigurationElement.GetType怎么用?C# ConfigurationElement.GetType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Configuration.ConfigurationElement的用法示例。


在下文中一共展示了ConfigurationElement.GetType方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ReadConfigurationElement

        private static IEnumerable<Argument> ReadConfigurationElement(ConfigurationElement element)
        {
            var arguments = new List<Argument>();

            var collection = element as ConfigurationElementCollection;

            if (collection != null)
            {
                foreach (ConfigurationElement child in collection)
                {
                    arguments.AddRange(ReadConfigurationElement(child));
                }
            }
            else
            {
                foreach (PropertyInfo property in element.GetType().GetProperties())
                {
                    object propertyValue = property.GetValue(element, null);

                    if (typeof (ConfigurationElement).IsAssignableFrom(property.PropertyType))
                    {
                        arguments.AddRange(ReadConfigurationElement((ConfigurationElement) propertyValue));
                    }

                    var argument = new Argument(property, propertyValue);
                    if (argument.Include())
                    {
                        arguments.Add(argument);
                    }
                }
            }
            return arguments;
        }
开发者ID:JontyMC,项目名称:EventStoreService,代码行数:33,代码来源:InstanceStrategy.cs

示例2: AutoConfigurationHelper

        internal AutoConfigurationHelper(ConfigurationElement element, Action<ConfigurationProperty, object> valueSetter, Func<ConfigurationProperty, object> valueGetter)
        {
            _ConfigElement = element;
            _ValueSetter = valueSetter;
            _ValueGetter = valueGetter;

            var type = element.GetType();
            Dictionary<ConfigurationProperty, PropertyInfo> properties;
            if (!_TypeProperties.TryGetValue(type, out properties))
            {
                properties = new Dictionary<ConfigurationProperty, PropertyInfo>();
                foreach (var member in type.GetProperties())
                {
                    var configField = member.GetCustomAttributes(typeof(ConfigurationPropertyAttribute), true).Cast<ConfigurationPropertyAttribute>().FirstOrDefault();
                    if (configField != null)
                    {
                        var property = new ConfigurationProperty(configField.Name, member.PropertyType, configField.DefaultValue, ConfigurationPropertyOptions.None);
                        properties[property] = member;
                    }
                }
                _TypeProperties.TryAdd(type, properties);
            }
            _Properties = properties;

            // Pre-initialize properties of type ConfigurationElement, or things go boom
            foreach (var property in _Properties)
            {
                if (typeof(ConfigurationElement).IsAssignableFrom(property.Value.PropertyType))
                    property.Value.SetValue(_ConfigElement, _ValueGetter(property.Key), null);
            }
        }
开发者ID:marcosb,项目名称:CommonCore,代码行数:31,代码来源:AutoConfigurationSection.cs

示例3: Register

        public void Register(ConfigurationElement element, Type @interface)
        {
            var type = element.GetType();

            if (ClassAlreadyRegistered(type))
                return;

            Register(element, new ConfigurationPropertyCollection(@interface, type).ToArray());
        }
开发者ID:miensol,项目名称:SimpleConfigSections,代码行数:9,代码来源:ConfigurationElementRegistrar.cs

示例4: Register

 protected override void Register(ConfigurationElement element, params ConfigurationProperty[] configurationProperties)
 {
     var ownerType = element.GetType();
     var properties = (SC.ConfigurationPropertyCollection)PropertyBagAccessor[ownerType];
     if (properties == null)
     {
         properties = new SC.ConfigurationPropertyCollection();
         PropertyBagAccessor[ownerType] = properties;
     }
     configurationProperties.ToList().ForEach(x => properties.Add(x));
 }
开发者ID:miensol,项目名称:SimpleConfigSections,代码行数:11,代码来源:ConfigurationElementRegistrar.DotNet.cs

示例5: Register

            protected override void Register(ConfigurationElement element, params ConfigurationProperty[] configurationProperties)
            {
                lock (ElementMaps)
                {
                    var ownerType = element.GetType();
                    var map = ElementMaps[ownerType];
                    if (map == null)
                    {
                        map = ElementMaps[ownerType] = ElementMapCreator(ownerType);
                    }
                    var properties = ElementMapPropertiesAccesor.GetValue(map) as SC.ConfigurationPropertyCollection;
                    if (properties == null)
                    {
                        properties = new SC.ConfigurationPropertyCollection();
                    }
                    ElementMapPropertiesAccesor.SetValue(map, properties);

                    configurationProperties.ToList().ForEach(x => properties.Add(x));

                    var einfo = ElementInformationConstructor(element);
                    ElementInformationAccessor.SetValue(element, einfo);
                }
            }
开发者ID:miensol,项目名称:SimpleConfigSections,代码行数:23,代码来源:ConfigurationElementRegistrar.Mono.cs

示例6: GetElementKey

		/// <summary>
		/// Gets the element key for a mimeType element that uniquely identifies it. 
		/// </summary>
		/// <param name="element">The <see cref="ConfigurationElement" /> to return the key for. </param>
		/// <returns>An Object that acts as the key for the specified <see cref="ConfigurationElement" />.</returns>
		/// <exception cref="System.ArgumentException">Thrown when the element parameter is not of type
		/// <see cref="MimeType" />.</exception>
		protected override object GetElementKey(ConfigurationElement element)
		{
			MimeType mimeType = element as MimeType;

			if (mimeType == null)
			{
				throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, Resources.Global_GetElementKey_Ex_Msg, typeof(MimeType).ToString(), element.GetType().ToString()));
			}

			return String.Concat(mimeType.FileExtension, "|", mimeType.BrowserId);
		}
开发者ID:haimon74,项目名称:KanNaim,代码行数:18,代码来源:Configuration.cs

示例7: GetElementKey

        /// <summary>
        /// Retrieves a key of a given element.
        /// </summary>
        /// <param name="element">Element whose key to retrieve.</param>
        /// <returns>A key of a given element.</returns>
        protected override object GetElementKey(ConfigurationElement element)
        {
            object ret = null;

            if (element != null && Type.Equals(element.GetType(), typeof(CultureConfiguration)))
                ret = ((CultureConfiguration)element).CultureName;

            return ret;
        }
开发者ID:volpav,项目名称:toprope,代码行数:14,代码来源:CultureConfigurationCollection.cs

示例8: GetTagForExtensionElement

            public string GetTagForExtensionElement(ConfigurationElement element)
            {
                Type elementType = element.GetType();

                Dictionary<string, Type> dictToSearch = GetDictToSearch(elementType);

                foreach(var keyValue in dictToSearch)
                {
                    if (keyValue.Value == elementType)
                    {
                        return keyValue.Key;
                    }
                }

                throw ElementTypeNotFound(elementType);
            }
开发者ID:jorgeds001,项目名称:CodeSamples,代码行数:16,代码来源:ExtensionElementMap.cs

示例9: SetIsPresent

 internal static void SetIsPresent(ConfigurationElement element)
 {
     // Work around for VSW 578830: ConfigurationElements that override DeserializeElement cannot set ElementInformation.IsPresent
     PropertyInfo elementPresent = element.GetType().GetProperty("ElementPresent", BindingFlags.Instance | BindingFlags.NonPublic);
     SetIsPresentWithAssert(elementPresent, element, true);
 }
开发者ID:krytht,项目名称:DotNetReferenceSource,代码行数:6,代码来源:ConfigurationHelpers.cs

示例10: ValidateElement

 internal static void ValidateElement(ConfigurationElement elem, ConfigurationValidatorBase propValidator, bool recursive)
 {
     ConfigurationValidatorBase validator = propValidator;
     if ((validator == null) && (elem.ElementProperty != null))
     {
         validator = elem.ElementProperty.Validator;
         if ((validator != null) && !validator.CanValidate(elem.GetType()))
         {
             throw new ConfigurationErrorsException(System.Configuration.SR.GetString("Validator_does_not_support_elem_type", new object[] { elem.GetType().Name }));
         }
     }
     try
     {
         if (validator != null)
         {
             validator.Validate(elem);
         }
     }
     catch (ConfigurationException)
     {
         throw;
     }
     catch (Exception exception)
     {
         throw new ConfigurationErrorsException(System.Configuration.SR.GetString("Validator_element_not_valid", new object[] { elem._elementTagName, exception.Message }));
     }
     if (recursive)
     {
         if ((elem is ConfigurationElementCollection) && (elem is ConfigurationElementCollection))
         {
             IEnumerator elementsEnumerator = ((ConfigurationElementCollection) elem).GetElementsEnumerator();
             while (elementsEnumerator.MoveNext())
             {
                 ValidateElement((ConfigurationElement) elementsEnumerator.Current, null, true);
             }
         }
         for (int i = 0; i < elem.Values.Count; i++)
         {
             ConfigurationElement element = elem.Values[i] as ConfigurationElement;
             if (element != null)
             {
                 ValidateElement(element, null, true);
             }
         }
     }
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:46,代码来源:ConfigurationElement.cs

示例11: FillConfiguration

        private static void FillConfiguration(ConfigurationElement sectionElement, XElement rootElement)
        {
            var sectionType = sectionElement.GetType();

            foreach (var property in sectionType.GetProperties())
            {
                var configPropertyAttribute = property.GetCustomAttribute<ConfigurationPropertyAttribute>();

                if (configPropertyAttribute == null)
                {
                    continue;
                }

                var propertyElement = rootElement.Element(configPropertyAttribute.Name);

                if (typeof(ConfigurationElementCollection).IsAssignableFrom(property.PropertyType))
                {
                    var addMethod = property.PropertyType.GetMethod("Add", new Type[] { typeof(ConfigurationElement) });

                    if (addMethod == null)
                    {
                        return;
                    }

                    var configurationCollectionAttribute = property.GetCustomAttribute<ConfigurationCollectionAttribute>();

                    var elementCollection = (ConfigurationElementCollection)property.GetValue(sectionElement);

                    var subElementName = string.IsNullOrEmpty(configurationCollectionAttribute.AddItemName) ? "add" : configurationCollectionAttribute.AddItemName;

                    foreach (var subElement in propertyElement.Elements(subElementName))
                    {
                        var elementInstance = (ConfigurationElement)configurationCollectionAttribute.ItemType.GetConstructor(new Type[] { }).Invoke(new object[] { });
                        FillConfiguration(elementInstance, subElement);
                        addMethod.Invoke(elementCollection, new object[] { elementInstance });
                    }

                }
                else if (typeof(ConfigurationElement).IsAssignableFrom(property.PropertyType))
                {
                    var elementInstance = (ConfigurationElement)property.GetValue(sectionElement);

                    FillConfiguration(elementInstance, propertyElement);
                }
                else
                {
                    object value = null;
                    if (propertyElement != null)
                    {
                        value = propertyElement.Value;
                    }
                    else
                    {
                        var attribute = rootElement.Attribute(configPropertyAttribute.Name);
                        if (attribute != null)
                        {
                            value = attribute.Value;
                        }
                        else
                        {
                            continue;
                        }
                    }

                    if (value != null)
                    {
                        var stringValue = value.ToString();
                        if (property.PropertyType.IsEnum)
                        {
                            property.SetValue(sectionElement, Enum.Parse(property.PropertyType, stringValue));
                        }
                        else if (property.PropertyType == typeof(int))
                        {
                            property.SetValue(sectionElement, int.Parse(stringValue));
                        }
                        else
                        {
                            property.SetValue(sectionElement, stringValue);
                        }
                    }
                }
            }
        }
开发者ID:cgoconseils,项目名称:XrmFramework,代码行数:83,代码来源:ConfigHelper.cs

示例12: ValidateElement

        internal static void ValidateElement(ConfigurationElement elem, ConfigurationValidatorBase propValidator, bool recursive) {
            // Validate a config element with the per-type validator when a per-property ( propValidator ) is not supplied
            // or with the per-prop validator when the element ( elem ) is a child property of another configuration element

            ConfigurationValidatorBase validator = propValidator;

            if ((validator == null) &&   // Not a property - use the per-type validator
                (elem.ElementProperty != null)) {
                validator = elem.ElementProperty.Validator;

                // Since ElementProperty can be overriden by derived classes we need to make sure that
                // the validator supports the type of elem every time
                if ((validator != null) && !validator.CanValidate(elem.GetType())) {
                    throw new ConfigurationErrorsException(SR.GetString(SR.Validator_does_not_support_elem_type, elem.GetType().Name));
                }
            }

            try {
                if (validator != null) {
                    validator.Validate(elem);
                }
            }
            catch (ConfigurationException) {
                // ConfigurationElement validators are allowed to throw ConfigurationErrorsException. 
                throw;
            }
            catch (Exception ex) {
                throw new ConfigurationErrorsException(SR.GetString(SR.Validator_element_not_valid, elem._elementTagName, ex.Message));
            }
            catch {
                throw new ConfigurationErrorsException(SR.GetString(SR.Validator_element_not_valid, elem._elementTagName, ExceptionUtil.NoExceptionInformation));
            }

            if (recursive == true) {
                if (elem is ConfigurationElementCollection) {
                    if (elem is ConfigurationElementCollection) {
                        IEnumerator it = ((ConfigurationElementCollection)elem).GetElementsEnumerator();
                        while( it.MoveNext() ) {
                            ValidateElement((ConfigurationElement)it.Current, null, true);
                        }
                    }   
                }
                
                // Validate all child elements recursively
                for (int index = 0; index < elem.Values.Count; index++) {
                    ConfigurationElement value = elem.Values[index] as ConfigurationElement;

                    if (value != null) {
                        // Run the per-type validator on the child element and proceed with validation in subelements
                        // Note we dont run the per-property validator here since we run those when the property value is set
                        ValidateElement(value, null, true);              // per-type
                    }
                }
            }
        }
开发者ID:gbarnett,项目名称:shared-source-cli-2.0,代码行数:55,代码来源:configurationelement.cs

示例13: ElementIsModified

		bool ElementIsModified (ConfigurationElement element)
		{
			return (bool) element.GetType ().GetMethod ("IsModified", BindingFlags.NonPublic | BindingFlags.Instance).Invoke (element, new object [0]);
		}
开发者ID:BrzVlad,项目名称:mono,代码行数:4,代码来源:SettingValueElement.cs

示例14: ValidateElement

        internal static void ValidateElement(ConfigurationElement elem, ConfigurationValidatorBase propValidator,
            bool recursive)
        {
            // Validate a config element with the per-type validator when a per-property ( propValidator ) is not supplied
            // or with the per-prop validator when the element ( elem ) is a child property of another configuration element

            ConfigurationValidatorBase validator = propValidator;

            if ((validator == null) && // Not a property - use the per-type validator
                (elem.ElementProperty != null))
            {
                validator = elem.ElementProperty.Validator;

                // Since ElementProperty can be overriden by derived classes we need to make sure that
                // the validator supports the type of elem every time
                if ((validator != null) && !validator.CanValidate(elem.GetType()))
                {
                    throw new ConfigurationErrorsException(string.Format(SR.Validator_does_not_support_elem_type,
                        elem.GetType().Name));
                }
            }

            try
            {
                validator?.Validate(elem);
            }
            catch (ConfigurationException)
            {
                // ConfigurationElement validators are allowed to throw ConfigurationErrorsException.
                throw;
            }
            catch (Exception ex)
            {
                throw new ConfigurationErrorsException(string.Format(SR.Validator_element_not_valid, elem.ElementTagName,
                    ex.Message));
            }

            if (recursive)
            {
                // Validate collection items:
                // Note: this is a bit of a hack - we will exploit the fact that this method is called with recursive == true only when serializing the top level section
                // At deserializtion time the per-element validator for collection items will get executed as part of their deserialization logic
                // However we dont perform validation in the serialization logic ( because at that time the object is unmerged and not all data is present )
                // so we have to do that validation here.
                if (elem is ConfigurationElementCollection)
                {
                    IEnumerator it = ((ConfigurationElementCollection)elem).GetElementsEnumerator();
                    while (it.MoveNext()) ValidateElement((ConfigurationElement)it.Current, null, true);
                }

                // Validate all child elements recursively
                for (int index = 0; index < elem.Values.Count; index++)
                {
                    ConfigurationElement value = elem.Values[index] as ConfigurationElement;

                    if (value != null)
                    {
                        // Run the per-type validator on the child element and proceed with validation in subelements
                        // Note we dont run the per-property validator here since we run those when the property value is set
                        ValidateElement(value, null, true); // per-type
                    }
                }
            }
        }
开发者ID:chcosta,项目名称:corefx,代码行数:64,代码来源:ConfigurationElement.cs

示例15: MergeBasedOnConfig

        private void MergeBasedOnConfig(XElement mergedElement, XElement partElement, ConfigurationElement configElement)
        {
            var defaultCollectionProperty = configElement.GetType()
                .GetProperties()
                .FirstOrDefault(p =>
                                    {
                                        var attr =
                                            (ConfigurationPropertyAttribute)
                                            Attribute.GetCustomAttribute(p, typeof (ConfigurationPropertyAttribute));
                                        return attr!=null && attr.IsDefaultCollection;
                                    });
            if (defaultCollectionProperty != null)
            {
                var configCollectionAttribute = (ConfigurationCollectionAttribute)Attribute.GetCustomAttribute(defaultCollectionProperty.PropertyType,
                                                                                                            typeof (ConfigurationCollectionAttribute));
                if (configCollectionAttribute != null)
                {
                    var keyProperty = configCollectionAttribute.ItemType.GetProperties()
                        .Select(p => new
                                         {
                                             Property = p,
                                             Attribute = (ConfigurationPropertyAttribute)
                                                         Attribute.GetCustomAttribute(p,
                                                                                      typeof (
                                                                                          ConfigurationPropertyAttribute
                                                                                          ))
                                         })
                        .FirstOrDefault(p => p.Attribute != null && p.Attribute.IsKey);

                    if (keyProperty != null)
                    {
                        MergeAttributes(mergedElement, partElement);

                        var mergedElements = mergedElement.Nodes().OfType<XElement>().ToList();

                        foreach (var partChildElement in partElement.Nodes().OfType<XElement>())
                        {
                            var key = partChildElement.Attributes()
                                .FirstOrDefault(
                                    a =>
                                    a.Name.LocalName.Equals(keyProperty.Attribute.Name,
                                                            StringComparison.OrdinalIgnoreCase));
                            if (key == null)
                                continue;

                            var mergedChildElement = mergedElements
                                .FirstOrDefault(e =>
                                                    {
                                                        var keyAttribute = e.Attribute(key.Name);
                                                        return keyAttribute != null && key.Value.Equals(keyAttribute.Value);
                                                    });

                            if (mergedChildElement != null)
                                mergedElements.Remove(mergedChildElement);
                            mergedElements.Add(partChildElement);
                        }

                        mergedElement.ReplaceNodes(mergedElements);
                        return;
                    }
                }
            }

            // TODO: actually, we should dig into each ConfigurationElement, but we'll skip it for now
            MergeAsRawXml(mergedElement, partElement);
        }
开发者ID:ayezutov,项目名称:NDistribUnit,代码行数:66,代码来源:ConfigurationFileMerger.cs


注:本文中的System.Configuration.ConfigurationElement.GetType方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。