This space is available to any ComponentArt employee to write about anything.

MaskedInput Transform Intellisense


MaskedInput class's Transform property that I described in depth in a few preceding blog posts presented us with an interesting design dilemma. At first it seemed like it should be a typical enumeration property, with one value for each Transform type. However, since the architecture allowed new Transform types to be added in a number of different ways (see the previous blog posts), the enum turned out to be too stifling. For that reason, we opted for a string instead.

However, we still wanted to offer some Intellisense, to give the developer a hint at the values he would most likely want to use. We did it by placing the TypeConverterAttribute on the Transform property:
public sealed class MaskedInput : BaseInput
{
  ...
  [TypeConverter(typeof(MaskedInputTransformConverter))]
  public string Transform
  {
    get {...}
    set {...}
  }
  ...
}

The implementation of MaskedInputTransformConverter is very simple:
/// <summary>
/// Provides Visual Studio intellisense for Transform property.
/// The list of StandardValues here corresponds to the properties of client-side ComponentArt_MaskedInput_Transforms object.
/// </summary>
public class MaskedInputTransformConverter : TypeConverter
{
  public string[] StandardValues =
  {
    "empty", 
    "CreditCard_VisaMasterCard",
    "CreditCard_AmEx",
    "Telephone_NorthAmerica",
    "ZipCode",
    "PostalCode",
    "PostalCode_Australia",
    "EmailAddress"
  };
  public override StandardValuesCollection GetStandardValues(ITypeDescriptorContext context)
  {
    return new StandardValuesCollection(StandardValues);
  }
  public override bool GetStandardValuesSupported(ITypeDescriptorContext context)
  {
    return true;
  }
}

This works really well in ASPX Intellisense, popping up the list of standard values, without forcing you to use one of them - exactly the behaviour we needed. The Intellisense also works for the Properties pane. Unfortunately it does not work in the CodeBehind files, and I don’t think there is a way to implement it there.

Share this post: email it! | bookmark it! | digg it! | reddit!

Posted by: Jovan
Posted: Monday, October 27, 2008 7:06 AM


Comments

Eli Gassert said:

Although you won't get direct intellisense, I'd also recommend having a public static class that contains public static readonly strings for each of the types. Something like: public static class StandardTypes { public static readonly string Empty = "empty"; public static readonly string CreditCard_VistaMasterCard = "CreditCard_VisaMasterCard"; ... } That way, people can at least say Transform = StandardTypes.ZipCode; and not have to worry about string literals. Alternatively you could use an enum and transform from the enum to the string representation. I'd be interested in knowing if using an enum type converter would reveal intellisense in the codebehind. Anyway, one last thing to consider. I wonder what would happen if you used a partial method or a delegate/event that allowed third-party transform developers to "hook" into the type converter and add values. GetStandardValues could simply call the partial method, delegate, or event to allow the standard list to be "widened" with the additional values. All of this is just theory. If none of it works, or if I've misspoken, then my apologies :) Cheers -eli
# October 27, 2008 9:01 AM

Jovan said:

Some very interesting ideas, thank you.  I will look into this as soon as I get a chance.  Probably later this week.  I'll report back if I am able to get any of these techniques to work.

# October 27, 2008 2:36 PM
Leave a Comment

(required) 

(required) 

(optional)

(required) 


Blogs On This Site
Thoughts on web user interfaces and component development.
Ramblings of a web control developer.
Web.UI news and more
Next weeks guest: A dog and a baby dog!
I'm in your base, killing your dudes.
Absurdity is it's own message.
Musings of an ex Java developer
im in ur page, hackin ur codez
ComponentArt in the Community
... and the program ran happily ever after.

This Blog