September 27, 2013

ObjectSerializer

I often face the need for an ObjectSerializer; to transform an object into an XML string or vice versa. This can be used in many ways, fx. when storing an object.

I have created a few ObjectSerializers myself and found several on the internet... So far the one below is the best.

internal static class ObjectSerializer<T>
{
 /// <summary>
 /// Serialize an object of type T into a XML string
 /// </summary>
 /// <param name="value">The object to be serialized</param>
 /// <returns>The serialized object of type T</returns>
 public static string ToXml(T value)
 {
  XmlSerializer serializer = new XmlSerializer(typeof(T));
  StringBuilder stringBuilder = new StringBuilder();
  XmlWriterSettings settings = new XmlWriterSettings()
  {
   Indent = true,
   OmitXmlDeclaration = true,
  };
 
  using (XmlWriter xmlWriter = XmlWriter.Create(stringBuilder, settings))
  {
   serializer.Serialize(xmlWriter, value);
  }
 
  return stringBuilder.ToString();
 }
 
 /// <summary>
 /// Deserialize a XML string into a object of type T
 /// </summary>
 /// <param name="xml">The XML as a string to be deserialized</param>
 /// <returns>The deserialized object of type T</returns>
 public static T FromXml(string xml)
 {
  XmlSerializer serializer = new XmlSerializer(typeof(T));
 
  // Create a new instance of T
  T value;
 
  using (StringReader stringReader = new StringReader(xml))
  {
   object deserialized = serializer.Deserialize(stringReader);
   value = (T)deserialized;
  }
 
  return value;
 }
}

September 16, 2013

Howto: Remove pre-Installed Windows 8 Modern UI Apps

Windows 8 is shipped with some preinstalled apps; fx. Sports, Finance, Travel and News... These apps can be uninstalled but they tend to reappear when they are updated. To uninstall these apps completely you can follow this guide.

First you have to run an elevated PowerShell (Run as Administrator)

To remove an app from your account - you can use the Remove-AppxPackage command. This method is the same as when you uninstalled an app from the Modern UI - they will come back when they are updated.

Use the Get-AppxPackage command to show the latest version of the installed apps (for all users)

Get-AppxPackage -AllUsers

When you create a new user on the system it will use a standard image as the base of the creation. You have to remove the apps from this image to get rid of all future updates of the preinstalled apps.

Use the Get-AppxProvisionedPackage command to show the apps in the image - the apps that will be installed for all new users

Get-AppXProvisionedPackage -online

Use the Remove-AppxProvisionedPackage command to remove an app from the image (for all users on the system).

Remove-AppXProvisionedPackage -online -PackageName <packagename>



This article is based on this link: How to Remove All Pre-Installed Windows 8 Metro Apps

If you regret and want to install them laiter then you can go to the Store and install them again.

Note: It'll take some minutes before the system finds out that the apps have been removed.