What do you use to generate code in .NET?

What are you using code generation for? What are typical scenarios that allow you to get real value from generating C # code at runtime ? In particular: what are you using for the CodeDOM namespace for?

+3
source share
6 answers

Codegen on the fly? Do you mean while working? I use this to create high-performance code access that could be used by other sensible uses. In most cases, you can use things like Delegate.CreateDelegate, but there are times when ILGenerator, etc. Have their place.

I use this in protobuf-net to access fields at runtime (by creating a wrapper, note the properties use Delegate.CreateDelegate), and in HyperDescriptor to create a faster implementation PropertyDescriptor. But in both cases I use ILGeneratordirectly - not CodeDom.

In fact, personally, I really would not have studied CodeDom if I hadn't; for runtime to work, I would first look at Expression. I have an article on InfoQ discussing this, or various things here on SO or on my blog that might be interesting.


codegen - ( ), , . LINQ-to-SQL (SqlMetal), EF .. , codegen. protobuf-net xslt codegen ( .proto); T4, 2.0/mono .., xslt ( ).

+2

, Moq, mocks stubs " " . , Castle.DynamicProxy, , , Reflection.Emit.

+2

, , XML, . XML .NET. CodeDOM.

+1

, XAML. XAML .

0

, , IMHO dom.

0

" ". , P (X, Y), X Y, X , Y , , X PX (Y), , P , X. , X, X "" . PX , Y.

: "" . X ( ) Y ( ). X , Y . P (X, Y) . 2 , , 2 18 ., .

, X, , . C X C PX (Y). PX , , . , X, Y. ( C) 0,5 2 3 .

, , . , X PX, Y,

-1

Source: https://habr.com/ru/post/1722932/


All Articles