.net 开发 配置文件的灵活使用
来源:互联网 发布:北京联合大学网络排名 编辑:程序博客网 时间:2024/05/17 08:52
配置文件的编写代码:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<section name="spring" type="spring_test.springClass,spring_test"/>
<section name="hellowChild_1" type="spring_test.IFactory.HelloClassChild_1,spring_test"/>
<section name="hellowChild_2" type="spring_test.IFactory.HelloClassChild_2,spring_test"/>
</configSections>
<spring Name="spring_class:this is a test" ></spring>
<hellowChild_1 Name="HelloClassChild_1 : this is a HelloClassChild_1 class" NameSpace="spring_test.IFactory"></hellowChild_1>
<hellowChild_2 Name="HelloClassChild_2 : this is a HelloClassChild_2 class" NameSpace="spring_test.IFactory"></hellowChild_2>
</configuration>
类的编写代码:
public HelloClassChild_2()
{
}
public HelloClassChild_2(string Name, string NameSpace)
{
this.Name = Name;
this.NameSpace = NameSpace;
}
[System.Configuration.ConfigurationProperty("Name", IsRequired = true)]
public string Name
{
get
{
return this["Name"].ToString();
}
set
{
this["Name"] = value;
}
}
[System.Configuration.ConfigurationProperty("NameSpace", IsRequired = true)]
public string NameSpace
{
get
{
return this["NameSpace"].ToString();
}
set
{
this["NameSpace"] = value;
}
}
public string GetWriteLine(string Name,string NameSpace)
{
return string.Format("程序加载的类为:{0} \n所属的命名空间为:{1}", Name, NameSpace);
}
public void WriteLineString(string Name, string NameSpace)
{
Console.WriteLine(GetWriteLine(Name,NameSpace));
}
类的实例化代码:
static void Main(string[] args)
{
var dataClass1 = System.Configuration.ConfigurationManager.GetSection("spring");
springClass spring = dataClass1 as spring_test.springClass;
Console.WriteLine(spring.Name);
var dataClass2 = System.Configuration.ConfigurationManager.GetSection("hellowChild_1");
IFactory.IHello iFactory_1 = dataClass2 as IFactory.IHello;
iFactory_1.WriteLineString(iFactory_1.Name, iFactory_1.NameSpace);
var dataClass3 = System.Configuration.ConfigurationManager.GetSection("hellowChild_1");
IFactory.IHello iFactory_2 = dataClass2 as IFactory.IHello;
iFactory_2.WriteLineString(iFactory_2.Name, iFactory_2.NameSpace);
Console.Read();
}
<script type="text/javascript"><!--google_ad_client = "ca-pub-1944176156128447";/* cnblogs 首页横幅 */google_ad_slot = "5419468456";google_ad_width = 728;google_ad_height = 90;//--></script><script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
- .net 开发 配置文件的灵活使用
- ASP.NET中表格的灵活使用
- 使用Web.Config Transformation配置灵活的配置文件
- 使用Web.Config Transformation配置灵活的配置文件
- 在.NET开发中灵活使用TreeView控件
- .NET开发使用Winform的配置文件App.config
- 灵活权限控制的DevFx.NET开发框架
- ASP.NET 多环境下配置文件web.config的灵活配置
- vb.net配置文件的使用
- Log4j 的灵活使用
- TRECT的灵活使用
- TRECT的灵活使用
- TRECT的灵活使用
- getchar()的灵活使用
- angularJs的灵活使用
- Visio的灵活使用
- Android开发————Fragment的灵活使用
- 编写灵活的.net代码
- Android ArrayAdapter 详解 .
- 三国SLG手机网游技术分析
- poj 2653 Pick-up sticks 线段相交
- c语言中逗号运算符和逗号表达式
- Spring——类扫描的注解解析器
- .net 开发 配置文件的灵活使用
- 今天粘贴一张照片到桌面,出现提示active什么的,按了确定后,图标从原来的透明底变成了以前98那种蓝色底了,刷新还闪屏
- python语法小结杂烩
- sockaddr sockaddr_in详解
- Nibernate映射配置,简单记法,配置说明。
- 【iOS开发】---- 使用Instrument检查内存占用过多的代码
- Orange's笔记
- 【修炼十二】当萝卜+大棒失效时,我们如何更有效激励员工?
- VS2012下基于Glut OpenGL GL_POLYGON_STIPPLE示例程序: