473,396 Members | 1,785 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Setting property value to string or accessing property methods

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?

Thanks!!


Nov 21 '05 #1
2 1402
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]
Nov 21 '05 #2
Thanks for the info, I'll just stick to keeping my properties and methods
seperate for now then.
"Tom Shelton" <ts******@YOUKNOWTHEDRILLcomcast.net> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
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]

Nov 21 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: user | last post by:
I have gotten properties to respond correctly, but when I try to do it in __init__: class foo: def getter(self): return "hello" def __init__(self):
21
by: Michael Bierman | last post by:
Please forgive the simplicy of this question. I have the following code which attempts to determine the color of some text and set other text to match that color. It works fine in Firefox, but does...
11
by: Alexander Walker | last post by:
Hello I would like to write a method that allows me to pass a reference to an instance of a class, the name of a property of that class and a value to set that property to, the method would then...
37
by: Joergen Bech | last post by:
(Slightly religious question): Suppose I have the following class: ---snip--- Public Class MyClass Private _MyVariable As Integer Public Property MyVariable() As Integer Get
2
by: garyusenet | last post by:
I could do with something similiar, can you tell me if you think this would work for me, and if there's any advantage in working with controls this way than how I currently am. At the moment...
3
by: Patient Guy | last post by:
Subject line would seem to say it all: How does one trigger the execution of a method within an object or any other code/function with the setting of an object property? More elaboration for...
7
by: FAQ server | last post by:
----------------------------------------------------------------------- FAQ Topic - How do I access a property of an object using a string?...
41
by: Jim | last post by:
Hi guys, I have an object which represents an "item" in a CMS "component" where an "item" in the most basic form just a field, and a "component" is effectively a table. "item" objects can be...
6
by: =?Utf-8?B?SmF5IFBvbmR5?= | last post by:
I am trying to access a Public property on a Master Page from a Base Page. On the content pages I have the MasterType Directive set up as follows: <%@ MasterType virtualpath="~/Master.master" %>...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.