I get too excited over new ways to work with generics

I do love a way to re-write code to make it even cleaner, so I'm a great fan of C#s generic List<T>.find() method as it allows me to search a list without the mess of a foreach loop and holding variable.

I do, however, always have to Google for the exact result if the condition is never met (so the thing we are searching for is never found), which, by the way, is default(T).

For example:

   1:  List<DateTime> dateList = generateDates();
   2:  DateTime dateWeWant = generateDateWeWant();
   3:  DateTime resultDate = dateList.find(delegate(DateTime searchDate){return (resultDate = dateWeWant);});
   4:  if (resultDate != default(DateTime))
   5:  {
   6:  //Found the date, work with it
   7:  else
   8:  {
   9:  //Not found the date, do something else (Don't you just love programmer grammar?)
  10:  } 

Which is all well and good, but there is an alternate syntax that gives the predicate an extra scrub and makes it look even prettier:

   1:  List<DateTime> dateList = generateDates();
   2:  DateTime dateWeWant = generateDateWeWant();
   3:  DateTime resultDate = dateList.find(testDate => testDate == dateWeWant );
   4:  if (resultDate != default(DateTime)
   5:  {
   6:  //Found the date, work with it
   7:  }
   8:  else
   9:  {
  10:  //Not found the date, do something else (Don&#39;t you just love programmer grammar?)</span>
  11:  } 

Is veeery niiiiiice.

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Posted by: Chris
Posted on: 10/30/2009 at 5:36 AM
Actions: E-mail | Kick it! | DZone it! | del.icio.us
Post Information: Permalink | Comments (20) | Post RSSRSS comment feed

Usfull web stuffs (triangles and color pallets)

Triangles in CSS you say?  Oh yes my friend....an interesting abuse of a feature: http://www.dinnermint.org/css/creating-triangles-in-css/  Hell, i didnt even know you could do the 4 color definition thing.

 

A bunch of tools - more specifically the color builder ones: http://webdesignledger.com/tools/15-free-online-tools-for-web-designers-on-a-budget

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Posted by: Chris
Posted on: 10/28/2009 at 4:53 PM
Actions: E-mail | Kick it! | DZone it! | del.icio.us
Post Information: Permalink | Comments (32) | Post RSSRSS comment feed

Article on .NET Configuration Files

Right Here:  A really good basic overview, and it promises (I'm still reading it) some more advanced trickery.  It also has a link in it to a download of the Framework Src...which looks like the CLR source with a build environment :)

New Toys!

Article:

http://www.codeproject.com/KB/dotnet/mysteriesofconfiguration.aspx

The Framework Src:

http://www.microsoft.com/downloads/details.aspx?FamilyId=8C09FD61-3F26-4555-AE17-3121B4F51D4D&displaylang=en

The song I'm listening to:

http://vampirefreaks.com/missnull

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Posted by: Chris
Posted on: 10/23/2009 at 5:38 AM
Actions: E-mail | Kick it! | DZone it! | del.icio.us
Post Information: Permalink | Comments (18) | Post RSSRSS comment feed

The Nerd Diagram

While waiting for the stupid Visual Studio "Oops, you hit F1 by accident and we are going to lock up for an hour or three" dialouge to go away I found this gem stumbling around the Internet - Many people ask me what the difference between a geek and a nerd is....this explains it better than I could (in pretty graphic form....very geekish):

 

http://www.dula.tv/blog/picture/the-nerd-diagram/

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Posted by: Chris
Posted on: 10/4/2009 at 12:11 PM
Actions: E-mail | Kick it! | DZone it! | del.icio.us
Post Information: Permalink | Comments (35) | Post RSSRSS comment feed

Getting a Label control to not wrap everything in a Span tag.

When internationalising a website, you really do care about what HTML gets placed into your code - in this particular case injecting <span> tags into a table with both left-to-right text and right-to-left text really REALLY confuses Firefox and Opera as to which direction to put the text.  The solution to this, we discovered, was to wrap the text in Paragraph tags, to give the browser some kind of a hint that this text should be lifted out of the RTL flow and LTRted.

Problem:

The text was placed using a custom control, which then used the System.Web.UI.Webcontrols.Label control to place the text, which we discovered was the culprit behind the offending span tags.

Digging around in the framework source code I discovered the offending tags were not, as we had thought, placed by Label itself but by System.Web.UI.Webcontrols.WebControl.   Not having time to change said control to a Literal (which did not inherit from WebControl, thus would also loose all the associated functionality along with that, like CssClass) we opted to try and change the way Label worked and spit out P tags instead.

Now, anyone who has tried to change the functionality of the Framework will know alot of things in there are private and internal which makes it a proper pain in the ass to change anything Microsoft  don't want you to change and in this case I can see why - it uses the surrounding tag to add the CssClass functionality et all, and needs SOMETHING to place there, plus if you surround the text with the wrong thing, it will try to add the class= attribute (ok, I know class is pretty much avaliable to any tag, but there could be other things it needs it for) and could screw things up - but I know that, and I'm building my own damn controls, with their own damn protection - so I want to change the damn tag.

Ok, So I grab the Label.cs and WebControl.cs files, and start digging through them and discover that the Tag it surround the surrounding tags are inserted on Render() from the tagKey private field.  So we cant change that without overriding Render(), which I have a great dislike for doing (if in the future they add something and I've overriden it, things could break, so I like to target the specific functionality instead) so we need to find how to mess with the tagKey member field.

 tagKey is set via the constructor of the class thusly:

   1:  protected WebControl() : this(HtmlTextWriterTag.Span) { 
   2:  }
   3:   
   4:  public WebControl(HtmlTextWriterTag tag) { 
   5:      tagKey = tag;
   6:  } 
   7:   
   8:  protected WebControl(string tag) { 
   9:      tagKey = HtmlTextWriterTag.Unknown;
  10:      tagName = tag;
  11:  }

 

which would seem to be easy to change but wait!  Label implements its constructors like so:

   1:  public Label() {
   2:  } 
   3:   
   4:  internal Label(HtmlTextWriterTag tag) : base(tag) {
   5:  }

 

Which...is a problem. They have blocked all our access to the string constructor (as constructors don't inherit without a similar constructor in the inheriting class, with the base() keyword) and made the HtmlTextWriterTag constructor internal...which means we can'tdo anything with it.

Fortunatly, the tagKey private field is encapsulatedwith a protected virtual public property as so:

   1:  [
   2:  Browsable(false), 
   3:  DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)
   4:  ] 
   5:  protected virtual HtmlTextWriterTag TagKey { 
   6:      get {
   7:          return tagKey; 
   8:      }
   9:  }

 

Win! We can override this, add our own private field, rebuild our constructorsand we are set.  The code follows:

   1:  public class FlexiLabel : Label
   2:  {
   3:      private HtmlTextWriterTag tagKeyOverride = HtmlTextWriterTag.Span;
   4:   
   5:      public HtmlTextWriterTag TagKeyOverride
   6:      {
   7:          get { return tagKeyOverride; }
   8:          set { tagKeyOverride = value; }
   9:      }
  10:   
  11:      [Browsable(false),DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  12:      protected override HtmlTextWriterTag TagKey
  13:      {
  14:          get
  15:          {
  16:              return tagKeyOverride;
  17:          }
  18:      }
  19:   
  20:      public FlexiLabel()
  21:          : base()
  22:      {
  23:      }
  24:   
  25:      public FlexiLabel(HtmlTextWriterTag inTagKey)
  26:          : base()
  27:      {
  28:          tagKeyOverride = inTagKey;
  29:      }
  30:  }

 

It's a pretty easy solution - but it's a pain digging through the framework src to figure it out.  Part of me wishes MS would make thigns a bit easier to navigate, but most of me have alot of respect and thanks to MS for releasing their source, it makes my life SO much easier.

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Posted by: Chris
Posted on: 8/28/2009 at 5:04 AM
Actions: E-mail | Kick it! | DZone it! | del.icio.us
Post Information: Permalink | Comments (29) | Post RSSRSS comment feed

IxC Site

One of my good friends, the rather talented Pete, just got his face and words into .net magazine - I have never bought this mag before as my professional remit dosn't really cover design, but it did have some really really cool design tips and UI geekery (like an overview of the facebook and Yahoo APIs).

One of the articles in this mag was about designer brochure sites, and I have decided that I am totally wasting IllegalException.com and the beautiful design Jess made for it, and it needs to stop.  Thus while I am waiting for more interesting projects to happen (I hate waiting for other people, I'm so damn impatient) I am going to drop out IxC's CMS, stop trying to put fancy code in there that no one sees, and just try to make a sexy, content filled website. 

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Posted by: Chris
Posted on: 8/25/2009 at 3:56 AM
Actions: E-mail | Kick it! | DZone it! | del.icio.us
Post Information: Permalink | Comments (25) | Post RSSRSS comment feed

Happy Canada Day!

Happy Canada Day!

Happy Canada Day!

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Posted by: Chris
Posted on: 7/1/2009 at 6:57 AM
Actions: E-mail | Kick it! | DZone it! | del.icio.us
Post Information: Permalink | Comments (33) | Post RSSRSS comment feed

Did you say...Paintball....Tanks

OH yes....I think you did:

http://www.iwantoneofthose.com/tank-paintball-battles/index.html

I think this hits so high on the awesome scale its worth breaking my vow of blog silence.

 

 

Ok, so I dont have a vow of blog silence, I'm just rubbish at updating it....but thats not the point - the TANKS are the point.

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Posted by: Chris
Posted on: 6/24/2009 at 6:07 AM
Actions: E-mail | Kick it! | DZone it! | del.icio.us
Post Information: Permalink | Comments (66) | Post RSSRSS comment feed

Arranging a relationship

......

How to promote yourself to the opposite sex - scarily enough I would most definatly date this person:

C - Stupid BHOs says (16:58):
 Diarra
 my new housemate
bunns .:. if today was your last day and tomorrow was too late; could you say goodbye to yesterday .:. says (16:58):
 yeah
C - Stupid BHOs says (16:58):
 thinks that me
 being me
 and you
 being you
 should get together in a relationship
 at the point that you visit england
 as I keep talking about you
bunns .:. if today was your last day and tomorrow was too late; could you say goodbye to yesterday .:. says (16:58):
 lmao it would be the best 2 week relationship ever!!!!
C - Stupid BHOs says (16:58):
 hell yeah
 it would be somewhat awesome
bunns .:. if today was your last day and tomorrow was too late; could you say goodbye to yesterday .:. says (16:59):
 and i think for that whole 2 weeks i might be able to abstain cheating on you.......no promises though!
C - Stupid BHOs says (16:59):
 lol

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Posted by: Chris
Posted on: 5/1/2009 at 10:55 AM
Actions: E-mail | Kick it! | DZone it! | del.icio.us
Post Information: Permalink | Comments (30) | Post RSSRSS comment feed

IPhone Manual

You know your cool when your phone's operating manual is the back page of the Metro!

 

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Posted by: Chris
Posted on: 2/17/2009 at 4:36 AM
Actions: E-mail | Kick it! | DZone it! | del.icio.us
Post Information: Permalink | Comments (41) | Post RSSRSS comment feed