您的位置:首页 > 其它

【开源系列】三国演义LBS (七)源码:基础框架:无与伦比的序列化!

2011-05-04 00:05 525 查看

前言

-----------------------------------------------

相关讨论组入口: http://www.pixysoft.net/ (点击进入)





功能简介:

----------------------------------------------- 通用的配置文件框架,是一切框架基础。

令微软都汗颜的序列化与反序列化,支持私有类、接口、甚至Method方法!!!使用动态编译,性能比微软自带的提升N个数量级!!

你能想到的,我都做到了!

快速入门-----------------------------------------------

配置文件操作:

/// <summary>
/// 配置文件格式
/// </summary>
public void test_000()
{
//<config>

// <config id="LogConfiguration">
// <LogCapacity>1048576</LogCapacity>
// <LogIp>false</LogIp>
// <ConsoleLevel>OFF</ConsoleLevel>
// <LogLevel>INFO</LogLevel>
// </config>

// <config id="ReflectionConfiguration">
// <InterfaceMappings>
// <InterfaceMapping filename="123" assemblyname="123" classname="afsd" />
// </InterfaceMappings>
// </config>

//</config>

// 必须有一个根节点是config

//子节点必须包含ID属性,表示类名,将用于反射为对象。
}

/// <summary>
/// 获取配置文件
/// 配置文件与xml反射相同,仅仅遵循了一定的规则
/// </summary>
public void test_001()
{
// 在bin/debug目录下,存在pixysoft.config配置文件,如果没有,从.conf目录copy过去。

// 默认模式下的配置

LogConfiguration config = Configuration.GetConfiguration<LogConfiguration>();
Console.WriteLine(config.LogCapacity);

//获取指定name的配置 方便多配置

Console.WriteLine(Configuration.GetConfiguration<ReflectionConfiguration>("ReflectionConfiguration", "hello1").Name);

//不区分大小写

Console.WriteLine(Configuration.GetConfiguration<ReflectionConfiguration>("REFLECTIONCONFIGURATION", "hello2").Name);

//输出结果

//------ Test started: Assembly: Pixysoft.Framework.Configurations.dll ------

//1048576
//hello1
//hello2

//1 passed, 0 failed, 0 skipped, took 0.19 seconds (Ad hoc).

}

interface ILogConfiguration
{
int LogCapacity { get;set;}
}

class LogConfiguration : ILogConfiguration
{
int logCapacity;
public int LogCapacity
{
get { return logCapacity; }
set { logCapacity = value; }
}
}

class ReflectionConfiguration
{
string name;
public string Name
{
get { return name; }
set { name = value; }
}

}

超级强大的序列化、反序列化

/// <summary>
/// 超级强大的XML序列化、反序列化,是一切框架的基础
/// 支持接口序列化、反序列化
/// 支持私有类序列化、反序列化
/// 支持动态编译序列化、反序列化
/// 支持方法序列化、反序列化
/// </summary>
public void test_002()
{
LogConfiguration config = new LogConfiguration();
config.LogCapacity = 1024;

//对象序列化为通用对象

IXmlNode node = XmlManager.Serialize(config);
Console.WriteLine(node.Node["logcapacity"].Text);

//通用对象序列化为字符串

Console.WriteLine(node.Serialize(true));

//字符串反序列化为通用对象

node = XmlManager.Deserialize(node.Serialize());
Console.WriteLine(node.Node["logcapacity"].Text);

//字符串反序列化为对象

config = XmlManager.Deserialize<LogConfiguration>(node.Serialize());
Console.WriteLine(config.LogCapacity);

//使用动态编译进行序列化/反序列化,提高性能 性能超高!!

node = XmlManager.DynamicSerialize(config);
Console.WriteLine(node.Node["logcapacity"].Text);
config = XmlManager.DynamicDeserialize<LogConfiguration>(node.Serialize());
Console.WriteLine(config.LogCapacity);

//使用接口反序列化 (当没有对方类、仅仅知道字符串的时候,本地代码只需要声明接口,即可实现反序列化!)

ILogConfiguration iconfig = XmlManager.PojoDeserialize<ILogConfiguration>(node.Serialize());
Console.WriteLine(iconfig.LogCapacity);
}

Html操作

/// <summary>
/// Html解析
/// </summary>
public void test_003()
{
string html = "<html><body>hello<a>sf</a></body></html>";

IHtmlNode node = HtmlManager.DeserializeFragment(html);
Console.WriteLine(node.Node["body"].Text);
}

下期预告:

-----------------------------------------------

Pixysoft.Framework.Schema

提供了对任意数据库进行元数据建模,是持久层的基础!

附件下载

----------------------------------------------- Pixysoft.Framework.Logs 打包下载:

http://www.boxcn.net/shared/tl4lc1v8e8

SVN:

http://qun.qq.com/air/#95755843/bbs
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐