代码生成的底层应用框架 fastCSharp

码农软件 · 软件分类 · 其他开发相关 · 2019-10-23 15:57:39

软件介绍

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;
    }
 fastCSharp的配置文件是一个纯数据的json格式文件,比如 Connection1 的配置定义
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;
            }
        }
    }
 有时候多个表格结构相同,那么只需要定义一个model,比如可以
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)
            {
                //缓存定义与事件定义 和 代码生成模式示例一样
            }
        }   
    }
 有人说ORM不适应于复杂的综合查询。真的吗?我现在展示一段查询代码
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))
                    });
 这个查询需求是,先根据话题(topic)ID查找相关联的问题(question)ID集合,然后找到这些问题的最佳答案(answer)ID集合,然后根据这些答案的用户(user)ID分组统计答案数量,最后将这些用户根据用户等级分组,每个分组根据答案数量取前6个用户。
我个人认为基于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
    {
    }
 代码生成模式将实现接口fastCSharp.setup.cSharp.serialize.ISerialize
1
2
3
4
5
6
7
8
9
10
https://codercto.com/soft/d/17396.html

High Performance JavaScript

High Performance JavaScript

Nicholas C. Zakas / O'Reilly Media / 2010-4-2 / USD 34.99

If you're like most developers, you rely heavily on JavaScript to build interactive and quick-responding web applications. The problem is that all of those lines of JavaScript code can slow down your ......一起来看看 《High Performance JavaScript》 这本书的介绍吧!

MD5 加密
MD5 加密

MD5 加密工具

正则表达式在线测试
正则表达式在线测试

正则表达式在线测试

RGB CMYK 转换工具
RGB CMYK 转换工具

RGB CMYK 互转工具