Object property with different return types

Ask a Question related to ASP.NET Building Controls, Design and Development.

  1. #1

    Default Object property with different return types

    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
    Simbad Guest

  2. Similar Questions and Discussions

    1. Return focus to custom property inspector?
      Hello, I'm working on a Dreamweaver CS3 extension that includes custom property inspector for 'div' tag with specific attributes. Using the...
    2. #29234 [Com]: empty($object->property) incorrect when property has access overloaded (__get)
      ID: 29234 Comment by: phpbugs at thunder-2000 dot com Reported By: chrissy at codegoat dot com Status: No...
    3. is it possible to bind required property of thevalidator to some variable or return value from a function
      In my code I need to change the required property of validator change based on a selectedItem of a list component. I do not want validators to...
    4. Serializing complex types in return message
      Hello, I'm working with a scenario where I have a base abstract data entity (ContactDTO) and a number of inherited concrete classes (ex,...
    5. Web Service with complex paramters and return types
      I'm starting to think about my first web service. In order to do its job, this web service needs to have a lot of inputs, and it needs to return...
  3. #2

    Default Re: Object property with different return types

    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" <anonymous@discussions.microsoft.com> wrote in message
    news:094a01c3d918$73f0a8a0$a101280a@phx.gbl...
    >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 Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

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 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139