Extensibility?

by javery on August 26, 2004

Let’s say you want to change the list of regular expressions normally displayed in the RegexTypeEditor, is this code a good sign? (Reflector is good)

private object[] get_CannedExpressions(){        object[] objArray1;      if (RegexEditorDialog.cannedExpressions == null)      {                objArray1 = new object[15];                objArray1[0] = SR.GetString("RegexCanned_Custom");                objArray1[1] = new RegexEditorDialog.CannedExpression(SR.GetString("RegexCanned_SocialSecurity"), @"\d{3}-\d{2}-\d{4}");                objArray1[2] = new RegexEditorDialog.CannedExpression(SR.GetString("RegexCanned_USPhone"), @"((\(\d{3}\) ?)|(\d{3}-))?\d{3}-\d{4}");                objArray1[3] = new RegexEditorDialog.CannedExpression(SR.GetString("RegexCanned_Zip"), @"\d{5}(-\d{4})?");                objArray1[4] = new RegexEditorDialog.CannedExpression(SR.GetString("RegexCanned_Email"), @"\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*");                objArray1[5] = new RegexEditorDialog.CannedExpression(SR.GetString("RegexCanned_URL"), @"http://([\w-]+\.)+[\w-]+(/[\w- ./?%&=]*)?");                objArray1[6] = new RegexEditorDialog.CannedExpression(SR.GetString("RegexCanned_FrZip"), @"\d{5}");                objArray1[7] = new RegexEditorDialog.CannedExpression(SR.GetString("RegexCanned_FrPhone"), @"(0( \d|\d ))?\d\d \d\d(\d \d| \d\d )\d\d");                objArray1[8] = new RegexEditorDialog.CannedExpression(SR.GetString("RegexCanned_DeZip"), @"(D-)?\d{5}");                objArray1[9] = new RegexEditorDialog.CannedExpression(SR.GetString("RegexCanned_DePhone"), @"((\(0\d\d\) |(\(0\d{3}\) )?\d )?\d\d \d\d \d\d|\(0\d{4}\) \d \d\d-\d\d?)");                objArray1[10] = new RegexEditorDialog.CannedExpression(SR.GetString("RegexCanned_JpnZip"), @"\d{3}(-(\d{4}|\d{2}))?");                objArray1[11] = new RegexEditorDialog.CannedExpression(SR.GetString("RegexCanned_JpnPhone"), @"(0\d{1,4}-|\(0\d{1,4}\) ?)?\d{1,4}-\d{4}");                objArray1[12] = new RegexEditorDialog.CannedExpression(SR.GetString("RegexCanned_PrcZip"), @"\d{6}");                objArray1[13] = new RegexEditorDialog.CannedExpression(SR.GetString("RegexCanned_PrcPhone"), @"(\(\d{3}\)|\d{3}-)?\d{8}");                objArray1[14] = new RegexEditorDialog.CannedExpression(SR.GetString("RegexCanned_PrcSocialSecurity"), @"\d{18}|\d{15}");                RegexEditorDialog.cannedExpressions = objArray1;      
}      return RegexEditorDialog.cannedExpressions;}

Basically you would have to create a new Type Editor which inherits from this one, then create a new control which inherits from the RegexValidator and then add an attribute targeting your new type editor. Obviously not built with extension in mind, unless I am missing something.

-James

{ 3 comments }

Baldrick Jameson August 26, 2004 at 1:38 am

What is your alternative?

Scott Mitchell August 26, 2004 at 2:00 am

Welcome to a large part of the .NET Framework 1.x. This is why it is often smart to wait until version 2.0 for any framework/product/etc.

For another example of lack of extensibility, see:

http://aspnet.4guysfromrolla.com/articles/051204-1.aspx

James Avery August 26, 2004 at 12:23 pm

My Suggestion? Maybe a public collection that coule be added to, hopefully on the actual control instead of on the editor.

Comments on this entry are closed.

Previous post: GMail Notifier

Next post: Clerks 2