Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Building Controls > Object property with different return types

Reply
Thread Tools

Object property with different return types

 
 
Simbad
Guest
Posts: n/a
 
      01-12-2004
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
 
Reply With Quote
 
 
 
 
Teemu Keiski
Guest
Posts: n/a
 
      01-18-2004
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).

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


"Simbad" <> wrote in message
news:094a01c3d918$73f0a8a0$...
>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



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Different behaviour in different struct declaration types __PaTeR C Programming 7 01-01-2009 12:13 AM
virtual method with different return types? Bit byte C++ 2 04-16-2006 12:20 AM
what value does lack of return or empty "return;" return Greenhorn C Programming 15 03-06-2005 08:19 PM
how to return different data types using a base class and pure virtual methods Mitch Mooney C++ 2 06-18-2004 07:52 AM
Boost + Python C/API: Mixing python return types with boost return types Steve Knight Python 2 10-10-2003 10:11 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57