GetSection() публичный Метод

public GetSection ( string sectionName ) : object
sectionName string
Результат object
Пример #1
0
 /// <summary>
 /// Registers WCF services type mappings from the given configuration excluding specified endpoints if needed.
 /// </summary>
 public static IServiceCollection AddWcfServices(this IServiceCollection container, ContextInformation ctx, Func<ServiceEndpointElement, bool> exclEndpoints)
 {
     String servicesPath = "system.serviceModel/services";
     ServicesSection services = (ServicesSection)(ctx != null ? ctx.GetSection(servicesPath) : ConfigurationManager.GetSection(servicesPath));
     foreach (ServiceElement service in services.Services)
     {
         Type serviceType = GetType(service.Name);
         if (serviceType == null) continue;
         foreach (ServiceEndpointElement endpoint in service.Endpoints)
         {
             Type contractType = GetType(endpoint.Contract);
             if (contractType == null || endpoint.IsSystemEndpoint || exclEndpoints != null && exclEndpoints(endpoint)) continue;
             container.AddScoped(contractType, serviceType);
         }
     }
     return container;
 }
Пример #2
0
 /// <summary>
 /// Registers WCF client type mappings from the given configuration excluding specified endpoints if needed.
 /// </summary>
 public static IServiceCollection AddWcfClientServices(this IServiceCollection container, ContextInformation ctx, Func<ChannelEndpointElement, bool> exclEndpoints)
 {
     String clientPath = "system.serviceModel/client";
     ClientSection client = (ClientSection)(ctx != null ? ctx.GetSection(clientPath) : ConfigurationManager.GetSection(clientPath));
     foreach (ChannelEndpointElement endpoint in client.Endpoints)
     {
         if (endpoint.Name == null || endpoint.Contract == null || exclEndpoints != null && exclEndpoints(endpoint)) continue;
         Type contractType = GetType(endpoint.Contract);
         Type factoryType = ctx != null ?
             typeof(ConfigurationChannelFactory<>).MakeGenericType(contractType) :
             typeof(ChannelFactory<>).MakeGenericType(contractType);
         container.AddSingleton(factoryType, sp => ctx == null ? Activator.CreateInstance(factoryType, endpoint.Name) :
             Activator.CreateInstance(factoryType, endpoint.Name, ctx, null));
         container.AddScoped(contractType, sp => factoryType.InvokeMember("CreateChannel", BindingFlags.InvokeMethod, null,
             sp.GetService(factoryType), new object[] { }));
     }
     return container;
 }
 internal static object GetAssociatedSection(ContextInformation evalContext, string sectionPath)
 {
     object section = null;
     if (evalContext != null)
     {
         section = evalContext.GetSection(sectionPath);
     }
     else
     {
         section = AspNetEnvironment.Current.GetConfigurationSection(sectionPath);
         if (DiagnosticUtility.ShouldTraceVerbose)
         {
             TraceUtility.TraceEvent(TraceEventType.Verbose, 0x80024, System.ServiceModel.SR.GetString("TraceCodeGetConfigurationSection"), new StringTraceRecord("ConfigurationSection", sectionPath), null, null);
         }
     }
     if (section == null)
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ConfigurationErrorsException(System.ServiceModel.SR.GetString("ConfigSectionNotFound", new object[] { sectionPath })));
     }
     return section;
 }
 internal static object UnsafeGetSectionFromContext(ContextInformation evalContext, string sectionPath)
 {
     return evalContext.GetSection(sectionPath);
 }
        /// Be sure to update UnsafeGetAssociatedSection if you modify this method
        internal static object GetAssociatedSection(ContextInformation evalContext, string sectionPath)
        {
            object retval = null;
            if (evalContext != null)
            {
                retval = evalContext.GetSection(sectionPath);
            }
            else
            {
                retval = AspNetEnvironment.Current.GetConfigurationSection(sectionPath);

                // Trace after call to underlying configuration system to
                // insure that configuration system is initialized
                if (DiagnosticUtility.ShouldTraceVerbose)
                {
                    TraceUtility.TraceEvent(TraceEventType.Verbose, TraceCode.GetConfigurationSection,
                        SR.GetString(SR.TraceCodeGetConfigurationSection),
                        new StringTraceRecord("ConfigurationSection", sectionPath), null, null);
                }
            }
            if (retval == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(
                    new ConfigurationErrorsException(SR.GetString(SR.ConfigSectionNotFound,
                    sectionPath)));
            }
            return retval;
        }