using System; namespace IDTF.Net { internal static class ExtensionMethods { public static string ToIDTFStringRGBA(this System.Drawing.Color color) { ///Convert the colors from 0-255 to 0-1.0 and 6 dec places /// // If the value is 255, then make it 1.0, otherwise divide by 256, and force cast to double double r = (color.R == 255) ? 1.0 : (double)color.R / 256; double g = (color.G == 255) ? 1.0 : (double)color.G / 256; double b = (color.B == 255) ? 1.0 : (double)color.B / 256; double a = (color.A == 255) ? 1.0 : (double)color.A / 256; return String.Format("{0} {1} {2} {3}", r.ToString(Format.SixDecPlFormat), g.ToString(Format.SixDecPlFormat), b.ToString(Format.SixDecPlFormat), a.ToString(Format.SixDecPlFormat)); } public static string ToIDTFStringRGB(this System.Drawing.Color color) { ///Convert the colors from 0-255 to 0-1.0 and 6 dec places /// // If the value is 255, then make it 1.0, otherwise divide by 256, and force cast to double double r = (color.R == 255) ? 1.0 : (double)color.R / 256; double g = (color.G == 255) ? 1.0 : (double)color.G / 256; double b = (color.B == 255) ? 1.0 : (double)color.B / 256; return String.Format("{0} {1} {2}", r.ToString(Format.SixDecPlFormat), g.ToString(Format.SixDecPlFormat), b.ToString(Format.SixDecPlFormat)); } // This got too difficult to do as ExtensionMethods methods, once multiple // List constrains were introduced //Instead that are statics on the ListExtension class // Create an extension method in IList that is constrained to IList! //http://grabbagoft.blogspot.com.au/2007/07/constrained-generic-extension-methods.html /// /// Export a List<Parent> to a stream in IDTF format /// /// /// /// //public static void Export(this T list, StreamWriter toStream) // where T : IList //{ // toStream.WriteLine("\tPARENT_LIST {"); // toStream.WriteLine(String.Format("\t\tPARENT_COUNT {0}", list.Count)); // for (int i = 0; i < list.Count; i++) // { // //note: double {{ wil output as single { in string.format // toStream.WriteLine(String.Format("\t\tPARENT {0} {{", i)); // list.ElementAt(i).Export(toStream); // toStream.WriteLine("\t\t}"); // } // toStream.WriteLine("\t}"); //} } }