G
Guest
I can't figure out how to approach this problem.
I would like to have a custom object that will contain some predefined
attributes.
The simple solution that I know is to create my own class -- something like:
public class MyClass
{
private string _property01 = string.Empty;
public string property01
{
get { return _property01; }
set { this._property01 = value; }
}
}
And use all hard-coded assignments like:
MyClass someRecord = new MyClass();
someRecord.Property01 = "blah blah";
string anotherBlah = someRecord.Property01;
What I am looking for is to generalize properties of my custom class as well
as generalize future population of those properties.
I think that I need a construct like this:
{
....
propertyName = "property01"
someRecord[propertyName].Value = "blah blah"
string anotherBlah = someRecord[propertyName].Value;
....
}
and perhaps extending that class with more methods like:
someRecord[propertyName].Remove;
someRecord[propertyName].Add;
someRecord[propertyName].Whatever;
It is seems to me that I will need to inherit from CollectionBase and use
some sort of constructor like:
public MyClass this[int index]
{
get { return ((MyClass)(List[index])); }
set { List[index] = value; }
}
Should I create some sort of a "special" constructor for my "MyClass" class?
With the one I've got I can return value by integer "index" which is a
sollectionBase IList method, I gathering... Which i could not make to work
anyway...
How can I supply my own "search" by name of the attribute, and not by its
index?
Should I extend constructor? Should I inherit from something else? Or
perhaps I am completely off-track with this idea.
Please advice.
Thanks in advance.
I would like to have a custom object that will contain some predefined
attributes.
The simple solution that I know is to create my own class -- something like:
public class MyClass
{
private string _property01 = string.Empty;
public string property01
{
get { return _property01; }
set { this._property01 = value; }
}
}
And use all hard-coded assignments like:
MyClass someRecord = new MyClass();
someRecord.Property01 = "blah blah";
string anotherBlah = someRecord.Property01;
What I am looking for is to generalize properties of my custom class as well
as generalize future population of those properties.
I think that I need a construct like this:
{
....
propertyName = "property01"
someRecord[propertyName].Value = "blah blah"
string anotherBlah = someRecord[propertyName].Value;
....
}
and perhaps extending that class with more methods like:
someRecord[propertyName].Remove;
someRecord[propertyName].Add;
someRecord[propertyName].Whatever;
It is seems to me that I will need to inherit from CollectionBase and use
some sort of constructor like:
public MyClass this[int index]
{
get { return ((MyClass)(List[index])); }
set { List[index] = value; }
}
Should I create some sort of a "special" constructor for my "MyClass" class?
With the one I've got I can return value by integer "index" which is a
sollectionBase IList method, I gathering... Which i could not make to work
anyway...
How can I supply my own "search" by name of the attribute, and not by its
index?
Should I extend constructor? Should I inherit from something else? Or
perhaps I am completely off-track with this idea.
Please advice.
Thanks in advance.