C#代码生成 [英] C# Code Generation

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

问题描述

我在看为项目创建一个小班发生器。我一直在阅读有关的CodeDOM所以它创建类的语义并不似乎是一个问题,但我不确定哦如何产生最好的融入开发和部署过程。




  1. 我应该如何触发类的创造?我已阅读应该是构建过程的一部分,我应该怎么做呢?


  2. 应创建的类?我读这些文件不应该由手工编辑,从来没有签入到源控制。应我甚至担心这个,只是生成类到同一目录下生成引擎?



解决方案

你的问题的答案部分取决于您所产生的目的类。



如果类作为一部分产生的发展的,他们应该生成文本文件和签入到您的SCM像任何其他类



如果您的类在动态的运行的为你的系统的操作的一部分生成的,我不会用CodeDOM的所有。我会用反思。


I am looking at creating a small class generator for a project. I have been reading about CodeDOM so it the semantics of creating the classes does not appear to be an issue, but am unsure oh how to best integrate the generation into the development and deployment process.

  1. How should I trigger the creation of the classes? I have read it should be part of the build process, how should I do this?

  2. Where should the classes be created? I read that the files should not be edited by hand, and never checked into source control. Should I even worry about this and just generate the classes into the same directory as the generator engine?

解决方案

The answers to your question depend partly on the purpose of your generated classes.

If the classes are generated as a part of the development, they should be generated as text files and checked into your SCM like any other class.

If your classes are generated dynamically at runtime as a part of the operation of your system, I wouldn't use the CodeDOM at all. I'd use Reflection.

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

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