Scott Hanselman

Now THERE'S a Training Session I'd like to take...

January 31, 2005 Comment on this post [2] Posted in ASP.NET
Sponsored By

This looks hot...a little something JasonW at DM is cooking up. Guerilla .NET 2.0 in London. Here's his outline:

  • The CLR, how it works, and what's new for v2.0
  • Garbage collector stuff inclduing the good, bad, and ugly of new stuff like HandleCollector and GC.AddMemoryPressure
  • C# type system stuff including Generics and Nullable
  • Fun with delegates including where Anon delegates actually make sense, including the Async Delegate Two-Step
  • Windows Forms.  Ian will give that talk, need I say more?
  • ADO.NET 2.0. Richard Blewett will be there and my guess is we'll have to chase him off the stage with a stick
  • The aforementioned new async coverage.  Two lectures worth of material.
  • Deployment, Deployment, Deployment. Fusion. ClickOnce. CAS.
  • Umanaged code Interop. The lab for this one is really cool - you'll have to see it to believe it.
  • "Old school" Networking. We'll actually talk less about remothing than we've done in the past, but more about sockets and MSMQ. 
  • HTTP - I wrote a brand new two-lecture look at "modern" HTTP programming starting with HttpListener and going all the way through ASP.NET and, of course, the much-hyped WebServices.

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

facebook bluesky subscribe
About   Newsletter
Hosting By
Hosted on Linux using .NET in an Azure App Service

RELEASE: FormattableObject an Aggregating reflection-based ToString() implementation

January 30, 2005 Comment on this post [3] Posted in ASP.NET | Internationalization | CodeRush
Sponsored By

Well, here you go, it's my implementation of a FormattableObject that I mentioned earlier. Take a look at the comments, Mark Miller had some great ideas, the best of which being a CodeRush plugin that handles the static analysis at design time and makes it harder to mess up these strings.

You can do this:

[Test]

public void MakePersonFormattedStringWithFormat()

{

    Person p = new Person();

    string foo = p.ToString("{BirthDate:D} My name is {FirstName} {LastName} and I'm cool.");

    Assert.AreEqual("Tuesday, January 22, 1974 My name is Scott Hanselman and I'm cool.", foo);

}

or

[Test]

public void MakePersonFormattedStringWithFormatAndChineseCulture()

{

    Person p = new Person();

    string foo = p.ToString("{BirthDate:D} My name is {FirstName} {LastName} and I'm cool.",new System.Globalization.CultureInfo("zh-cn"));

    Assert.AreEqual("1974?1?22? My name is Scott Hanselman and I'm cool.", foo);

}

You can either:

  • Derive your objects from FormattableObject and you get these ToString implementations for free

or

  • Implement a few ToString's and IFormattable yourself and delegate over to the static implementations in FormattableObject:

 
public string ToString(string format, System.IFormatProvider formatProvider)

{

    return Corillian.Voyager.Common.ObjectFormatString.ToString(this,format,formatProvider);

}

 

public string ToString(string format)

{

    return this.ToString(format,null);

}

Here you go, enjoy.  If you don't, screw you.  If you do, I take full credit.

FormattableObject 0.5 (11kb)

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

facebook bluesky subscribe
About   Newsletter
Hosting By
Hosted on Linux using .NET in an Azure App Service

Work continues on dasBlog...

January 29, 2005 Comment on this post [4] Posted in ASP.NET | DasBlog | Bugs
Sponsored By

The team's work continues on dasBlog. You can see the moment to moment details in the Bugs or Tracker section of SF.

If that's too much data, there's a roll up on the Wiki that shows the bugs, new features and goodness that'll be in an upcoming "point release" of 1.7 if you've been wisely hanging back while we tighten the screws.

Here's some highlights:

  • Admin: UploadImage and UploadAttachment have returned in their previous incarnations. We also include the Image Gallery (which some people dig immensely) and support for an RSS Enclosure.
  • Macros: We support two new macros for "Compressed Titles" that can allow dasBlog users to completely remove the look of "permalink.aspx" in lieu of something like: http://www.hanselman.com/blog/WorkContinuesOnDasBlog.aspx. Some tweaks and controversy remain. We shall see.
  • Small Breaking Change: The TitleList macro will require parens to be called, ala TitleList().
  • And lots of small bug fixes.

More soon.

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

facebook bluesky subscribe
About   Newsletter
Hosting By
Hosted on Linux using .NET in an Azure App Service

Is this a good idea? Has it been done? Should it? An Aggregating ToString() implementation...

January 27, 2005 Comment on this post [14] Posted in ASP.NET | NUnit
Sponsored By

Travis and I were kicking around this idea. It's either already been done and it's a great idea, it's a good idea and no one has bothered, or it's stupid because _______.

We use a lot of "Domain Objects" like say, "public class Person." Why not have a "aggregated" ToString override like this:

Person p = new Person("Scott","Hanselman",new DateTime(1974,1,22);
//blah blah blah
string foo = p.ToString("My name is {FirstName} {LastName} and my birthday is {Birthdate:MM/dd/yyyy}");

Is this stupid? Would it gain you anything over:

string foo = String.Format("My name is {0} {1} and my birthday is {2:MM/dd/yyyy}",p.FirstName,p.LastName,p.BirthDate);

I've got it half done, but I wanted to know your thoughts before I finish it.

My thinking is that, even though it'd be slow (Reflection) it's useful for these reasons:

  • Quick Testing - Seems convenient to me, useful for NUnit.
  • Ultra-Late Bound - Ya, I know I'm Mr. So-Early-Bound-I-Generate-Everything but sometimes you just don't know until late, which leads me to:
  • Externalization of Complex Formatted Strings - True, you're embedding knowledge of your properties in a string, but it'd allow you to add a different series of fields if another language required it. This would be an improvement over ordinal style ({0}, {1}) format strings, no? Perhaps a silly use case.
  • DataBinding - You can let an ASP.NET DataGrid just call ToString on an object and it'll "do the right thing" as opposed to doing a TemplateColumn or an OnItemDataBound callback.
  • It just calls down into the underlying object's ToString - It's basically using the aggregate ToString's format string to get Properties and Fields and call their respective ToString's using the embedded (after the colon) format string.

Am I smoking crack?

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

facebook bluesky subscribe
About   Newsletter
Hosting By
Hosted on Linux using .NET in an Azure App Service

Turning off AutoComplete for TextBoxes in IE and FireFox

January 26, 2005 Comment on this post [6] Posted in ASP.NET
Sponsored By

This is one a lot of people know, but it's worth covering again because it's easily forgotten as it's a small detail. Since we do eFinance sites, we often don't want folks' UserNames collected and stored in AutoComplete, especially when the site is browsed on a public machine.

<form id="formSignOn" autocomplete="off" method="post" runat="server">

Note that autocomplete="false" doesn't work. However, autocomplete="off" works in both IE and FireFox.

Thanks to Johnson Michael for reminding me of this tip.

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

facebook bluesky subscribe
About   Newsletter
Hosting By
Hosted on Linux using .NET in an Azure App Service

Disclaimer: The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.