public XmlTextSerializer(Type type, RedactAttribute redactAttribute, EncryptAttribute encryptAttribute, Type[] extraTypes) { _encryptAttribute = encryptAttribute; if (!ValueTypes.TryGetValueConverter(type, redactAttribute, extraTypes, out _valueConverter)) { _valueConverter = SimpleTypeValueConverter.Create(type, redactAttribute); } }
public XmlAttributeSerializer(Type type, string attributeName, RedactAttribute redactAttribute, EncryptAttribute encryptAttribute, IXmlSerializerOptions options) { _attributeName = attributeName; _encryptAttribute = encryptAttribute; if (!ValueTypes.TryGetValueConverter(type, redactAttribute, options.ExtraTypes, out _valueConverter)) { _valueConverter = SimpleTypeValueConverter.Create(type, redactAttribute); } }
public static IXmlSerializerOptions WithRedactAttribute(this IXmlSerializerOptions options, RedactAttribute redactAttribute) { return new XmlSerializerOptions { DefaultNamespace = options.DefaultNamespace, ExtraTypes = options.ExtraTypes, RootElementName = options.RootElementName, RedactAttribute = redactAttribute, TreatEmptyElementAsString = options.TreatEmptyElementAsString, ShouldAlwaysEmitNil = options.ShouldAlwaysEmitNil }; }
private SimpleTypeValueConverter(Type type, RedactAttribute redactAttribute) { if (redactAttribute != null) { _parseString = GetRedactedGetParseStringFunc(type); _getString = GetRedactedGetStringFunc(type, redactAttribute); } else { _parseString = GetNonRedactedGetParseStringFunc(type); _getString = GetNonRedactedGetStringFunc(type); } }
public static bool TryGetValueConverter(Type type, RedactAttribute redactAttribute, Type[] extraTypes, out IValueConverter valueConverter) { Func<RedactAttribute, Type[], IValueConverter> factory; if (_factories.TryGetValue(type, out factory)) { valueConverter = factory(redactAttribute, extraTypes); return true; } valueConverter = null; return false; }
public static bool TryGetValueConverter(Type type, RedactAttribute redactAttribute, Type[] extraTypes, out IValueConverter valueConverter) { Func <RedactAttribute, Type[], IValueConverter> factory; if (_factories.TryGetValue(type, out factory)) { valueConverter = factory(redactAttribute, extraTypes); return(true); } valueConverter = null; return(false); }
private static int CreateKey(Type type, RedactAttribute redactAttribute) { unchecked { var key = type.GetHashCode(); if (redactAttribute != null) { key = (key * 397) ^ redactAttribute.GetHashCode(); } return(key); } }
public static bool TryRedact(RedactAttribute redactAttribute, object value, bool redactEnabled, out string redactedValue) { if (value == null) { redactedValue = null; return true; } Func<bool, object, string> redactFunc; if (_redactFuncs.TryGetValue(GetRedactFuncKey(value.GetType()), out redactFunc)) { redactedValue = redactFunc(redactEnabled, value); return true; } redactedValue = null; return false; }
public static bool TryRedact(RedactAttribute redactAttribute, object value, bool redactEnabled, out string redactedValue) { if (value == null) { redactedValue = null; return(true); } Func <bool, object, string> redactFunc; if (_redactFuncs.TryGetValue(GetRedactFuncKey(value.GetType()), out redactFunc)) { redactedValue = redactFunc(redactEnabled, value); return(true); } redactedValue = null; return(false); }
private static int CreateKey(Type type, RedactAttribute redactAttribute) { unchecked { var key = type.GetHashCode(); if (redactAttribute != null) { key = (key * 397) ^ redactAttribute.GetHashCode(); } return key; } }
public static IXmlSerializerOptions WithRedactAttribute(this IXmlSerializerOptions options, RedactAttribute redactAttribute) { return(new XmlSerializerOptions { DefaultNamespace = options.DefaultNamespace, ExtraTypes = options.ExtraTypes, RootElementName = options.RootElementName, RedactAttribute = redactAttribute, TreatEmptyElementAsString = options.TreatEmptyElementAsString, ShouldAlwaysEmitNil = options.ShouldAlwaysEmitNil, ShouldUseAttributeDefinedInInterface = options.ShouldUseAttributeDefinedInInterface, Culture = options.Culture }); }
public static SimpleTypeValueConverter Create(Type type, RedactAttribute redactAttribute) { return _map.GetOrAdd( CreateKey(type, redactAttribute), _ => new SimpleTypeValueConverter(type, redactAttribute)); }
public TypeTypeValueConverter(RedactAttribute redactAttribute) { _redactAttribute = redactAttribute; }
private static Func<object, ISerializeOptions, string> GetRedactedGetStringFunc(Type type, RedactAttribute redactAttribute) { if (type == typeof(string)) { return (value, options) => redactAttribute.Redact((string)value, options.ShouldRedact); } if (type == typeof(bool) || type == typeof(bool?)) { return (value, options) => redactAttribute.Redact((bool?)value, options.ShouldRedact); } if (type == typeof(DateTime) || type == typeof(DateTime?)) { return (value, options) => redactAttribute.Redact((DateTime?)value, options.ShouldRedact); } if (type == typeof(DateTimeOffset) || type == typeof(DateTimeOffset?)) { return (value, options) => redactAttribute.Redact((DateTimeOffset?)value, options.ShouldRedact); } if (type == typeof(TimeSpan) || type == typeof(TimeSpan?)) { return (value, options) => redactAttribute.Redact((TimeSpan?)value, options.ShouldRedact); } return (value, options) => redactAttribute.Redact(value, options.ShouldRedact); }
public static SimpleTypeValueConverter Create(Type type, RedactAttribute redactAttribute) { return(_map.GetOrAdd( Tuple.Create(type, redactAttribute != null), _ => new SimpleTypeValueConverter(type, redactAttribute))); }
public EnumTypeValueConverter(RedactAttribute redactAttribute, IEnumerable<Type> extraTypes) { _redactAttribute = redactAttribute; _enumExtraTypes = extraTypes.Where(t => t.IsEnum).ToList(); }
private static Func <object, ISerializeOptions, string> GetRedactedGetStringFunc(Type type, RedactAttribute redactAttribute) { if (type == typeof(string)) { return((value, options) => redactAttribute.Redact((string)value, options.ShouldRedact)); } if (type == typeof(bool) || type == typeof(bool?)) { return((value, options) => redactAttribute.Redact((bool?)value, options.ShouldRedact)); } if (type == typeof(DateTime) || type == typeof(DateTime?)) { return((value, options) => redactAttribute.Redact((DateTime?)value, options.ShouldRedact)); } if (type == typeof(DateTimeOffset) || type == typeof(DateTimeOffset?)) { return((value, options) => redactAttribute.Redact((DateTimeOffset?)value, options.ShouldRedact)); } if (type == typeof(TimeSpan) || type == typeof(TimeSpan?)) { return((value, options) => redactAttribute.Redact((TimeSpan?)value, options.ShouldRedact)); } if (type == typeof(char) || type == typeof(char?)) { return((value, options) => redactAttribute.Redact((char?)value, options.ShouldRedact, options.ShouldSerializeCharAsInt)); } return((value, options) => redactAttribute.Redact(value, options.ShouldRedact)); }
public UriTypeValueConverter(RedactAttribute redactAttribute) { _redactAttribute = redactAttribute; }
public EnumTypeValueConverter(RedactAttribute redactAttribute, IEnumerable <Type> extraTypes) { _redactAttribute = redactAttribute; _enumExtraTypes = extraTypes.Where(t => t.IsEnum).ToList(); }