在c#中使用CodeDom生成using语句 [英] Generate a using statement using CodeDom in c#
本文介绍了在c#中使用CodeDom生成using语句的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要帮助以下代码我想用C#中的CodeDom生成它。
有没有办法做到这一点?
如果没办法在CodeDom中执行此操作是除了使用语句之外的任何替代方法吗?
使用(SqlConnection con1 = < span class =code-keyword> new SqlConnection(Core.ConnectionStringSample))
{
using (SqlCommand cmd = con1 .CreateCommand())
{
}
}
解决方案
< blockquote>我对CodeDom并不是特别熟悉,但使用 try-finally
可以重写使用
语句,例如:
(SqlConnection con1 = new SqlConnection(Core。 ConnectionStringSample))
{
// code
}
可以写成:
SqlConnection con1 = 新的 SqlConnection(Core.ConnectionStringSample);
尝试
{
// 代码
}
最后
{
if (con1!= null )
{
con1.Dispose();
}
}
I need help with the below code I would like to generate it using CodeDom in C#.
Is there any way to do this?
If there is no way to do this in CodeDom is the any alternative way beside using statement?
using (SqlConnection con1 = new SqlConnection(Core.ConnectionStringSample))
{
using (SqlCommand cmd = con1.CreateCommand())
{
}
}
解决方案
I''m not particularly familiar with CodeDom, but ausing
statement can be rewritten usingtry-finally
, for example:
(SqlConnection con1 = new SqlConnection(Core.ConnectionStringSample)) { // code }
can be written as:
SqlConnection con1 = new SqlConnection(Core.ConnectionStringSample); try { // code } finally { if (con1 != null) { con1.Dispose(); } }
这篇关于在c#中使用CodeDom生成using语句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文