XmlSerializer made Generic

April 8, 2010

Here’s a little generic improvement to the XmlSerializer:

    public class XmlSerializer<T> : XmlSerializer
    {
        public XmlSerializer()
            : base(typeof (T))
        {
        }

        public void Serialize(FileInfo fileInfo, T o)
        {
            using (FileStream stream = File.Create(fileInfo.FullName))
            {
                Serialize(stream, o);
            }
        }

        public static T Deserialize(FileInfo fileInfo)
        {
            var serializer = new XmlSerializer<T>();
            using (FileStream stream = fileInfo.OpenRead())
            {
                var result = (T) serializer.Deserialize(stream);
                return result;
            }
        }
    }

Agile – Team Up!

April 8, 2010

Having been quite a nomad concerning work places, I have seen many developer teams. And I must say, many developers that take their title a little to seriously. Just because you are a higher ranked developer on paper, does not mean that you are a better developer than your co-developers. Actually, acheiving these titles often takes quite some time, and thus might even be outdated regarding new technologies at that time.

There is nothing wrong with having experience, but a really good developer shouldn’t need a title to earn the respect of your collegues, that will automatically come from working with them. If feel that you have lots of experience to share from, that’s good, let it propagate to your team through a two-way communicationprocess, in stead of instructing your ‘workers’. Team up! look at them as equals with other skill sets than yourself.

Please check out the Agile Manifesto if you haven’t read it before. If you don’t see the point in it, you might want to embrace this.

Titles are paper, while intelligence resides in the head. Remember: “If you think you are smarter than everyone else, you are probably not as smart as you think.”

Is DataBinding Better?

December 1, 2009

Asking me? Yes it’s better to take advantage of this technology. So why do developers avoid using it in so many cases? Guess it’s because they don’t realize the advantages it comes with, or is it because they don’t know how to use it correctly?

So what are the advantages? Well, if you ask me there are many. First you can start building your user interface by defining the data objects, this way you don’t let the user interface dominate your business model. How to do this:

First you define your data objects:

Data Objects

Build your project…

Then you open your user control on which you wish to map the data object, add a new data source to the project:

  1. Data > Show Data Sources > Add New Data Source…

Add the data object. Now the data object will appear in the data sources panel. Modify the controls to add for the data source by using the drop down at the root (select form if you want to display a detailed view using specific controls). For each member in the data source (you can add user- or 3rd party controls if the implement data binding for the data type) select the specific controls to be used.

Now drag the newly added data source onto a form or user control and you will, depending on how you configured the root element of the data source, get a data grid with auto populated columns or a detailed form view with the controls defined in the data source. The latter is my favorite, and with custom controls implementing data binding its a pleasure building an entire form in just one drag… and drop.

LINQ Concurrency

February 17, 2009

When using LINQ with multiple threads operations can be interrupted in the middle of everything. To handle this LINQ to SQL has this neat “Update Check” feature that checks is the record has been changed or deleted before a update record is submitted. Id this check fails a ChangeConflictException is thrown and we need to handle this. We might do as follows:

while(dataContext.GetChangeSet().Updates.Count > 0)
{
try
        {
            dataContext.SubmitChanges(ConflictMode.ContinueOnConflict);
        }
        catch (ChangeConflictException)
        {
                  foreach(ChangeConflict conflict in dataContext.ChangeConflicts)
                  {
                             conflict.Resolve(RefreshMode.KeepChanges);    
                  }
        }
}

And presto! We have an update that will survive a multithreaded environment.

Visual Studio 2008 SP1 and SCSF Guidance

January 22, 2009

I realized that the SCSF guidance package started to behave inconsistently after installing VS 2008 SP1 on my machine. When right clicking a VS project the “Add View (With Presenter)” only appears on the context menu for some projects.

This is due to the SCSF guidance being incompatible with VS 2008 SP1. There is a fix on Codeplex, but it requires you to recompile the guidance package – I have done this and can confirm that the fix i working properly. Instead of recompiling the guidance package, you can download a custom SCSF installer packaged by Artazor, which includes this fix here.

Hopefully this will be of some help to someone and maybe the Microsoft Patterns & Practices will have a new SCSF release out soon.