Hello,
I have the following code:
MySection sect =
System.Configur ation.Configura tionManager.Get Section(Name) as
MySection;
foreach (Person p in sect.People) {
Interaction.Msg Box(p.Name);
}
Now I am trying to create a method that is a little bit more generic.
As result as GetSection I will get a class. This class can be of many
types (MySection, Google, ...).
All I know is that this class inherits ConfigurationEl ementCollection .
Then I want to loop through each item of this class and find the item
which Name is equal to a Key value I provide.
The item can be of type People (if the collection is of type
MySection), Service (if the collection if of type Google), ...
The one thing I know is that any of this classes has a property named
Name to which I will compare to Key.
I would like to create a method for this, for example Get, and then
use it:
People p = (People)Get("My Section")
or
Service s = (Service)Get("G oogle")
Is this possible to create this generalization?
Or should I even do this?
Thanks,
Miguel
I have the following code:
MySection sect =
System.Configur ation.Configura tionManager.Get Section(Name) as
MySection;
foreach (Person p in sect.People) {
Interaction.Msg Box(p.Name);
}
Now I am trying to create a method that is a little bit more generic.
As result as GetSection I will get a class. This class can be of many
types (MySection, Google, ...).
All I know is that this class inherits ConfigurationEl ementCollection .
Then I want to loop through each item of this class and find the item
which Name is equal to a Key value I provide.
The item can be of type People (if the collection is of type
MySection), Service (if the collection if of type Google), ...
The one thing I know is that any of this classes has a property named
Name to which I will compare to Key.
I would like to create a method for this, for example Get, and then
use it:
People p = (People)Get("My Section")
or
Service s = (Service)Get("G oogle")
Is this possible to create this generalization?
Or should I even do this?
Thanks,
Miguel
Comment