代码生成的底层应用框架 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

C++程序设计

C++程序设计

谭浩强 / 清华大学出版社 / 2004-6-1 / 36.00元

《C++程序设计》作者深入调查了我国大学的程序设计课程的现状和发展趋势,参阅了国内外数十种有关C++的教材,认真分析了学习者在学习过程中遇到的困难,研究了初学者的认识规律。在本书中做到准确定位,合理取舍内容,设计了读者易于学习的教材体系,并且以通俗易懂的语言化解了许多复杂的概念,大大减少了初学者学习C++的困难。C++是近年来国内外广泛使用的现代计算机语言,它既支持面向过程的程序设计,也支持基于对......一起来看看 《C++程序设计》 这本书的介绍吧!

图片转BASE64编码
图片转BASE64编码

在线图片转Base64编码工具

HTML 编码/解码
HTML 编码/解码

HTML 编码/解码

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

RGB CMYK 互转工具