There’s a new Code to HTML Addin for Visual Studio 2008 and a Plugin for Windows live writer from the same author.
I saw it mentioned by MSDN News on Twitter today and I had to download and install it out of curiosity.
The result looks great. What do you think?
Code Snippet
- using System;
- using System.Xml.Schema;
- using DotNetExpansions.IO;
-
- namespace WithValidation
- {
- internal class Program
- {
- private static void Main()
- {
- // Variation for use with Validation.
- var config = new Configuration4Validation
- {
- BackGroundColorSettings = new Configuration4Validation.BackGroundColor
- {
- R = 255,
- G = 255,
- B = 255
- },
- FontColorSettings = new Configuration4Validation.FontColor
- {
- R = 0,
- G = 0,
- B = 0
- },
- UserFont = new Configuration4Validation.FontParams
- {
- Name = "Calibri",
- Size = 12
- },
- WindowSettings = new Configuration4Validation.WindowParams
- {
- Height = 600,
- Width = 800,
- X = 300,
- Y = 200
- }
- };
-
- var configManager = new XmlIo(Environment.CurrentDirectory, "config.xml");
- // Saving your configuration to the XML file.
- configManager.Save(config);
-
- // Loading a configuration with validation
- configManager.ValidationEvent += OnValidationEvent;
- Configuration4Validation newConfig;
- try
- {
- if(configManager.FileIsValidWith("configSchema.xsd"))
- newConfig = configManager.Load<Configuration4Validation>();
- else
- DoSomethingAppropriate();
- }
- catch(XmlSchemaValidationException problem)
- {
- Console.WriteLine(problem.ToString());
- }
-
- // Verhindert das selbsttätige Schließen des Konsolenfensters.
- Console.WriteLine("\nPress any key to terminate the program.");
- Console.ReadKey();
- }
-
- // Only needed when validation is involved.
- private static void OnValidationEvent(object sender, System.Xml.Schema.ValidationEventArgs e)
- {
- // Just a demo. Do something appropriate with the event.
- Console.WriteLine(e.Exception);
- Console.WriteLine(e.Message);
- Console.WriteLine(e.Severity);
- }
-
- // Only needed when validation is involved.
- private static void DoSomethingAppropriate()
- {
- // Do something appropriate.
- }
- }
- }
Code Snippet
- using System;
- using System.Drawing;
- using DotNetExpansions.IO;
-
- namespace WithoutValidation
- {
- internal class Program
- {
- private static void Main()
- {
- // Variation for use without validation.
- var config = new Configuration
- {
- BackgroundColor = .FromArgb(255, 255, 255),
- FontColor = .FromArgb(0, 0, 0),
- UserFont = new Font("Calibri", 12),
- WindowLocation = new (300, 200),
- WindowSize = new (800, 600)
- };
-
-
- var configManager = new XmlIo(Environment.CurrentDirectory, "config.xml");
- // Saving your configuration to the XML file.
- configManager.Save(config);
-
- // Loading your configuration from the xml file.
- Configuration newConfig = configManager.Load<Configuration>();
-
- // Verhindert das selbsttätige Schließen des Konsolenfensters.
- Console.WriteLine("\nPress any key to terminate the program.");
- Console.ReadKey();
- }
- }
- }
By the way, the code in these boxes are quick reference demos for the XmlIO class, which is part of my .Net Expansions Framework. You can download the latest release at http://cyrons.svn.beanstalkapp.com/general/DotNetExpansions/tags. The framework comes along with complete intellisense support and a compiled help file (.chm).