The problem you are seeing is that the properties are being expanded by the
compiler to:
string GetValue();
SetValue(string);
DateTime GetValue();
SetValue(DateTime);
The Set methods are not too much of a problem as C# follows C++ overloading
rules and allows for methods to have the same name but different types of
parameters.
The Get methods however only differ by return value and therefore are seen
to be the same method. Incidently the CLR does support methods having the
same name but a different return value it's just that the language doesn't
for a variety of reasons.
Based on the code below if this class is to be used then having two fields
holding the same value is probably asking for trouble (normalisation of data
etc.).
If the class is wrapping a DateTime then I'd suggest:
1. Only contain a DateTime field; lose the string.
2. Use the Value accessor to get/set the DateTime value (or possible use
conversion operators see below).
3. Use ToString to convert the DateTime to a string.
4. Either add a SetValue(string) and parse the string into the DateTime
field or look into using conversion operators (see
http://windowssdk.msdn.microsoft.com.../85w54y0a.aspx).
HTH
- Andy
"AAJ" <a.a.com> wrote in message
news:%(E-Mail Removed)...
> Hi all
>
> I would like to have a class that can set/return values of different
> datatype via a single accessor, i.e. overload the accessor
>
> i.e. something like
>
> DateTime m_DateValue;
> string m_StringValue;
>
> public string Value
> {
> get { return m_StringValue; }
> set { m_StringValue = value; }
> }
> public DateTime Value
> {
> get { return m_DateValue; }
> set { m_DateValue = value; }
> }
>
> so I can use something like
>
> ValueHandler testDate = new ValueHandler();
> testDate.Value = "1/1/2006";
> DateTime returndate = testDate.Value;
>
> As well as
>
> ValueHandler testString = new ValueHandler();
> testString.Value = "My test String";
> string returnString = testString.Value;
>
> i.e. depending on the datatype, I can use the same accessor to store in
> either a DateTime field or a string field
>
> is there anyone who knows how to do this
>
> thanks
>
> Andy
>