M
Michael Stahl
What I want to do:
I want to have a class which is reading an .ini file and manipulate the
application with the data from the ini file.
What I have now:
An ini file:
[textBox1]
Text=Hallo
Dock=none
ForeColor=red
A class with:
object iwill=null;
parentType = this.GetType();
System.IO.StreamReader sr=
new System.IO.StreamReader(INIFilePath,System.Text.Encoding.UTF8,false);
string str="";
while(sr.Peek()>=0)
{
str=sr.ReadLine().Trim();
//Get the Control I want to change
if(str.StartsWith("["))
{
foreach(Control con in this.Controls)
{
if("["+con.Name.ToString()+"]"==str)
{
iwill=con;
}
}
}
Type myType = iwill.GetType();
//Get the Property I want to change
PropertyInfo pi =myType.GetProperty(str.Split('=')[0]);
if( pi != null )
{
object result=null;
TypeConverter converter=
TypeDescriptor.GetConverter(pi.PropertyType);
result =converter.ConvertFrom(str.Split('=')[1]);
//Change the property
pi.SetValue(iwill,result,null);
}
}
With this i could change textBox1 properties like Dock, Text...
This is working with all my controlls in my Application, but not with
other objects, like sqlConnectionString, or sqlSelectStatements, cause
they are no Controlls.
QUESTION:
Is there a way to get thru all objects in my Application, like i do it
with the Controls in my example?
Must I do something completely different?
Hope someone knows what to do!!
I want to have a class which is reading an .ini file and manipulate the
application with the data from the ini file.
What I have now:
An ini file:
[textBox1]
Text=Hallo
Dock=none
ForeColor=red
A class with:
object iwill=null;
parentType = this.GetType();
System.IO.StreamReader sr=
new System.IO.StreamReader(INIFilePath,System.Text.Encoding.UTF8,false);
string str="";
while(sr.Peek()>=0)
{
str=sr.ReadLine().Trim();
//Get the Control I want to change
if(str.StartsWith("["))
{
foreach(Control con in this.Controls)
{
if("["+con.Name.ToString()+"]"==str)
{
iwill=con;
}
}
}
Type myType = iwill.GetType();
//Get the Property I want to change
PropertyInfo pi =myType.GetProperty(str.Split('=')[0]);
if( pi != null )
{
object result=null;
TypeConverter converter=
TypeDescriptor.GetConverter(pi.PropertyType);
result =converter.ConvertFrom(str.Split('=')[1]);
//Change the property
pi.SetValue(iwill,result,null);
}
}
With this i could change textBox1 properties like Dock, Text...
This is working with all my controlls in my Application, but not with
other objects, like sqlConnectionString, or sqlSelectStatements, cause
they are no Controlls.
QUESTION:
Is there a way to get thru all objects in my Application, like i do it
with the Controls in my example?
Must I do something completely different?
Hope someone knows what to do!!