Wednesday, April 07, 2004
A rant about the state of things
4/7/2004 2:46:16 PM (GMT Standard Time, UTC+00:00)  #    Comments [0]  |  Trackback
the hard way
Programming | .Net | C#
4/7/2004 2:27:08 PM (GMT Standard Time, UTC+00:00)  #    Comments [0]  |  Trackback
Tuesday, April 06, 2004

Serialization is one of my favorite features of .Net and I use it more every day.  Much like Xml, once you've gotten the hang of it, you find new uses every time you turn around. 

Today I wanted to serialize to string.  Simple enough?  The examples I found online often created byteArrays and char arrays and went through more work than necesary.  So, for those who are searching like I was, here is the simplest example I could write.

The simplest overload provided by the Serialize method of the System.Xml.Serialization.XmlSerializer class takes two parameters: TextWriter and an instance of the class to serialize. 

System.IO.StringWriter inherits from TextWriter, therefore, it can be used in this method call.

using System;

using System.Xml.Serialization;

using System.IO;

 

namespace HPCi.ResourceGuide.Google

{

      [Serializable]

      ///

      /// A very simple entity class

      ///

      public class Class1

      {

            ///

            /// A couple of public fields. 

            /// In the real world, I always create

            /// private fields with public accessors

            /// additionally, I usually initialize fields to

            /// default values or empty values rather than null

            ///

            public string MyPublicStringField = String.Empty;

            public bool IsPrettyCool = true;

 

            ///

            /// Serialization of the class

            /// Incredibly simple and can be used for any class,

            /// just change the type

            ///

            /// string

            public string SerializeToXml()

            {

                  // Serialization of Class into string of xml

                  XmlSerializer xmlsSlzr = new XmlSerializer( typeof( Class1 ) );

                  StringWriter sw = new StringWriter();

                  xmlsSlzr.Serialize( sw, this );

                  return sw.ToString();

            }

      }

}

note:  you could easily make this a static method and pass in the class instance to serialize.  Use reflection to create a type to pass to the XmlSerializer contructor. 

The following code illustrates this:

public static string SerializeToXml(object obj)

            {

                  // Serialization of generic Class into string of xml

                  XmlSerializer xmlsSlzr = new XmlSerializer( obj.GetType() );

                  StringWriter sw = new StringWriter();

                  xmlsSlzr.Serialize( sw, obj);

                  return sw.ToString();

            }

      }

}

 

I don't like this approach as much as it reminds me too much of vb and utility function libraries.  A less oo approach.

Programming | .Net | C#
4/6/2004 9:32:28 PM (GMT Standard Time, UTC+00:00)  #    Comments [2]  |  Trackback
My new car stereo has affected my ability to park correctly...
4/6/2004 5:38:18 PM (GMT Standard Time, UTC+00:00)  #    Comments [1]  |  Trackback
Monday, April 05, 2004

While prototyping a generic form generator, I found success when using Type.GetType() to get a System.Type instance.  I passed in the string name of the “Type” I wished to inspect, for instance:

Type type = Type.GetType("MyNamespace.MyClass");
// List of properties that belong to the given Type
PropertyInfo[] itemTypeProperties = type.GetProperties();
// Object property
PropertyInfo property;
// Loop through the properties of the specified Type
for(int i = 0; i < itemTypeProperties.Length; i++ )
{
   ...make some labels and form fields
}

The class MyNamespace.MyClass was defined in a sepecate .cs file within the same project as the Form where I called the above code.  Everything worked great!

I wanted to move the class .cs file to its own project as it will be reused by more than one project (aah!  good, eh) but, when I did, the above code failed.  ...but, for why?!

I checked that the reference was appropriately made to the new project and that the build order and dependencies were correct but I got a null reference after the line:
Type type = Type.GetType("MyNamespace.MyClass");

I then tried the following.

// Get an instance of the desired class
MyNamespace.MyClass MyInstance = new MyNamespace.MyClass;
// Get the Type from the class instance
Type type = MyInstance.GetType();
// ...continue as before
// List of properties that belong to the given Type
PropertyInfo[] itemTypeProperties = type.GetProperties();
// Object property
PropertyInfo property;
// Loop through the properties of the specified Type
for(int i = 0; i < itemTypeProperties.Length; i++ )
{
   ...make some labels and form fields
}

For the life of me, I can't figure out why moving a file outside the project causes a failure.  I assume there is something I am missing about assembly inspection that is probably quite obvious.  If I figure it out, I'll post a follow up.  If you figure it out, tell me why I'm dumb

Programming | .Net | C#
4/5/2004 9:44:58 PM (GMT Standard Time, UTC+00:00)  #    Comments [1]  |  Trackback
Wednesday, March 31, 2004

How to cope with life's negative emotions.

Vocabulary is a pwerful thing.  It makes a real difference what words you use to describe something, even with yourself.

When experincing "anger" over something that someone did or did not do (and this applies to professional and personal situations), ask yourself if it is really "anger" you are feeling.  Often, you'll find that your emotions have self-fueled themselves a little hotter than they really are.  Most of the time you can downgrade to "disappointed" rather than "angry".  Disappointment brings feelings of frustration and these, repeated over time, can boil over and become exagerated. 

If you are really angry, you need to act.  Someone has hurt or threatened you physically!  They have caused you danger or put you in harm's way.  If not, is it really anger?  Are you not sure? Then repeat the first paragraph.  Otherwise, read on...

Now that you've placed the emotion where it belongs, ask yourself why you are disappointed.  Disappointment is always a mismatch of expectations and results or experience.  Now you merely have to decide if you were appropriate with your expectations.  As Michael said, “If all else fails, lower your expectations.”   Having unrealistic expectations causes everyone stress.  If you have experienced the same frustrating situation over and over and not adjusted your expectations, who is to blame for your disappointment?  Einstein said, “Repeating the same behavior and expecting a different result is the definition of insanity” (or something like that). 

When someone truly drops the ball and doesn't reach a reasonable goal, deliverable or standard, you have every right to be disappointed.  Communicate that in a calm and proactive way.  The next time a similar situation comes up, be appropriate, expect better than last time but don't hope for a miracle.  Well, you can hope, as long as you understand that hope implie doubt.  Know that the same thing can happen again.  Be sure to communicate what you exepct up front!

What to do when expectations are disappointing in themselves?  That's when action is required.  If someone consistently repeats a very diappointing behavior and you have to keep lowering your expectation of them, it might be time to find someone else to count on. 

All the answers cannot be had by changing a word here and there.  Always being less aggressive will mean you are always less effective.  That's not good either.  Balance is the key. 

The bottom line is that we are all master of our own emotions.  Your emotions begin with you and end with you and directly effect only yourself.  If you can chose whether to feel mildly disserved or furiously miserable, why would you chose the latter?

As far as vocabulary goes, consider this if you don't believe a choice in word can make such a difference: Americans have hundreds of words for money but only one for love.  What seems to be the most important thing to americans in this day and age?  ...and why am I still at work, getting ready to go to a professional study group, when my wife and 11 month old son are at home practicing walking?  Not because I want to, but because money is very important in America.  (that doesn't mean I don't enjoy the group, just that a lot of life can be missed while you're trying to boost your corporate value...)

 

3/31/2004 11:14:46 PM (GMT Standard Time, UTC+00:00)  #    Comments [1]  |  Trackback
Friday, March 26, 2004

I have been trying to use VSS integration with VS.Net for well over a year.  It works great at home when I am by myself.  I can track changes and keep versions in history and can confidently change code knowing that I can roll back if I have to.  At work, however, when it is critically important, the integration has limitations that result in having to use VSS explorer outside of VSS.Net.

I have come to very few revolutionary conclusions.  I was hoping to get to a point where I could recommend a configuration for a large development team.  Unfortunately, I can only express that for those who wish to use it, VSS integration is tolerable.

First off, only bind what you will be editing.  If you aren't going to be changing a project that is part of a larger solution, get the files from source control and use them locally but don't bind them to the VSS location.  If you don't need the source code at all (for debugging or stepping through funtionality) simply get the binaries and use the compiled dll.  Its much easier and saves a lot of time when getting latest.

For a project that you do modify and require VSS functionality, here are some tips:

  • Project should remain writable.  It is a pain in the butt to have to check the project out to remove a component from the project or to add a test page.  When you need to make persistent project changes, check out the project file externally, make your changes, check it back in, then mark the file writable again.
  • In VS.Net, under tools --> options --> Source Control --> General:  check the box 'Allow checked in items to be edited'
  • Now you can chose “edit“ in the Source Control dialog in addition to check out, when you attempt to modify a file.  Very useful when you want to add a simple message or line of test code but do not want to persist that change
  • When you try to save the file, you can choose “save as“
  • right click on the file you want to save, choose properties, uncheck read only.
  • Save your edited file
  • When you get latest next time, over write your changes if you want to

 

Its cumbersome but marginally useful.  Its like a cup holder that doesn't really hold any cup well (my Acura) but is better than no cup holder at all (my Westfalia)

 

That's all I have for now, if I think of anything else, I'll let you know.

 

Programming | .Net | C#
3/26/2004 4:15:37 PM (GMT Standard Time, UTC+00:00)  #    Comments [0]  |  Trackback
Monday, March 22, 2004

I spent about 11 hours on my car stereo this past weekend.  I got two of four speakers installed!  I will do the other two next weekend. 

I could have paid someone to install my car audio but I wanted to make sure it was done right.  I had an amplifier installed at HiFi Buys about three years ago and they not only did an awful job, they fried my existing stereo.  They replaced it with an Alpine but took three days consisting of 16 hours to get it finished.  When they were done, my clock no longer lit up on the dash board and there was a huge crack in the plastic behind the fold-down rear seat.  You get what you pay for!

Whe I've finished the door speakers, I will replace the head unit.  That shouldn't take but an hour. 

Following that I will install two amplifiers.  Small, inexpensive ones, of course!  These will take several hours.  They require lots of wires be run.  It annoys me that car stereo equipment requires thicker wire than an arc welder but, according to all the newgroups and wire guage tables, it is really necessary.  When I have the amps in place, I will need to build a box for my sub and get that installed as well.  The box should take a day and the install only a minute and 5 seconds. 

From that point forward I will be smiling every time I have to drive somewhere, everytime traffic crawls to a stop, everytime the light turns red in front of me and every time the clock tells me it is time for my commute home. 

3/22/2004 9:01:44 PM (GMT Standard Time, UTC+00:00)  #    Comments [1]  |  Trackback

I thought having a baby would be the maturing factor in my late twenties life, making me unquestionably an adult.  I have to admit the reality is sobering.  A tiny person’s life is not only a result of your actions but also completely dependent on you.  However, I haven’t acted like such a kid, such a goofy, bumbling, silly person since I was as tall as my 11-month son!  So having children is as maturing as a rollercoaster ride at Six Flags. 

We just put a contract on a house!  Now I am a real adult.  I am going to enjoy all the benefits and responsibility of home-ownership.  It’s been a lot of fun so far!  I am very pleased to think that I own some lawn and a fence and a bunch of walls, not to mention the dishwasher, fridge, stove, garbage disposal, lighting fixtures, furnace, basement, sun room, porch, attic, cabinets and molding.  I have a mortgage, a second mortgage, homeowner’s insurance, a security system, pest-control, water, gas and electric hook-ups and all the systems that make it all work.  Talk about coming screeching into adulthood! 

My wife and I are tremendously excited to start investing in our property.  We already had that feeling of belonging and purpose and righteousness in our rental because we residing together.  It didn’t matter if it were an apartment, a hotel room or a van down by the river.  It was home.  Now we can paint the ceiling midnight blue if we want to without asking anyone’s permission.  It’s a small thing, really, but very librating. 

3/22/2004 8:51:09 PM (GMT Standard Time, UTC+00:00)  #    Comments [1]  |  Trackback
Wednesday, March 10, 2004

I have been trying to use VSS integration with VS.Net for well over a year.  It works great at home when I am by myself.  I can track changes and keep versions in history and can confidently change code knowing that I can roll back if I have to.  At work, however, when it is critically important, the integration has limitations that result in having to use VSS explorer outside of VSS.Net.

I have come to very few revolutionary conclusions.  I was hoping to get to a point where I could recommend a configuration for a large development team.  Unfortunately, I can only express that for those who wish to use it, VSS integration is tolerable.

First off, only bind what you will be editing.  If you aren't going to be changing a project that is part of a larger solution, get the files from source control and use them locally but don't bind them to the VSS location.  If you don't need the source code at all (for debugging or stepping through funtionality) simply get the binaries and use the compiled dll.  Its much easier and saves a lot of time when getting latest.

For a project that you do modify and require VSS functionality, here are some tips:

  • Project should remain writable.  It is a pain in the butt to have to check the project out to remove a component from the project or to add a test page.  When you need to make persistent project changes, check out the project file externally, make your changes, check it back in, then mark the file writable again.
  • In VS.Net, under tools --> options --> Source Control --> General:  check the box “Allow checked in items to be edited“
    now you can chose “edit“ in the Source Control dialog in addition to check out.  very useful when you want to add a simple message or line of test code but do not want to persist that change

That's all I have for now, if I think of anything else, I'll let you know.

 

Programming | .Net | C#
3/10/2004 4:30:35 PM (GMT Standard Time, UTC+00:00)  #    Comments [0]  |  Trackback
Tuesday, March 09, 2004

Stumbled across this blog specifically for gadgets.  Get your geek fix here

3/9/2004 3:49:27 PM (GMT Standard Time, UTC+00:00)  #    Comments [0]  |  Trackback

Theme design by Jelle Druyts

Pick a theme: