循环所有属性 [英] Loop ALL Properties
问题描述
我正在试图循环第三方
控件的属性。例如,我有一个文本框,其最大长度位于MyTextBox.Properties.MaxLength的
- 而不是dotnet文本框,而不是
MyTextBox.MaxLength。如果我循环内置的dotnet控件,它会发现
属性没问题。但循环通过第三方控件,
Properties.MaxLength未列出。我希望找到它如何使用反射来命名它,所以我可以使用GetValue和SetValue来动态地设置
控件的值,直到运行时才知道它们的类型。如何获得
访问循环控件的所有属性?
Dim t As Type = ctl.GetType
For Each pp As PropertyInfo in t.GetProperties()
Console.WriteLine(" {0} = {1}",pp.Name,pp.GetValue(ctl,Nothing))
下一页
I am going in circles trying to loop through properties on 3rd party
controls. For example, I have a textbox that has its maximum length located
at MyTextBox.Properties.MaxLength - instead of the dotnet textbox which is
MyTextBox.MaxLength. If I loop a built in dotnet control, it finds the
property no problem. But looping through the 3rd party control,
Properties.MaxLength does not get listed. I was hoping to find how it names
it using reflection, so I could use GetValue and SetValue to dyanmically set
values of controls without knowing their type until runtime. How can I gain
access to loop ALL the properties of a control?
Dim t As Type = ctl.GetType
For Each pp As PropertyInfo In t.GetProperties()
Console.WriteLine("{0} = {1}", pp.Name, pp.GetValue(ctl, Nothing))
Next
推荐答案
嗨Derek,
我有没有得到它是正确的MyTextBox.Properties是你自己的数组
''属性'',像字典?如果是这样,它与''真实财产'的关系如何,
'本地'为一个班级?
问候,Alex Meleta
[TechBlog] http://devkids.blogspot.com
Hi Derek,
Did I get it right that MyTextBox.Properties is sort of your own array of
''properties'', like dictionary? If so, that how it relates to ''real properties'',
''native'' for a class?
Regards, Alex Meleta
[TechBlog] http://devkids.blogspot.com
i
i
你应该递归循环。
>
" Derek Hart" < de ******** @ yahoo.comwrote in message
news:eI ************** @ TK2MSFTNGP03.phx.gbl .. 。
You should be looping recursively.
"Derek Hart" <de********@yahoo.comwrote in message
news:eI**************@TK2MSFTNGP03.phx.gbl...
>我正在试图循环第三方
控件的属性。例如,我有一个文本框,其最大长度位于MyTextBox.Properties.MaxLength - 而不是作为MyTextBox.MaxLength的dotnet文本框。如果我循环内置的dotnet控件,它会发现
属性没问题。但循环通过第三方控件,
Properties.MaxLength未列出。我希望找到它如何使用反射命名它,所以我可以使用GetValue和SetValue来动态设置控件的值,直到运行时才知道它们的类型。我怎样才能获得对控件的所有属性的循环?
Dim t As Type = ctl.GetType
For Each pp As PropertyInfo in t.GetProperties()
Console.WriteLine(" {0} = {1}",pp.Name,pp.GetValue(ctl,Nothing))
Next
>I am going in circles trying to loop through properties on 3rd party
controls. For example, I have a textbox that has its maximum length located
at MyTextBox.Properties.MaxLength - instead of the dotnet textbox which is
MyTextBox.MaxLength. If I loop a built in dotnet control, it finds the
property no problem. But looping through the 3rd party control,
Properties.MaxLength does not get listed. I was hoping to find how it names
it using reflection, so I could use GetValue and SetValue to dyanmically
set values of controls without knowing their type until runtime. How can I
gain access to loop ALL the properties of a control?
Dim t As Type = ctl.GetType
For Each pp As PropertyInfo In t.GetProperties()
Console.WriteLine("{0} = {1}", pp.Name, pp.GetValue(ctl, Nothing))
Next
第三方Developer Express文本框控件。它有很多属性。不能
弄清楚如何循环并获得所有这些。
" Alex Meleta" < am ***** @ gmail.comwrote in message
news:df ************************* @ news.microsoft.co m ...
3rd Party Developer Express textbox control. It has many properties. Can''t
figure out how to loop and get all of them.
"Alex Meleta" <am*****@gmail.comwrote in message
news:df*************************@news.microsoft.co m...
嗨Derek,
我是否理解MyTextBox.Properties有点像你自己的一堆
''属性'',就像字典一样?如果是这样,它是如何与''真实的
属性''相关联,''本地'为一个类?
问候,Alex Meleta
[TechBlog] http://devkids.blogspot.com
> i
>i
这篇关于循环所有属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!