System.Configuration.MgmtConfigurationRecord.GetSectionGroup C# (CSharp) Method

GetSectionGroup() private method

private GetSectionGroup ( string configKey ) : ConfigurationSectionGroup
configKey string
return ConfigurationSectionGroup
        internal ConfigurationSectionGroup GetSectionGroup(string configKey) {
            ConfigurationSectionGroup configSectionGroup = LookupSectionGroup(configKey);
            if (configSectionGroup == null) {
                BaseConfigurationRecord configRecord;
                FactoryRecord factoryRecord = FindFactoryRecord(configKey, false, out configRecord);
                if (factoryRecord == null) {
                    return null;
                }

                if (!factoryRecord.IsGroup) {
                    throw ExceptionUtil.ParameterInvalid("sectionGroupName");
                }

                if (factoryRecord.FactoryTypeName == null) {
                    //
                    // If no type is defined for the section group, return a base ConfigurationSectionGroup.
                    // For example: 
                    //  <configSections>
                    //      <sectionGroup name="mySectionGroup" />
                    //  </configSections>
                    // 
                    configSectionGroup = new ConfigurationSectionGroup();
                }
                else {
                    //
                    // Create the section group of the desired type.
                    // For example: 
                    //  <configSections>
                    //      <sectionGroup name="mySectionGroup" type="MySectionGroupType, acme" />
                    //  </configSections>
                    //
                    ConstructorInfo ctor = EnsureSectionGroupFactory(factoryRecord);

                    try {
                        configSectionGroup = (ConfigurationSectionGroup) TypeUtil.InvokeCtorWithReflectionPermission(ctor);
                    }
                    catch (Exception e) {
                        throw new ConfigurationErrorsException(SR.GetString(SR.Config_exception_creating_section_handler, factoryRecord.ConfigKey), 
                                e, factoryRecord);
                    }
                    catch {
                        throw new ConfigurationErrorsException(SR.GetString(SR.Config_exception_creating_section_handler, factoryRecord.ConfigKey), 
                                factoryRecord);
                    }
                }

                configSectionGroup.AttachToConfigurationRecord(this, factoryRecord);

                // Add it to the collection
                SectionGroups[configKey] = configSectionGroup;
            }

            return configSectionGroup;
        }