Click here to Skip to main content
12,996,975 members (69,994 online)
Rate this:
Please Sign up or sign in to vote.
See more:
How can i generate the below code inside a method or codemembermethod? How can i generate it using codedom?

SqlConnection con1 = new SqlConnection(Core.ConnectionStringSample);
Posted 27-Dec-12 3:46am
Sergey Alexandrovich Kryukov 27-Dec-12 12:20pm
1) I wonder why?

2) Why don't you want simply to write a text of code (compose or modify it during run-time, if you really need to use CodeDOM) and compile with CodeDOM into an assembly? This is a major way to use CodeDOM...

3) If the above cannot suit your (then, why?), did you consider using System.Reflection.Emit, to just emit the code you need?

You really need to answer, otherwise it would not make sense to continue.

Thank you,

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

it is easy to emit the code but i want to properly identify which is the method, type reference etc. when they are generated.

I tried using Codevariabledeclarationstatement but the output is just like a string or same as the output of console.writeline.

The proper identification for a certain type does not generated.
SqlConnection cn = new SqlConnection();

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170622.1 | Last Updated 28 Dec 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100