On 2005-05-26, Brian Mitchell <Ma********@hotmail.com> wrote:
Hello, I am trying to create a property that can be set to a string or give
the user a list of methods inside that property.
For instance, I have the property -Location-. I would like the option of
either saying something.Location="Houston" OR something.Location.GetLocation
(which sets a private variable) . Is there a way of doing this?
There is no way to do that in the current VB. That would require an
implicit conversion operator defined for your Location object property.
It can however be done in C# (and probably VB.NET 2005 - I'd have to
check):
using System;
public class Location
{
private string location;
public string GetLocation ()
{
return this.location;
}
public static implicit operator Location (string theString)
{
Location loc = new Location ();
loc.location = theString;
return loc;
}
}
public class Something
{
private Location location = new Location ();
public Location Location
{
get
{
return this.location;
}
set
{
this.location = value;
}
}
public static void Main ()
{
Something something = new Something ();
something.Location = "Huston";
Console.WriteLine (something.Location.GetLocation ());
}
}
Very simple example - not something I would normally recommend doing...
--
Tom Shelton [MVP]