public JsonValueConverter(JsonSerializerOptions serializerOptions = null, ConverterMappingHints mappingHints = null) : base(model => JsonSerializer.Serialize(model, serializerOptions), value => JsonSerializer.Deserialize <TEntity>(value, serializerOptions), mappingHints) { }
public DateTimeKindValueConverter(DateTimeKind kind, ConverterMappingHints mappingHints = null) : base( v => v.ToUniversalTime(), v => DateTime.SpecifyKind(v, kind), mappingHints) { }
/// <summary> /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to /// the same compatibility standards as public APIs. It may be changed or removed without notice in /// any release. You should only use it directly in your code with extreme caution and knowing that /// doing so can result in application failures when updating to a new Entity Framework Core release. /// </summary> public StringDateTimeConverter( [NotNull] Expression <Func <TModel, TProvider> > convertToProviderExpression, [NotNull] Expression <Func <TProvider, TModel> > convertFromProviderExpression, [CanBeNull] ConverterMappingHints mappingHints = null) : base(convertToProviderExpression, convertFromProviderExpression, mappingHints) { }
public NullableDecimalValueConverter(ConverterMappingHints mappingHints = null) : base( e => e.HasValue ? e.Value.Value : (decimal?)null, e => e.HasValue ? new Decimal <Tag>(e.Value) : (Decimal <Tag>?)null, mappingHints) { }
public static CreditStateValueConverter Create( Expression <Func <State, string> > convertToStoreExpression, Expression <Func <string, State> > convertFromStoreExpression, ConverterMappingHints mappingHints = default(ConverterMappingHints)) { return(new CreditStateValueConverter(convertToStoreExpression, convertFromStoreExpression, mappingHints)); }
/// <summary> /// Initializes a new instance of the <see cref="BoolToIntConverter"/> class. /// </summary> /// <param name="mappingHints">The mapping hints.</param> public BoolToIntConverter(ConverterMappingHints mappingHints = null) : base( v => Convert.ToInt32(v), v => Convert.ToBoolean(v), mappingHints) { }
public EfCoreValueConverter(ConverterMappingHints mappingHints = null) : base( id => id.Value, value => new OrderLineId(value), mappingHints ) { }
public ListConverter(ConverterMappingHints mappingHints = null) : base( v => JsonSerializer.Serialize(v, null), v => JsonSerializer.Deserialize <List <TValueType> >(v, null), mappingHints) { }
/// <summary> /// Builds the value converter. /// </summary> /// <param name="mappingHints"> /// The mapping hints to use, if any. /// </param> /// <returns> /// The <see cref="ValueConverter{TModel,TProvider}"/>. /// </returns> public ValueConverter <TModelType, TStoreType> Build(ConverterMappingHints mappingHints = null) { var(encryptionProvider, modelDecoder, modelEncoder) = ModelType; var storeDecoder = Decoder; var storeEncoder = Encoder; if (modelDecoder is null || modelEncoder is null || storeDecoder is null || storeEncoder is null) { return(null); } if (encryptionProvider is null) { return(new ValueConverter <TModelType, TStoreType>( m => storeEncoder(StandardConverters.BytesToStream(modelDecoder(m))), s => modelEncoder(StandardConverters.BytesToStream(storeDecoder(s))), mappingHints)); } return(new EncryptionConverter <TModelType, TStoreType>( encryptionProvider, m => encryptionProvider.Encrypt(m, modelDecoder, storeEncoder), s => encryptionProvider.Decrypt(s, storeDecoder, modelEncoder), mappingHints)); }
public ExistingCoursesConverter(ConverterMappingHints mappingHints = null) : base(v => ConvertConfiguration.ObjectToJson(v), v => ConvertConfiguration.ObjectFromJson <CourseId>(v), mappingHints ) { }
/// <summary> /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to /// the same compatibility standards as public APIs. It may be changed or removed without notice in /// any release. You should only use it directly in your code with extreme caution and knowing that /// doing so can result in application failures when updating to a new Entity Framework Core release. /// </summary> public StringObjectIdConverter( Expression <Func <TModel, TProvider> > convertToProviderExpression, Expression <Func <TProvider, TModel> > convertFromProviderExpression, ConverterMappingHints mappingHints = null) : base(convertToProviderExpression, convertFromProviderExpression, mappingHints) { }
public NullableFloatValueConverter(ConverterMappingHints mappingHints = null) : base( e => e.HasValue ? e.Value.Value : (float?)null, e => e.HasValue ? new Float <Tag>(e.Value) : (Float <Tag>?)null, mappingHints) { }
public NullableDoubleValueConverter(ConverterMappingHints mappingHints = null) : base( e => e.HasValue ? e.Value.Value : (double?)null, e => e.HasValue ? new Double <Tag>(e.Value) : (Double <Tag>?)null, mappingHints) { }
public NullableULongValueConverter(ConverterMappingHints mappingHints = null) : base( e => e.HasValue ? e.Value.Value : (ulong?)null, e => e.HasValue ? new ULong <Tag>(e.Value) : (ULong <Tag>?)null, mappingHints) { }
public NullableUIntValueConverter(ConverterMappingHints mappingHints = null) : base( e => e.HasValue ? e.Value.Value : (uint?)null, e => e.HasValue ? new UInt <Tag>(e.Value) : (UInt <Tag>?)null, mappingHints) { }
public NullableStringValueConverter(ConverterMappingHints mappingHints = null) : base( e => e.HasValue ? e.Value.Value : null, e => new String <Tag>(e), mappingHints) { }
public CreditStateValueConverter( Expression <Func <State, string> > convertToStoreExpression, Expression <Func <string, State> > convertFromStoreExpression, ConverterMappingHints mappingHints = default(ConverterMappingHints)) : base(convertToStoreExpression, convertFromStoreExpression, mappingHints) { }
public StringDictionaryValueConverter(ConverterMappingHints mappingHints = null) : base( toValue => ConvertToString(toValue), fromValue => ConvertToDictionary(fromValue), mappingHints) { }
public EncryptionValueConverter(IEncryptionService encryptionService, ConverterMappingHints mappingHints = default(ConverterMappingHints)) : base( model => ConvertTo(encryptionService, model), encryptedString => ConvertFrom(encryptionService, encryptedString), mappingHints) { }
public JsonValueConverter( Expression <Func <TModel, TProvider> > convertToProviderExpression, Expression <Func <TProvider, TModel> > convertFromProviderExpression, Type tModel, ConverterMappingHints mappingHints = null) : base(convertToProviderExpression, convertFromProviderExpression, mappingHints) { _tModel = tModel; }
public JsonValueConverter(ConverterMappingHints mappingHints = null) : base( v => JsonConvert.SerializeObject(v), v => JsonConvert.DeserializeObject <T>(v), mappingHints ) { }
public TypeIdConverter(ConverterMappingHints mappingHints = null) : base( id => id.Value, value => new TypeId(value), mappingHints ) { }
public StronglyTypedIdValueConverter(ConverterMappingHints mappingHints = null) : base( id => id.Value, value => Create(value), mappingHints ) { }
/// <summary> /// Creates a new <see cref="EncryptionConverter{TModel,TProvider}"/> instance. /// </summary> public EncryptionConverter( IEncryptionProvider encryptionProvider, Expression <Func <TModel, TProvider> > convertToProviderExpression, Expression <Func <TProvider, TModel> > convertFromProviderExpression, ConverterMappingHints mappingHints = null) : base(convertToProviderExpression, convertFromProviderExpression, mappingHints) { EncryptionProvider = encryptionProvider; }
/// <summary> /// Adds hints from the given object to this one. Hints that are already specified are /// not overridden. /// </summary> /// <param name="hints"> The hints to add. </param> /// <returns> The combined hints. </returns> public override ConverterMappingHints With(ConverterMappingHints hints) => hints == null ? this : new RelationalConverterMappingHints( hints.Size ?? Size, hints.Precision ?? Precision, hints.Scale ?? Scale, hints.IsUnicode ?? IsUnicode, (hints as RelationalConverterMappingHints)?.IsFixedLength ?? IsFixedLength);
private static int?CalculateSize(ConverterMappingHints mappingHints, int?size) { if (mappingHints.SizeFunction != null && size != null) { size = mappingHints.SizeFunction(size.Value); } return(size); }
public IdentifierValueConverter(ConverterMappingHints mappingHints = null) : base( id => id.GetValue() == null ? default : (TDatabaseClrType)Convert.ChangeType(id.GetValue(), typeof(TDatabaseClrType)), value => new Identifier(value), mappingHints == null ? new ConverterMappingHints(valueGeneratorFactory: (p, t) => new IdentifierValueGenerator <TDatabaseClrType>()) : mappingHints.With(new ConverterMappingHints(valueGeneratorFactory: (p, t) => new IdentifierValueGenerator <TDatabaseClrType>())) ) { }
/// <summary> /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to /// the same compatibility standards as public APIs. It may be changed or removed without notice in /// any release. You should only use it directly in your code with extreme caution and knowing that /// doing so can result in application failures when updating to a new Entity Framework Core release. /// </summary> public CompositeValueConverter( [NotNull] ValueConverter converter1, [NotNull] ValueConverter converter2, [CanBeNull] ConverterMappingHints mappingHints = null) : base( Compose( (Expression <Func <TModel, TMiddle> >)converter1.ConvertToProviderExpression, (Expression <Func <TMiddle, TProvider> >)converter2.ConvertToProviderExpression), Compose( (Expression <Func <TProvider, TMiddle> >)converter2.ConvertFromProviderExpression, (Expression <Func <TMiddle, TModel> >)converter1.ConvertFromProviderExpression), mappingHints) { }
/// <summary> /// This API supports the Entity Framework Core infrastructure and is not intended to be used /// directly from your code. This API may change or be removed in future releases. /// </summary> public CompositeValueConverter( [NotNull] ValueConverter converter1, [NotNull] ValueConverter converter2, ConverterMappingHints mappingHints = default) : base( Compose( (Expression <Func <TModel, TMiddle> >)converter1.ConvertToStoreExpression, (Expression <Func <TMiddle, TStore> >)converter2.ConvertToStoreExpression), Compose( (Expression <Func <TStore, TMiddle> >)converter2.ConvertFromStoreExpression, (Expression <Func <TMiddle, TModel> >)converter1.ConvertFromStoreExpression), mappingHints) { }
/// <summary> /// Configures the property as capable of storing encrypted data. /// </summary> /// <param name="property"> /// The <see cref="PropertyBuilder{TProperty}"/>. /// </param> /// <param name="encryptionProvider"> /// The <see cref="IEncryptionProvider"/> to use, if any. /// </param> /// <param name="format"> /// One of the <see cref="StorageFormat"/> values indicating how the value should be stored in the database. /// </param> /// <param name="mappingHints"> /// The <see cref="ConverterMappingHints"/> to use, if any. /// </param> /// <returns> /// The updated <see cref="PropertyBuilder{TProperty}"/>. /// </returns> /// <exception cref="ArgumentNullException"> /// <paramref name="property"/> is <see langword="null"/>. /// </exception> /// <exception cref="ArgumentOutOfRangeException"> /// <paramref name="format"/> is not a recognised value. /// </exception> public static PropertyBuilder <byte[]> IsEncrypted( this PropertyBuilder <byte[]> property, IEncryptionProvider encryptionProvider, StorageFormat format = StorageFormat.Default, ConverterMappingHints mappingHints = null) { if (property is null) { throw new ArgumentNullException(nameof(property)); } return(format switch { StorageFormat.Default => encryptionProvider is null ? property : property.HasConversion(encryptionProvider.FromBinary().ToBinary().Build(mappingHints)), StorageFormat.Binary => encryptionProvider is null ? property : property.HasConversion(encryptionProvider.FromBinary().ToBinary().Build(mappingHints)), StorageFormat.Base64 => property.HasConversion(encryptionProvider.FromBinary().ToBase64().Build(mappingHints)), _ => throw new ArgumentOutOfRangeException(nameof(format)), });