Пример #1
0
 public JsonValueConverter(JsonSerializerOptions serializerOptions = null,
                           ConverterMappingHints mappingHints      = null)
     : base(model => JsonSerializer.Serialize(model, serializerOptions),
            value => JsonSerializer.Deserialize <TEntity>(value, serializerOptions),
            mappingHints)
 {
 }
Пример #2
0
 public DateTimeKindValueConverter(DateTimeKind kind, ConverterMappingHints mappingHints = null)
     : base(
         v => v.ToUniversalTime(),
         v => DateTime.SpecifyKind(v, kind),
         mappingHints)
 {
 }
Пример #3
0
 /// <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)
 {
 }
Пример #4
0
 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)
 {
 }
Пример #5
0
 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)
 {
 }
Пример #7
0
 public EfCoreValueConverter(ConverterMappingHints mappingHints = null) : base(
         id => id.Value,
         value => new OrderLineId(value),
         mappingHints
         )
 {
 }
Пример #8
0
 public ListConverter(ConverterMappingHints mappingHints = null)
     : base(
         v => JsonSerializer.Serialize(v, null),
         v => JsonSerializer.Deserialize <List <TValueType> >(v, null),
         mappingHints)
 {
 }
Пример #9
0
        /// <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)
 {
 }
Пример #12
0
 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)
 {
 }
Пример #13
0
 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)
 {
 }
Пример #14
0
 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)
 {
 }
Пример #15
0
 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)
 {
 }
Пример #16
0
 public NullableStringValueConverter(ConverterMappingHints mappingHints = null)
     : base(
         e => e.HasValue ? e.Value.Value : null,
         e => new String <Tag>(e),
         mappingHints)
 {
 }
Пример #17
0
 public CreditStateValueConverter(
     Expression <Func <State, string> > convertToStoreExpression,
     Expression <Func <string, State> > convertFromStoreExpression,
     ConverterMappingHints mappingHints = default(ConverterMappingHints)) :
     base(convertToStoreExpression, convertFromStoreExpression, mappingHints)
 {
 }
Пример #18
0
 public StringDictionaryValueConverter(ConverterMappingHints mappingHints = null) :
     base(
         toValue => ConvertToString(toValue),
         fromValue => ConvertToDictionary(fromValue),
         mappingHints)
 {
 }
Пример #19
0
 public EncryptionValueConverter(IEncryptionService encryptionService,
                                 ConverterMappingHints mappingHints = default(ConverterMappingHints)) : base(
         model => ConvertTo(encryptionService, model),
         encryptedString => ConvertFrom(encryptionService, encryptedString),
         mappingHints)
 {
 }
Пример #20
0
 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
         )
 {
 }
Пример #22
0
 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
         )
 {
 }
Пример #24
0
 /// <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);
Пример #26
0
 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>()))
         )
 {
 }
Пример #28
0
 /// <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)
 {
 }
Пример #29
0
 /// <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)
 {
 }
Пример #30
0
        /// <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)),
            });