- 授权协议: BSD
- 开发语言: C#
- 操作系统: Windows
- 软件首页: http://www.51nod.com/topic/index.html#!topicId=100000056
- 软件文档: http://www.51nod.com/question/index.html#!questionId=987
软件介绍
fastCSharp是一个基于.NET元数据的代码生成的底层应用框架,目标是打造一个“开发+运行”效率双优的开源框架。
经过半年多的时间,除了与web开发直接相关的部分,都已经在fastCSharp part 1.5中完成了重写工作。
fastCSharp现在实现的代码生成实例主要有5个:
1、基于缓存查询模式的ORM代码生成实例(现在只支持MSSQL),自定义配置类是fastCSharp.setup.cSharp.sqlTable,同时支持反射模式fastCSharp.setup.cSharp.sqlTable.sqlTool。
下面是ORM的model定义示例
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
|
[fastCSharp.setup.cSharp.sqlTable(ConnectionName = "Connection1")]
public partial class model1
{
///
/// 自增列,一个表格只允许一个,如果不配置IsIdentity = true,将自动匹配名称为 id 的成员
///
[fastCSharp.setup.sqlMember(IsIdentity = true)]
public int id;
///
/// 关键字1,多个关键字成员按照成员定义顺序一致
///
[fastCSharp.setup.sqlMember(IsPrimaryKey = true)]
public int key1;
///
/// 关键字2
///
[fastCSharp.setup.sqlMember(IsPrimaryKey = true, IsAscii = true, MaxLength = 32)]
public string key2;
public enum EnumByte : byte
{
Enum1
}
///
/// 直接支持枚举类型转换,可以不指定SqlType = typeof(byte)
///
[fastCSharp.setup.sqlMember(SqlType = typeof(byte))]
public EnumByte key2;
///
/// 指定隐式类型转换
///
[fastCSharp.setup.sqlMember(SqlType = typeof(string))]
public partial struct image
{
public string url;
///
/// 如果不能隐式类型转换,必须实现互转函数
///
public static implicit operator image(string url) { return new image { url = url }; }
public static implicit operator string(image image) { return image.url; }
}
///
/// 支持隐式类型转换
///
[fastCSharp.setup.sqlMember(IsAscii = true, MaxLength = 64)]
public image icon = string.Empty;
}
|
|
1
2
3
4
5
6
7
8
9
10
11
12
|
{
sql: {
checkConnection:["Connection1"],
Connection1:
{
Diantou:{
Type:"sql2008",
Connection:"server=192.168.0.100;database=dbname;uid=username;pwd=password"
}
}
}
}
|
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
public partial class bModel1 : model1.sqlTable
{
static bModel1()
{
if (SqlTool != null)
{
//定义缓存
Cache = new fastCSharp.sql.cache.whole.identityArray(SqlTool);
//定义缓存同步个性化处理事件
Cache.OnInserted += XXX;
Cache.OnUpdated += XXX;
}
}
}
|
|
1
2
3
4
5
6
7
8
9
10
|
public abstract class bModelBase : model1.sqlTable
where tableType : bModelBase
{
}
public partial class bModel1_1 : bModelBase
{
}
public partial class bModel1_N : bModelBase
{
}
|
|
1
2
3
4
5
6
7
8
9
10
11
|
public class bModel1 : model1
{
private static readonly fastCSharp.setup.cSharp.sqlTable.sqlTool sqlTool = fastCSharp.setup.cSharp.sqlTable.sqlTool.Default;
static bModel1()
{
if (sqlTool != null)
{
//缓存定义与事件定义 和 代码生成模式示例一样
}
}
}
|
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
|
return diantou.dataProxy.questionTopic.getTopicCache(id)
.getArray(value => diantou.dataProxy.question.get(value.linkId))
.getHash(value => value.bestAnswerId)
.getArray(value => diantou.dataProxy.answer.get(value))
.getFind(value => value != null)
.group(value => value.userId)
.getArray(value => new keyValue(diantou.dataProxy.user.get(value.Key), value.Value.Count))
.group(value => value.Key.grade0)
.getArray(value => new userStat
{
grade0 = value.Key,
count = value.Value.Count,
path = topic.path.bestAnswer,
users = value.Value.rangeSort((left, right) => right.Value - left.Value, 0, 6)
.getArray(user => diantou.dataProxy.user.get(user.Key, userId))
});
|
我个人认为基于ORM的查询更简单流畅。如果用SQL实现这个需求,该是一个多么复杂的SQL语句?如果需求有一点点变化,修改这个SQL语句该是多麻烦的事?
2、数据类快速序列化代码生成实例,自定义配置类是fastCSharp.setup.cSharp.serialize,同时支持反射模式。
|
1
2
3
4
5
6
7
|
///
/// 仅仅选择字段成员,反射模式可以不必配置
///
[fastCSharp.setup.cSharp.serialize(Filter = fastCSharp.setup.memberFilter.InstanceField)]
public partial class model1
{
}
|
|
1
2
3
4
5
6
7
8
9
10
https://codercto.com/soft/d/17396.html
版权所有,保留一切权利!© 2018-2026 码农网
粤ICP备17054400号-3
|
