static ContextObject() { DefaultFormatter = new FormatterMatcher(); var defaultFormatter = new[] { typeof(IFormattable), typeof(string), typeof(bool), typeof(char), typeof(int), typeof(double), typeof(short), typeof(float), typeof(long), typeof(byte), typeof(sbyte), typeof(decimal), typeof(DateTime), }; foreach (var type in defaultFormatter) { DefaultFormatter.AddFormatter(type, new Func <object, object, object>(DefaultFormatterImpl)); } }
static ContextObject() { DefaultFormatter = new FormatterMatcher(); foreach (var type in new[] { typeof(IFormattable), }) { //we have to use a proxy function to get around a changing delegate that maybe overwritten by the user //if the user overwrites the static DefaultToStringWithFormatting after we have added it to the list this would //have no effect DefaultFormatter.AddFormatter(type, new Func <object, object, object>(DefaultFormatterImpl)); } DefaultDefinitionOfFalse = (value) => value != null && value as bool? != false && // ReSharper disable once CompareOfFloatsByEqualityOperator value as double? != 0 && value as int? != 0 && value as string != string.Empty && // We've gotten this far, if it is an object that does NOT cast as enumberable, it exists // OR if it IS an enumerable and .Any() returns true, then it exists as well (!(value is IEnumerable) || ((IEnumerable)value).Cast <object>().Any() ); DefinitionOfFalse = DefaultDefinitionOfFalse; }
/// <summary> /// Initializes a new instance of the <see cref="ParserOptions" /> class. /// </summary> /// <param name="template">The template.</param> /// <param name="sourceStream">The source stream.</param> /// <param name="encoding">The encoding.</param> public ParserOptions([NotNull] string template, Func <Stream> sourceStream, Encoding encoding) { Template = template; SourceFactory = sourceStream ?? (() => new MemoryStream()); Encoding = encoding ?? Encoding.Default; Formatters = new FormatterMatcher(); Null = string.Empty; MaxSize = 0; DisableContentEscaping = false; WithModelInference = false; }