Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / Building Controls / January 2004

Tip: Looking for answers? Try searching our database.

Object property with different return types

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Simbad - 12 Jan 2004 14:29 GMT
I have a control 'MyControl' with a property of
type 'MyObject'.  MyObject has a property 'MyField' that
is a enum type.  I want the type of enum to vary
depending on a another property of MyObject
called 'MyFieldType'.  E.g. if MyFieldType = TypeA,
MyField returns EnumA.  See code below:

public enum FieldTypes
{
TypeA,
TypeB
}

public enum EnumA
{
Big,
Medium,
Small
}

public enum EnumB
{
Short,
Tall,
Squat,
Huge
}

[DefaultProperty("MyFieldType")]
public class MyObject
{
 private FieldTypes m_MyFieldType;
 private object m_MyField = 0;

 public FieldTypes MyFieldType
 {
   get {return m_MyFieldType;}
   set {m_MyFieldType = value;}
 }

 public object MyField
 {
   get
   {
     if (MyFieldType == FieldTypes.TypeA)
     {
       return (EnumA)m_MyField;
     }
     else
     {
       return (EnumB)m_MyField;
     }
   }
   set
   {
     m_MyField = value;
   }
 }
}

My problem is that the MyField property is not editable
via a dropdown list in the designer.  It appears as a
greyed-out (read only) string representation of the
respective enum (EnumA or EnumB).  I've tried writing a
TypeConverter (inheriting from EnumConverter) but just
ended up going round in circles.

Does anyone have an example of what I'm trying to do or
point me in the right direction?

Thanks
Teemu Keiski - 18 Jan 2004 13:36 GMT
Hi,

I suspect that the property should be of only one type for it to work
correctly. You can't parameterize its type (the type needs to be fixed at
design-time).

Signature

Teemu Keiski
MCP, Microsoft MVP (ASP.NET), AspInsiders member
ASP.NET Forum Moderator, AspAlliance Columnist

>I have a control 'MyControl' with a property of
> type 'MyObject'.  MyObject has a property 'MyField' that
[quoted text clipped - 67 lines]
>
> Thanks

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.