.NET REFLECTION 中 FieldInfo 类的使用问题

发布于 2024-10-21 03:42:48 字数 1575 浏览 1 评论 0原文

<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

Dim resources As   
System.ComponentModel.ComponentResourceManager = New System.ComponentModel.ComponentResourceManager(GetType(_Class))
    Me.SqlSelectCommand1 = New System.Data.SqlClient.SqlCommand
    Me.SqlInsertCommand1 = New System.Data.SqlClient.SqlCommand
    Me.SqlUpdateCommand1 = New System.Data.SqlClient.SqlCommand
    Me.SqlDeleteCommand1 = New System.Data.SqlClient.SqlCommand
    Me.SqlDataAdapter1 = New System.Data.SqlClient.SqlDataAdapter
    Me.SqlConnection1 = New System.Data.SqlClient.SqlConnection

.....
.....



Me.SqlInsertCommand1.CommandText = resources.GetString("SqlInsertCommand1.CommandText")
    Me.SqlInsertCommand1.Connection = Me.SqlConnection1
    Me.SqlInsertCommand1.Parameters.AddRange(New System.Data.SqlClient.SqlParameter() {New System.Data.SqlClient.SqlParameter("@MAIN_FACILITY_USED", System.Data.SqlDbType.NVarChar, 0, "MAIN FACILITY USED")

为什么下面的行我无法访问有关 sqlinsertcommand 的参数集合,但我可以通过以下代码访问 sqlinsertcommand 及其命令文本本身:

Dim flags As BindingFlags = BindingFlags.NonPublic Or BindingFlags.Instance Or BindingFlags.NonPublic
 For Each info As FieldInfo In AssemblyInstance.GetType().GetFields(flags)
  If info.FieldType.FullName = "System.Data.SqlClient.SqlCommand" Then
    cmd = CType(info.GetValue(AssemblyInstance), SqlCommand)
   End If
Next

How can Ireach that sqlparameter collection via fieldinfo or other related classes in >NET Reflection ? 看起来很粗鲁,但任何帮助甚至建议对我来说都很重要。

<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

Dim resources As   
System.ComponentModel.ComponentResourceManager = New System.ComponentModel.ComponentResourceManager(GetType(_Class))
    Me.SqlSelectCommand1 = New System.Data.SqlClient.SqlCommand
    Me.SqlInsertCommand1 = New System.Data.SqlClient.SqlCommand
    Me.SqlUpdateCommand1 = New System.Data.SqlClient.SqlCommand
    Me.SqlDeleteCommand1 = New System.Data.SqlClient.SqlCommand
    Me.SqlDataAdapter1 = New System.Data.SqlClient.SqlDataAdapter
    Me.SqlConnection1 = New System.Data.SqlClient.SqlConnection

.....
.....



Me.SqlInsertCommand1.CommandText = resources.GetString("SqlInsertCommand1.CommandText")
    Me.SqlInsertCommand1.Connection = Me.SqlConnection1
    Me.SqlInsertCommand1.Parameters.AddRange(New System.Data.SqlClient.SqlParameter() {New System.Data.SqlClient.SqlParameter("@MAIN_FACILITY_USED", System.Data.SqlDbType.NVarChar, 0, "MAIN FACILITY USED")

How come with the following line I cannot reach this collection of the parameter regarding to sqlinsertcommand but I can reach the sqlinsertcommand and its commandtext itself by the following code:

Dim flags As BindingFlags = BindingFlags.NonPublic Or BindingFlags.Instance Or BindingFlags.NonPublic
 For Each info As FieldInfo In AssemblyInstance.GetType().GetFields(flags)
  If info.FieldType.FullName = "System.Data.SqlClient.SqlCommand" Then
    cmd = CType(info.GetValue(AssemblyInstance), SqlCommand)
   End If
Next

How can I reach that sqlparameter collection via fieldinfo or other related classes in >NET Reflection?
Seems rude but any help or even suggestion means a lot to me.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

风透绣罗衣 2024-10-28 03:42:48

所以“cmd”是“System.Data.SqlClient.SqlCommand”的实例?! - 是的,应该的。
然后它有一个属性“Parameters”来保存您的参数。

so "cmd" is an Instance of "System.Data.SqlClient.SqlCommand" ?! - yes it should.
then it has a property "Parameters" which holds your parameters.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文