代码生成 [英] Code Generation

查看:79
本文介绍了代码生成的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,

我听到一些关于创建代码以生成C#或VB .NET代码的大肆宣传,

是代码生成(听起来很直接)。我还没有真正看到

它是如何在现实世界中完成的。我想知道什么样的情况代码

代最有意义。我认为可以通过与单元测试相关的一些技巧来完成。有没有人完成代码生成,你能与世界其他地方分享你的故事吗?


TIA

解决方案

你好


就我而言,我使用代码生成来生成c#中的数据访问类。

我做了一个读取数据库模式(表,字段,主键,

外键,数据类型等)的工具,并为每个表生成一个类,其中包含保存数据的私有

字段,以及访问这些字段的公共属性。用于插入,更新,删除数据的

方法

这样做的优势在于而不是使用数据集/数据表首先是

速度(在数据集中所有数据都存储为对象,这意味着在

中读取和写入数据时会发生
类型转换/装箱/拆箱的丢失数据集。)和编译时间类型检查。


最好的问候


" Hayato Iriumi" <喜***** @ hotmail.com>在消息中写道

news:uQ ************** @ TK2MSFTNGP09.phx.gbl ...

你好,
我听到一些关于创建代码以生成C#或VB .NET代码的大肆宣传,即代码生成(听起来很直接)。我真的没看到它是如何在现实世界中完成的。我想知道什么样的情况代码一代最有意义。我认为可以通过与单元测试相关的技巧来完成。有没有人完成代码生成,你可以和世界其他地方分享你的故事吗?

blockquote>

用于为业务构建软件的工具,使用代码生成

http://www.manager-erp.com/eng/products/its/platform/

" Hayato Iriumi" <喜***** @ hotmail.com>在消息中写道

news:uQ ************** @ TK2MSFTNGP09.phx.gbl ...

你好,
我听到一些关于创建代码以生成C#或VB .NET代码的大肆宣传,即代码生成(听起来很直接)。我真的没看到它是如何在现实世界中完成的。我想知道什么样的情况代码一代最有意义。我认为可以通过与单元测试相关的技巧来完成。有没有人完成代码生成,你可以和世界其他地方分享你的故事吗?

blockquote>

来自MSDN的优秀文章:
http://msdn.microsoft.com/msdnmag/is...n/default.aspx


它通常用于生成数据访问层代码,或简单的用户

接口代码(为数据库表操作添加/更新/删除/列表,对于

示例)。


希望这有帮助,

---尼克


" Hayato Iriumi" <喜***** @ hotmail.com>在消息中写道

news:uQ ************** @ TK2MSFTNGP09.phx.gbl ...

你好,
我听到一些关于创建代码以生成C#或VB .NET代码的大肆宣传,即代码生成(听起来很直接)。我真的没看到它是如何在现实世界中完成的。我想知道什么样的情况代码一代最有意义。我认为可以通过与单元测试相关的技巧来完成。有没有人完成代码生成,你可以和世界其他地方分享你的故事吗?

blockquote>

Hello,
I hear some hypes about creating code to generate C# or VB .NET code, that
is, code generation (sounds straight forward enough). I haven''t really seen
how it''s done in real world. I''m wondering in what kind of situation code
generation makes most sense. I''m think that sort of tricks can be done in
relation to unit testing. Has anyone done code generation and can you share
your story with the rest of the world?

TIA

解决方案

Hello

In my case, I used code generation to generate data access classes in c#.
I made a tool that reads the database schema (tables, fields, primary keys,
foreign keys, data types, etc) and generate one class per table with private
fields holding the data, and public properties to access these fields. And a
method for insert, update, delete from datable

The advantage of doing this rather than using a dataset / datatable is first
speed (in data sets all data are stored as objects, which means a lost of
type casting / boxing / unboxing occurs when reading and writing data in the
dataset.) and compile time type checking.

Best regards

"Hayato Iriumi" <hi*****@hotmail.com> wrote in message
news:uQ**************@TK2MSFTNGP09.phx.gbl...

Hello,
I hear some hypes about creating code to generate C# or VB .NET code, that
is, code generation (sounds straight forward enough). I haven''t really seen how it''s done in real world. I''m wondering in what kind of situation code
generation makes most sense. I''m think that sort of tricks can be done in
relation to unit testing. Has anyone done code generation and can you share your story with the rest of the world?

TIA



Tool used to build software for the business, using code generation

http://www.manager-erp.com/eng/products/its/platform/

"Hayato Iriumi" <hi*****@hotmail.com> wrote in message
news:uQ**************@TK2MSFTNGP09.phx.gbl...

Hello,
I hear some hypes about creating code to generate C# or VB .NET code, that
is, code generation (sounds straight forward enough). I haven''t really seen how it''s done in real world. I''m wondering in what kind of situation code
generation makes most sense. I''m think that sort of tricks can be done in
relation to unit testing. Has anyone done code generation and can you share your story with the rest of the world?

TIA



Excellent article from MSDN:
http://msdn.microsoft.com/msdnmag/is...n/default.aspx

It is commonly used to generate data access layer code, or simple user
interface code (add/update/delete/list for database table operations, for
example).

Hope this helps,
--- Nick

"Hayato Iriumi" <hi*****@hotmail.com> wrote in message
news:uQ**************@TK2MSFTNGP09.phx.gbl...

Hello,
I hear some hypes about creating code to generate C# or VB .NET code, that
is, code generation (sounds straight forward enough). I haven''t really seen how it''s done in real world. I''m wondering in what kind of situation code
generation makes most sense. I''m think that sort of tricks can be done in
relation to unit testing. Has anyone done code generation and can you share your story with the rest of the world?

TIA



这篇关于代码生成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆