M
Mr. X.
Hello,
For the following code,
I had a problem.
I want to search only the properties that can be shown and writeable outside
(to a file, etc ...)
=====================
public findWritable(Control myControl)
{
System.Reflection.PropertyInfo[] prs = null;
bool foundBA;
prs =
MyControl.GetProperties(BindingFlags.Public | BindingFlags.Instance);
foundBA = false;
for (int j = 0; j <= prs.Count() - 1; j++)
{
foundBA = true;
if
(prs[j].GetCustomAttributes(false).Count() == 0)
{
foundBA = false;
}
else
{
foundBA = true;
foreach (object att_loopVariable in
prs[j].GetCustomAttributes(false))
{
if (att_loopVariable is
System.ComponentModel.BrowsableAttribute)
{
System.ComponentModel.BrowsableAttribute
att;
att =
(System.ComponentModel.BrowsableAttribute)att_loopVariable;
if (!(att as
System.ComponentModel.BrowsableAttribute).Browsable)
{
foundBA = false;
}
}
}
}
if (foundBA & prs[j].CanRead &&
prs[j].CanWrite)
{
// Property is visible and can be read neighter write
// *** ... DO SOMETHING ... ***//
}
}
}
======
The above code doesn't work for TextBox.Text
and also has some extra elements for TextBox (AutoCompleteCustomResource).
(//*** Do something ***// in remarks should work fine, with no problems).
What's wrong with my code?
I need a generic solution, please.
Thanks
For the following code,
I had a problem.
I want to search only the properties that can be shown and writeable outside
(to a file, etc ...)
=====================
public findWritable(Control myControl)
{
System.Reflection.PropertyInfo[] prs = null;
bool foundBA;
prs =
MyControl.GetProperties(BindingFlags.Public | BindingFlags.Instance);
foundBA = false;
for (int j = 0; j <= prs.Count() - 1; j++)
{
foundBA = true;
if
(prs[j].GetCustomAttributes(false).Count() == 0)
{
foundBA = false;
}
else
{
foundBA = true;
foreach (object att_loopVariable in
prs[j].GetCustomAttributes(false))
{
if (att_loopVariable is
System.ComponentModel.BrowsableAttribute)
{
System.ComponentModel.BrowsableAttribute
att;
att =
(System.ComponentModel.BrowsableAttribute)att_loopVariable;
if (!(att as
System.ComponentModel.BrowsableAttribute).Browsable)
{
foundBA = false;
}
}
}
}
if (foundBA & prs[j].CanRead &&
prs[j].CanWrite)
{
// Property is visible and can be read neighter write
// *** ... DO SOMETHING ... ***//
}
}
}
======
The above code doesn't work for TextBox.Text
and also has some extra elements for TextBox (AutoCompleteCustomResource).
(//*** Do something ***// in remarks should work fine, with no problems).
What's wrong with my code?
I need a generic solution, please.
Thanks