November 29, 2010

AssemblyVersion and AssemblyFileVersion

See here
and here

  • AssemblyVersion is .NET version info whilst 'AssemblyFileVersion' is Windows version number, ie., what you see when you do view the file properties of an assembly in windows explorer. AssemblyVersion defines the version other assemblies are compiled against in their manifest.
  • If 'AssemblyFileVersion' attribute is not present in 'AssemblyInfo.cs' then AssemblyFileVesrion takes the same value as AssemblyVersion.

November 4, 2010

Proxy, Decorator, Adapter, Bridge and Facade Patterns

Found the following explanantion here. It is a useful description of the differences between these patterns as they are very similar.

Proxy, Decorator, Adapter, and Bridge are all variations on "wrapping" a class. But their uses are different:
  • Proxy could be used when you want to lazy-instantiate an object, or hide the fact that you're calling a remote service, or control access to the object.
  • Decorator is also called "Smart Proxy." This is used when you want to add functionality to an object, but not by extending that object's type. This allows you to do so at runtime.
  • Adapter is used when you have an abstract interface, and you want to map that interface to another object which has similar functional role, but a different interface.
  • Bridge is very similar to Adapter, but we call it Bridge when you define both the abstract interface and the underlying implementation. I.e. you're not adapting to some legacy or third-party code, you're the designer of all the code but you need to be able to swap out different implementations.
  • Facade is a higher-level (read: simpler) interface to a subsystem of one or more classes. Think of Facade as a sort of container for other objects, as opposed to simply a wrapper.

November 2, 2010

Deleting a Read-Only File

See also the FileAttributesExtender class
and the PathCombine class
string fullPath = PathCombine(pathRoot, relativePath);
if (File.Exists(fullPath))
{
    FileAttributes fas = File.GetAttributes(fullPath);
    if (fas.Contains(FileAttributes.ReadOnly))
        File.SetAttributes(fullPath, FileAttributes.Normal);
    File.Delete(fullPath);
}