Ask a Question related to ASP.NET Building Controls, Design and Development.
-
Simbad #1
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
-
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... -
#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... -
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... -
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,... -
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... -
Teemu Keiski #2
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



Reply With Quote

