System.Configuration.TypeUtil.VerifyAssignableType C# (CSharp) Метод

VerifyAssignableType() статический приватный Метод

static private VerifyAssignableType ( Type baseType, Type type, bool throwOnError ) : Type
baseType System.Type
type System.Type
throwOnError bool
Результат System.Type
        static internal Type VerifyAssignableType(Type baseType, Type type, bool throwOnError) {
            if (baseType.IsAssignableFrom(type)) {
                return type;
            }

            if (throwOnError) {
                throw new TypeLoadException(
                    SR.GetString(SR.Config_type_doesnt_inherit_from_type, type.FullName, baseType.FullName));
            }

            return null;
        }

Usage Example

Пример #1
0
            private void Init(RuntimeConfigurationRecord configRecord, FactoryRecord factoryRecord)
            {
                // Get the type of the factory
                Type type = TypeUtil.GetType(configRecord.Host, factoryRecord.FactoryTypeName,
                                             true);

                // If the type is a ConfigurationSection, that's the type.
                if (typeof(ConfigurationSection).IsAssignableFrom(type))
                {
                    _sectionCtor = TypeUtil.GetConstructor(type, typeof(ConfigurationSection),
                                                           true);
                }
                else
                {
                    // Note: in v1, IConfigurationSectionHandler is in effect a factory that has a Create method
                    // that creates the real section object.

                    // throws if type does not implement IConfigurationSectionHandler
                    TypeUtil.VerifyAssignableType(typeof(IConfigurationSectionHandler), type, true);

                    // Create an instance of the handler
                    _sectionHandler =
                        (IConfigurationSectionHandler)TypeUtil.CreateInstance(type);
                }
            }