关于C#Section配置未初始化的问题
https://www.cnblogs.com/lxshwyan/p/10828305.html
如果使用了configSection节点,则configSection必须位于根节点的第0个。App.config中代码如下:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<section name="CustomerSingleConfig" type="ConfiguraDemo.CustomerSingleConfig,ConfiguraDemo"/>
</configSections>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />
</startup>
<CustomerSingleConfig PlatChName="监控平台系统" PlatEnName="Monitoring platform system"></CustomerSingleConfig>
</configuration>
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Text;
using System.Threading.Tasks; namespace ConfiguraDemo
{
public class CustomerSingleConfig : ConfigurationSection
{
/// <summary>
/// 获取配置信息
/// </summary>
/// <returns></returns>
public static CustomerSingleConfig GetConfig()
{
return GetConfig("CustomerSingleConfig");
}
private static CustomerSingleConfig GetConfig(string sectionName)
{
try
{
CustomerSingleConfig section = (CustomerSingleConfig)ConfigurationManager.GetSection(sectionName);
if (section == null)
throw new ConfigurationErrorsException("Section " + sectionName + " is not found.");
return section;
}
catch (Exception ex)
{
throw new ConfigurationErrorsException("Section " + ex.Message);
}
} /// <summary>
/// 平台中文名称
/// </summary>
[ConfigurationProperty("PlatChName", DefaultValue = "", IsRequired = true, IsKey = false)]
public string PlatChineseName
{
get { return (string)this["PlatChName"]; }
set { this["PlatChName"] = value; }
}
/// <summary>
/// 平台英文名称
/// </summary>
[ConfigurationProperty("PlatEnName", DefaultValue = "", IsRequired = true, IsKey = false)]
public string PlatEnglishName
{
get { return (string)this["PlatEnName"]; }
set { this["PlatEnName"] = value; }
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks; namespace ConfiguraDemo
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("---------------------单级配置节点测试-----------------");
Console.WriteLine("PlatChName:" + CustomerSingleConfig.GetConfig().PlatChineseName);
Console.WriteLine("PlatEnName:" + CustomerSingleConfig.GetConfig().PlatEnglishName);
Console.ReadKey();
}
}
}
输出结果
---------------------单级配置节点测试-----------------
PlatChName:监控平台系统
PlatEnName:Monitoring platform system
继承ConfigurationSection需要添加System.Configuration引用
关于C#Section配置未初始化的问题的更多相关文章
- C#异常断电后重新启动项目出现配置未初始化错误
		
转到如截图中所示路径,将其下的数据删掉,就可以启动了.
 - C语言全局未初始化数据段分析
		
前言: 在分析C语言全局未初始化变量时,发现在目标文件中全局未初始化变量并不是直接放在bss段中. 再后来发现在两个.c文件中定义同名的全局变量,链接时居然没有发生符号重定义错误.才知道C语言弱定义的 ...
 - 让Spring Boot项目启动时可以根据自定义配置决定初始化哪些Bean
		
让Spring Boot项目启动时可以根据自定义配置决定初始化哪些Bean 问题描述 实现思路 思路一 [不符合要求] 思路二[满足要求] 思路三[未试验] 问题描述 目前我工作环境下,后端主要的框架 ...
 - 三叔学FPGA系列之二:Cyclone V中的POR、配置、初始化,以及复位
		
对于FPGA内部的复位,之前一直比较迷,这两天仔细研究官方数据手册,解开了心中的诸多疑惑,感觉自己又进步了呢..... 原创不易,转载请转原文,注明出处,谢谢. 一.关于POR(Power-On ...
 - springboot hikari 连接池 在启动时未初始化数据库连接问题
		
在启动Springboot 项目时 2019-11-18 21:32:38.223 INFO 1080 --- [on(4)-127.0.0.1] o.s.web.servlet.Dispatcher ...
 - mybatis源码分析--如何加载配置及初始化
		
简介 Mybatis 是一个持久层框架,它对 JDBC 进行了高级封装,使我们的代码中不会出现任何的 JDBC 代码,另外,它还通过 xml 或注解的方式将 sql 从 DAO/Repository ...
 - C++中未初始化的bool值的问题
		
原创文件,欢迎阅读,禁止转载. 问题描述 你见过一个这样的bool值吗,判断 var 和 !var 都是成立的,今天被我遇到了,是在一个坑里遇到的.今天调试了一个程序,发送一个网络消息,结果总是得不到 ...
 - c语言中较常见的由内存分配引起的错误_内存越界_内存未初始化_内存太小_结构体隐含指针
		
1.指针没有指向一块合法的内存 定义了指针变量,但是没有为指针分配内存,即指针没有指向一块合法的内浅显的例子就不举了,这里举几个比较隐蔽的例子. 1.1结构体成员指针未初始化 struct stude ...
 - void指针、NULL指针和未初始化指针
		
一个指针可以被声明为void类型,比如void *x.一个指针可以被赋值为NULL.一个指针变量声明之后但没有被赋值,叫做未初始化指针. 1 2 3 4 5 6 7 8 9 10 11 12 13 1 ...
 
随机推荐
- 【unity游戏入门】1 环境安装
			
作者 罗芭Remoo 2021年9月24日 这一个系列随笔记录如何使用unity引擎从零开始开发游戏,软件版本均使用最新版本 有关unity的背景介绍可以通过unity官网https://unity. ...
 - MPI学习笔记(三):矩阵相乘的分块并行(行列划分法)
			
mpi矩阵乘法:C=αAB+βC 一.主从模式的行列划分并行法 1.实现方法 将可用于计算的进程数comm_sz分解为a*b,然后将矩阵A全体行划分为a个部分,将矩阵B全体列划分为b个部分,从而将整个 ...
 - 巧用 transition 实现短视频 APP 点赞动画
			
在各种短视频界面上,我们经常会看到类似这样的点赞动画: 非常的有意思,有意思的交互会让用户更愿意进行互动. 那么,这么有趣的点赞动画,有没有可能使用纯 CSS 实现呢?那当然是必须的,本文,就将巧妙的 ...
 - 第二章 Kubernetes快速入门
			
一.四组基本概念 Pod/Pod控制器: Name/Namespace: Label/Label选择器: Service/Ingress. 二.Pod/Pod控制器 2.1 Pod Pod是K8S里能 ...
 - SpringBoot_事务总结
			
Springboot 事务 1. 打印SQL 日志的两种配置方式 [1]通过配置包的log等级来打印SQL日志,但这种不会打印出事务日志 logging.level.com.grady.mybatis ...
 - flink-cdc实时同步mysql数据到elasticsearch
			
本文首发于我的个人博客网站 等待下一个秋-Flink 什么是CDC? CDC是(Change Data Capture 变更数据获取)的简称.核心思想是,监测并捕获数据库的变动(包括数据 或 数据表的 ...
 - 使用PBIS将Linux加入域
			
 使用PBIS将Linux加入域 很多企业已经部署的微软的活动目录,为了方便管理,可以把Linux加入域.网上流传了很多把Linux加入域的方法,感觉比较复杂,并且似乎并没有真正的加入域.只是完成 ...
 - Elasticsearch:使用 Nginx 来保护 Elastic Stack
			
文章转载自:https://elasticstack.blog.csdn.net/article/details/112213364
 - 使用Docker方式部署Mongodb多副本集(replSet)
			
linux主机ip:192.168.0.253 1. 创建网络与容器 docker pull mongo docker network create mongo-rs docker run --nam ...
 - 分布式存储系统之Ceph集群状态获取及ceph配置文件说明
			
前文我们了解了Ceph的访问接口的启用相关话题,回顾请参考https://www.cnblogs.com/qiuhom-1874/p/16727620.html:今天我们来聊一聊获取ceph集群状态和 ...