static ObjectFormatter() { new StringFormatter().Register(); new Int64Formatter().Register(); new Int32Formatter().Register(); new Int16Formatter().Register(); new ByteFormatter().Register(); new BooleanFormatter().Register(); new CharFormatter().Register(); new DateTimeFormatter().Register(); new PairFormatter().Register(); new TripletFormatter().Register(); new ArrayListFormatter().Register(); new HashtableFormatter().Register(); new ObjectArrayFormatter().Register(); new UnitFormatter().Register(); new FontUnitFormatter().Register(); new ColorFormatter().Register(); enumFormatter = new EnumFormatter(); enumFormatter.Register(); typeFormatter = new TypeFormatter(); typeFormatter.Register(); singleRankArrayFormatter = new SingleRankArrayFormatter(); singleRankArrayFormatter.Register(); typeConverterFormatter = new TypeConverterFormatter(); typeConverterFormatter.Register(); binaryObjectFormatter = new BinaryObjectFormatter(); binaryObjectFormatter.Register(); }
public void EnumFormatter_Nullable_NoValue() { SampleEnum?testval = null; var formatter = new EnumFormatter(); var result = formatter.Format(testval, 0); Assert.Single(result); Assert.True(result.ContainsKey(string.Empty), "Should have a single, empty key"); Assert.Equal(result[string.Empty], string.Empty); }
public void EnumFormatter() { var testval = SampleEnum.SecondValue; var formatter = new EnumFormatter(); var result = formatter.Format(testval, 0); Assert.Single(result); Assert.True(result.ContainsKey(string.Empty), "Should have a single, empty key"); Assert.Equal("SecondValue", result[string.Empty]); }
public WildCardDefinition(string fieldName, string wildCardType, EWildCardFieldType fieldType) { FieldName = fieldName; try { WildCardType = (EWildCardType)EnumFormatter.ToEnum(wildCardType, WildCardType.GetType()); } catch { throw new Exception("Unable to resolve WildCardType or improper type passed."); } WildCardFieldType = fieldType; }
static ObjectFormatter () { new StringFormatter ().Register (); new Int64Formatter ().Register (); new Int32Formatter ().Register (); new Int16Formatter ().Register (); new ByteFormatter ().Register (); new BooleanFormatter ().Register (); new CharFormatter ().Register (); new DateTimeFormatter ().Register (); new PairFormatter ().Register (); new TripletFormatter ().Register (); new ArrayListFormatter ().Register (); new HashtableFormatter ().Register (); new ObjectArrayFormatter ().Register (); new UnitFormatter ().Register (); new FontUnitFormatter ().Register (); new IndexedStringFormatter ().Register (); new ColorFormatter ().Register (); enumFormatter = new EnumFormatter (); enumFormatter.Register (); typeFormatter = new TypeFormatter (); typeFormatter.Register (); singleRankArrayFormatter = new SingleRankArrayFormatter (); singleRankArrayFormatter.Register (); typeConverterFormatter = new TypeConverterFormatter (); typeConverterFormatter.Register (); binaryObjectFormatter = new BinaryObjectFormatter (); binaryObjectFormatter.Register (); }
public static void LogMessage(string message, string source, EType type, ESeverity severity) { string logPath = ConfigurationManager.AppSettings["LogPath"]; string logFileName = StringFormatter.SafeFileName(String.Format("{0}.txt", DateTime.Now.ToShortDateString())); StreamWriter writer = null; //Open stream writer depending on if this is a new file or not try { if (!File.Exists(logPath + logFileName)) { writer = File.CreateText(logPath + logFileName); } else { writer = File.AppendText(logPath + logFileName); } //write log entry string logEntry = DateTime.Now.ToString("MM/dd/yyyy hh:mm:ss.fff tt") + ControlCharacters.Tab + EnumFormatter.ToString(type) + ControlCharacters.Tab + EnumFormatter.ToString(severity) + ControlCharacters.Tab + source + ControlCharacters.Tab + StringFormatter.RemoveInvisibleCharacters(message); writer.WriteLine(logEntry); } catch { throw; } finally { writer.Close(); } }
private static IFormatter <T> Create() { if (typeof(T) == typeof(sbyte)) { return((IFormatter <T>)(object) new SByteFormatter()); } if (typeof(T) == typeof(byte)) { return((IFormatter <T>)(object) new ByteFormatter()); } if (typeof(T) == typeof(short)) { return((IFormatter <T>)(object) new Int16Formatter()); } if (typeof(T) == typeof(ushort)) { return((IFormatter <T>)(object) new UInt16Formatter()); } if (typeof(T) == typeof(int)) { return((IFormatter <T>)(object) new Int32Formatter()); } if (typeof(T) == typeof(uint)) { return((IFormatter <T>)(object) new UInt32Formatter()); } if (typeof(T) == typeof(long)) { return((IFormatter <T>)(object) new Int64Formatter()); } if (typeof(T) == typeof(ulong)) { return((IFormatter <T>)(object) new UInt64Formatter()); } if (typeof(T) == typeof(bool)) { return((IFormatter <T>)(object) new BooleanFormatter()); } if (typeof(T) == typeof(char)) { return((IFormatter <T>)(object) new CharFormatter()); } if (typeof(T) == typeof(float)) { return((IFormatter <T>)(object) new SingleFormatter()); } if (typeof(T) == typeof(double)) { return((IFormatter <T>)(object) new DoubleFormatter()); } if (typeof(T) == typeof(string)) { return((IFormatter <T>)(object) new StringFormatter()); } if (typeof(T) == typeof(sbyte[])) { return((IFormatter <T>)(object) new SByteArrayFormatter()); } if (typeof(T) == typeof(byte[])) { return((IFormatter <T>)(object) new ByteArrayFormatter()); } if (typeof(T) == typeof(short[])) { return((IFormatter <T>)(object) new Int16ArrayFormatter()); } if (typeof(T) == typeof(ushort[])) { return((IFormatter <T>)(object) new UInt16ArrayFormatter()); } if (typeof(T) == typeof(int[])) { return((IFormatter <T>)(object) new Int32ArrayFormatter()); } if (typeof(T) == typeof(uint[])) { return((IFormatter <T>)(object) new UInt32ArrayFormatter()); } if (typeof(T) == typeof(long[])) { return((IFormatter <T>)(object) new Int64ArrayFormatter()); } if (typeof(T) == typeof(ulong[])) { return((IFormatter <T>)(object) new UInt64ArrayFormatter()); } if (typeof(T) == typeof(bool[])) { return((IFormatter <T>)(object) new BooleanArrayFormatter()); } if (typeof(T) == typeof(char[])) { return((IFormatter <T>)(object) new CharArrayFormatter()); } if (typeof(T) == typeof(float[])) { return((IFormatter <T>)(object) new SingleArrayFormatter()); } if (typeof(T) == typeof(double[])) { return((IFormatter <T>)(object) new DoubleArrayFormatter()); } if (typeof(T) == typeof(string[])) { return((IFormatter <T>)(object) new StringArrayFormatter()); } if (typeof(T).IsEnum) { return(EnumFormatter.Create <T>()); } if (typeof(T).IsArray) { return(ArrayFormatter.Create <T>()); } if (typeof(T).IsAbstract) { return(UnionFormatter.Create <T>()); } return(ObjectFormatter.Create <T>()); }