代码生成的底层应用框架 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://www.codercto.com/soft/d/17396.html

Python网络编程(第3版)

Python网络编程(第3版)

[美] Brandon Rhodes、[美] John Goerzen / 诸豪文 / 人民邮电出版社 / 2016-9 / 79.00元

本书针对想要深入理解使用Python来解决网络相关问题或是构建网络应用程序的技术人员,结合实例讲解了网络协议、网络数据及错误、电子邮件、服务器架构和HTTP及Web应用程序等经典话题。具体内容包括:全面介绍Python3中最新提供的SSL支持,异步I/O循环的编写,用Flask框架在Python代码中配置URL,跨站脚本以及跨站请求伪造攻击网站的原理及保护方法,等等。一起来看看 《Python网络编程(第3版)》 这本书的介绍吧!

CSS 压缩/解压工具
CSS 压缩/解压工具

在线压缩/解压 CSS 代码

RGB转16进制工具
RGB转16进制工具

RGB HEX 互转工具

随机密码生成器
随机密码生成器

多种字符组合密码