GenericTypes(ISpecification <TypeInfo> specification, ITypeFormatter formatter) : base( new TypeCandidates(specification, formatter, new AssemblyTypePartitions(specification, formatter.Get), TypeLoader.Default) .Get) { }
public bool TryGetFormatterForType(Type type, out ITypeFormatter formatter) { formatter = _factory(type); // return formatter != null; if (formatter != null) { return(true); } if (Formatters.TryGetValue(type, out formatter)) { return(true); } if (type.IsGenericType && FormatterFactories.TryGetValue( type.GetGenericTypeDefinition(), out var factory)) { formatter = factory(type); Formatters[type] = formatter; return(true); } return(false); }
protected override bool TryInferFormatter(Type type, out ITypeFormatter formatter) { if (type.IsGenericType && type.GetGenericTypeDefinition() == typeof(ReadOnlyMemory <>)) { formatter = Formatter.Create( type, (obj, writer) => { var toArray = Formatter.FormatReadOnlyMemoryMethod.MakeGenericMethod (type.GetGenericArguments()); var array = toArray.Invoke(null, new[] { obj }); writer.Write(array.ToDisplayString()); }, PlainTextFormatter.MimeType); return(true); } formatter = null; return(false); }
public Identities(IIdentityStore source, INames alias, ITypeFormatter formatter, IIdentifiers identifiers) { _source = source; _alias = alias; _formatter = formatter; _identifiers = identifiers; }
protected override bool TryInferFormatter(Type type, out ITypeFormatter formatter) { if (typeof(JToken).IsAssignableFrom(type)) { formatter = new JsonFormatter <JToken>(); return(true); } formatter = null; return(false); }
public CsvTypeWriter([NotNull] CsvWriter writer, [NotNull] ITypeFormatter <T> formatter) { if (writer == null) { throw new ArgumentNullException("writer"); } if (formatter == null) { throw new ArgumentNullException("formatter"); } this._formatter = formatter; this._writer = writer; }
protected override bool TryInferFormatter(Type type, out ITypeFormatter formatter) { if (typeof(JToken).IsAssignableFrom(type)) { formatter = Formatter.Create( type, (value, writer) => writer.Write(value.ToString()), JsonFormatter.MimeType); return(true); } formatter = null; return(false); }
public bool TryGetFormatterForType(Type type, out ITypeFormatter formatter) { if (!Formatters.TryGetValue(type, out formatter)) { if (type.IsGenericType && OpenGenericFormatterFactories.TryGetValue( type.GetGenericTypeDefinition(), out var factory)) { formatter = factory(type); Formatters[type] = formatter; } } return(true); }
/// <summary> /// Add a formatter assembly to the dict formatters /// </summary> internal void AddFormatterAssembly(Assembly assembly) { // Scan for all types foreach (Type t in assembly.GetTypes()) { if (t.GetInterface("MARC.Everest.Formatters.XML.ITS1.ITypeFormatter", true) != null) { ITypeFormatter tf = (ITypeFormatter)assembly.CreateInstance(t.FullName); lock (s_dictFormatters) { if (!s_dictFormatters.ContainsKey(tf.HandlesType)) { s_dictFormatters.Add(tf.HandlesType, t); } } } } }
public TypeFormatter() { _defaultFormatter = new DefaultFormatter(); _formatters = new Dictionary<Type, ITypeFormatter> { { typeof (string), new StringFormatter() }, { typeof (decimal), new DecimalFormatter() }, { typeof (decimal?), new DecimalFormatter() }, { typeof (float), new FloatFormatter() }, { typeof (float?), new FloatFormatter() }, { typeof (long), new LongFormatter() }, { typeof (long?), new LongFormatter() }, { typeof (Type), new EdmTypeFormatter() }, { typeof (DateTime), new DateTimeFormatter() }, { typeof (DateTime?), new DateTimeFormatter() }, { typeof (DateTimeOffset), new DateTimeOffsetFormatter() }, { typeof (DateTimeOffset?), new DateTimeOffsetFormatter() }, { typeof (TimeSpan), new TimeFormatter() }, { typeof (TimeSpan?), new TimeFormatter() }, { typeof (Guid), new GuidFormatter() }, { typeof (Guid?), new GuidFormatter() } }; }
/// <summary> /// Creates a new object. /// </summary> /// <param name="formatterTypes"></param> public UseFormatterAttribute(params Type[] formatterTypes) { var formattersList = formatterTypes .Select(r => { ITypeFormatter formatterInstance = null; try { formatterInstance = Activator.CreateInstance(r) as ITypeFormatter; } catch { } return(formatterInstance); }) .ToArray(); if (formattersList.Any(r => r == null)) { CtorErrorMessage = $"At least one of the formatter types does not implement {nameof(ITypeFormatter)}"; } var countDistinctTypes = formattersList .Where(r => r != null) .Select(r => r .GetType() .GetInterface(TypeFormatterResolver.ITypeFormatterGenericName) .GetGenericArguments()[0] ) .Distinct(); if (CtorErrorMessage == null && countDistinctTypes.Count() != formattersList.Length) { CtorErrorMessage = $"At least two of the formatters are for the same type"; } CtorErrorMessage = CtorErrorMessage ?? ""; IsValid = CtorErrorMessage == ""; Formatters = IsValid ? formattersList : new ITypeFormatter[0]; }
public TypeFormatter() { _defaultFormatter = new DefaultFormatter(); _formatters = new Dictionary <Type, ITypeFormatter> { { typeof(string), new StringFormatter() }, { typeof(decimal), new DecimalFormatter() }, { typeof(decimal?), new DecimalFormatter() }, { typeof(float), new FloatFormatter() }, { typeof(float?), new FloatFormatter() }, { typeof(long), new LongFormatter() }, { typeof(long?), new LongFormatter() }, { typeof(Type), new EdmTypeFormatter() }, { typeof(DateTime), new DateTimeFormatter() }, { typeof(DateTime?), new DateTimeFormatter() }, { typeof(DateTimeOffset), new DateTimeOffsetFormatter() }, { typeof(DateTimeOffset?), new DateTimeOffsetFormatter() }, { typeof(TimeSpan), new TimeFormatter() }, { typeof(TimeSpan?), new TimeFormatter() }, { typeof(Guid), new GuidFormatter() }, { typeof(Guid?), new GuidFormatter() } }; }
private void AddFormatter(List <FormatterAndType> formatterList, Type type, ITypeFormatter typeFormatter) { var record = new FormatterAndType() { Type = type, Formatter = typeFormatter, }; var idx = formatterList.FindIndex(r => r.Type == type); if (idx != -1) { formatterList[idx] = record; } else { formatterList.Add(record); } if (formatterList == _FormatterList) { SetDirectAccessProperty(type, typeFormatter); } }
public bool TryGetFormatterForType(Type type, out ITypeFormatter formatter) { formatter = _factory(type); if (formatter != null) { return(true); } if (Formatters.TryGetValue(type, out formatter)) { return(true); } if (TryInferFormatter( type, out formatter)) { Formatters[type] = formatter; return(true); } return(false); }
public GenericTypes(IActivatingTypeSpecification specification, ITypeFormatter formatter) : this(IsGenericTypeSpecification.Default.And(specification), formatter) { }
public void TestSetUp() { _formatter = new FloatFormatter(); }
public void TestSetUp() { _formatter = new EdmTypeFormatter(); }
public Types(IPartitionedTypeSpecification specification, IAssemblyTypePartitions partitions, ITypeIdentities identities, ITypeFormatter formatter) : this(identities, new TypeCandidates(specification, formatter, TypeLoader.Default, partitions)) { }
public void TestSetUp() { _formatter = new DefaultFormatter(); }
public void TestSetUp() { _formatter = new DecimalFormatter(); }
public TypeCandidates(ISpecification <TypeInfo> specification, ITypeFormatter formatter, params ITypePartitions[] partitions) : this(new IdentityPartitionedTypeCandidates(specification, formatter), new PartitionedTypeCandidates(partitions)) { }
public static void Format(this ITypeFormatter formatter, object instance, TextWriter writer) { formatter.Format(new FormatContext(), instance, writer); }
public void TestSetUp() { _formatter = new LongFormatter(); }
public static string Format <T>(this ITypeFormatter formatter, T value) { return(formatter.Format(typeof(T), value)); }
private void SetDirectAccessProperty(Type type, ITypeFormatter typeFormatter) { if (type == typeof(bool)) { BoolFormatter = (ITypeFormatter <bool>)typeFormatter; } else if (type == typeof(byte)) { ByteFormatter = (ITypeFormatter <byte>)typeFormatter; } else if (type == typeof(char)) { CharFormatter = (ITypeFormatter <char>)typeFormatter; } else if (type == typeof(Int16)) { Int16Formatter = (ITypeFormatter <Int16>)typeFormatter; } else if (type == typeof(UInt16)) { UInt16Formatter = (ITypeFormatter <UInt16>)typeFormatter; } else if (type == typeof(Int32)) { Int32Formatter = (ITypeFormatter <Int32>)typeFormatter; } else if (type == typeof(UInt32)) { UInt32Formatter = (ITypeFormatter <UInt32>)typeFormatter; } else if (type == typeof(Int64)) { Int64Formatter = (ITypeFormatter <Int64>)typeFormatter; } else if (type == typeof(UInt64)) { UInt64Formatter = (ITypeFormatter <UInt64>)typeFormatter; } else if (type == typeof(float)) { FloatFormatter = (ITypeFormatter <float>)typeFormatter; } else if (type == typeof(double)) { DoubleFormatter = (ITypeFormatter <double>)typeFormatter; } else if (type == typeof(decimal)) { DecimalFormatter = (ITypeFormatter <decimal>)typeFormatter; } else if (type == typeof(DateTime)) { DateTimeFormatter = (ITypeFormatter <DateTime>)typeFormatter; } else if (type == typeof(DateTimeOffset)) { DateTimeOffsetFormatter = (ITypeFormatter <DateTimeOffset>)typeFormatter; } else if (type == typeof(Guid)) { GuidFormatter = (ITypeFormatter <Guid>)typeFormatter; } else if (type == typeof(byte[])) { ByteArrayFormatter = (ITypeFormatter <byte[]>)typeFormatter; } else if (type == typeof(string)) { StringFormatter = (ITypeFormatter <string>)typeFormatter; } }
public void TestSetUp() { _formatter = new TimeFormatter(); }
public IdentityPartitionedTypeCandidates(ISpecification <TypeInfo> specification, ITypeFormatter formatter) : this(WellKnownIdentities.Default .ToDictionary(x => x.Value.Identifier, new TypeNamePartition(specification, formatter).Get) .Get) { }
public void TestSetUp() { _formatter = new DateTimeOffsetFormatter(); }
public AssemblyTypePartitions(IPartitionedTypeSpecification specification, ITypeFormatter formatter) : this(specification, formatter.Get) { }
public void TestSetUp() { _formatter = new GuidFormatter(); }
static string GetString <T>([NotNull] Action <CsvWriter, CsvTypeWriter <T> > action, [NotNull] ITypeFormatter <T> formatter) where T : class { if (action == null) { throw new ArgumentNullException("action"); } if (formatter == null) { throw new ArgumentNullException("formatter"); } using (var memStream = new MemoryStream()) using (var streamWriter = new StreamWriter(memStream)) using (var csvWriter = new CsvWriter(streamWriter)) { var objWriter = new CsvTypeWriter <T>(csvWriter, formatter); action(csvWriter, objWriter); streamWriter.Flush(); memStream.Position = 0; var sr = new StreamReader(memStream); return(sr.ReadToEnd()); } }
public ODataFilterExpressionVisitor(IFilterExpressionParserStrategy filterExpressionParserStrategy, ITypeFormatter typeFormatter) { _filterExpressionParserStrategy = filterExpressionParserStrategy; _typeFormatter = typeFormatter; }
public TypeNamePartition(ISpecification <TypeInfo> specification, ITypeFormatter formatter) : this(ApplicationTypes, specification.IsSatisfiedBy, formatter.Get) { }
public void ValidateHelper(XmlWriter s, IGraphable o, ITypeFormatter formatter, XmlIts1FormatterGraphResult resultContext) { IResultDetail[] details = null; if (ValidateConformance && (!formatter.Validate(o, s.ToString(), out details))) resultContext.AddResultDetail(details.Length > 0 ? details : new IResultDetail[] { new DatatypeValidationResultDetail(ValidateConformance ? ResultDetailType.Error : ResultDetailType.Warning, o.GetType().ToString(), s.ToString()) }); }