Let's say I have type Point2D
(this is example), how can I use this type with ConfigurationSection
-- in other words, what methods I have to implement in order value of my type be created from string.
One way would be to provide TypeConverter
, is there another way? Without introducing extra types, solely within my custom type (in this example Point2D
)?
Another way, but it is more a trick, would be for example having properties x
and y
of know type int
, and then provide creator property to get Point2D
-- I don't want to go that path.
Update: Example as requested:
public sealed class MyConfig : ConfigurationSection
{
[ConfigurationProperty("LeftPoint", IsRequired = true),
TypeConverter(typeof(Point2DTypeConverter))]
public Point2D LeftPoint
{
get { return (Point2D )this["LeftPoint"]; }
set { this["LeftPoint"] = value; }
}
...
}
as you can see I use type converter for Point2D
and it works. No problem. However I wonder if it would be possible to do conversion (parsing really from string) inside my type Point2D
so I could remove entire converter (not as attribute tag, but completely).