streda 3. októbra 2007

LINQ to XML - XDocument a String

V tomto príspevku sú vyzdvihované XML literály jazyka VB9 v porovnaní s C# 3.0. Hlavnou výhodou XML literálov je sprehľadnenie kódu. Podobný výsledok môžeme však jednoducho dosiahnúť aj v C# 3.0 vytvorením vlastnej rozšírujúcej metódy (extension method), ktorá bude parsovať reťazec na XDocument takto:


   1:  using System;

   2:  using System.Xml.Linq;

   3:   

   4:  namespace StringToXDocument

   5:  {

   6:      public class Program

   7:      {

   8:          static void Main(string[] args)

   9:          {

  10:              XDocument doc = @"<book>

  11:                                    <title>Pro WCF</title>

  12:                                    <publisher>APress</publisher>

  13:                                </book>".ToXDocument();

  14:          }

  15:      }

  16:   

  17:      public static class StringExtensions

  18:      {

  19:          public static XDocument ToXDocument(this string text)

  20:          {

  21:              return XDocument.Parse(text);

  22:          }

  23:      }

  24:  }

pondelok 1. októbra 2007

IL Merge - Quick Start

ILMerge is utility that merges set of .NET assemblies into single .NET assembly. To use ILMerge download it from here and run installation. Using of ILMerge ilustrates following command:

ILMerge /out:MergedAssembly.exe Application.exe Library1.dll Library2.dll Library3.dll

ILMerge is a console application, but it can be also used as library. Assemblies containing unmanaged code can't be merged.

DoEvents in WPF

I developed some WPF application with ProgressBar control and I solved problem how to realize the equivalent of Application.DoEvents() method in WPF. WPF based solution using dispatcher is described here. But I discovered that for this purposes can be also well known System.Windows.Forms.Application.DoEvents() method used. It is very easy, just add reference to system.windows.forms.dll assembly and use this method exactly like in WinForms.
APress - Pro WPF in C# 2008Sams - Windows Presentation FoundationO'Reilly - Programming WPFWrox - Professional WPF Programming