Esempio n. 1
0
 /// <summary>
 ///     <para>
 ///         Creates a new instance of this converter.
 ///     </para>
 ///     <para>
 ///         This converter does not preserve order because the ordering of bits in
 ///         the standard binary representation of a GUID does not match the ordering
 ///         in the standard string representation.
 ///     </para>
 /// </summary>
 /// <param name="mappingHints">
 ///     Hints that can be used by the <see cref="ITypeMappingSource" /> to create data types with appropriate
 ///     facets for the converted data.
 /// </param>
 public GuidToBytesConverter([CanBeNull] ConverterMappingHints mappingHints = null)
     : base(
         v => v.ToByteArray(),
         v => v == null ? Guid.Empty : new Guid(v),
         _defaultHints.With(mappingHints))
 {
 }
Esempio n. 2
0
 /// <summary>
 ///     Creates a new instance of this converter.
 /// </summary>
 /// <param name="mappingHints">
 ///     Hints that can be used by the <see cref="ITypeMappingSource"/> to create data types with appropriate
 ///     facets for the converted data.
 /// </param>
 public StringToGuidConverter([CanBeNull] ConverterMappingHints mappingHints = null)
     : base(
         ToGuid(),
         ToString(),
         _defaultHints.With(mappingHints))
 {
 }
 /// <summary>
 ///     Creates a new instance of this converter.
 /// </summary>
 /// <param name="mappingHints">
 ///     Hints that can be used by the <see cref="ITypeMappingSource" /> to create data types with appropriate
 ///     facets for the converted data.
 /// </param>
 public TimeSpanToStringConverter([CanBeNull] ConverterMappingHints mappingHints = null)
     : base(
         ToString(),
         ToTimeSpan(),
         _defaultHints.With(mappingHints))
 {
 }
 /// <summary>
 ///     Creates a new instance of this converter.
 /// </summary>
 /// <param name="mappingHints">
 ///     Hints that can be used by the <see cref="ITypeMappingSource" /> to create data types with appropriate
 ///     facets for the converted data.
 /// </param>
 public DateTimeOffsetToBytesConverter([CanBeNull] ConverterMappingHints mappingHints = null)
     : base(
         v => ToBytes(v),
         v => v == null ? default : FromBytes(v),
         _defaultHints.With(mappingHints))
 {
 }
 /// <summary>
 ///     Creates a new instance of this converter.
 /// </summary>
 /// <param name="mappingHints">
 ///     Hints that can be used by the <see cref="ITypeMappingSource" /> to create data types with appropriate
 ///     facets for the converted data.
 /// </param>
 public DateTimeToBinaryConverter([CanBeNull] ConverterMappingHints mappingHints = null)
     : base(
         v => v.ToBinary(),
         v => DateTime.FromBinary(v),
         mappingHints)
 {
 }
 /// <summary>
 ///     Creates a new instance of this converter.
 /// </summary>
 /// <param name="mappingHints">
 ///     Hints that can be used by the <see cref="ITypeMappingSource" /> to create data types with appropriate
 ///     facets for the converted data.
 /// </param>
 public DateTimeToStringConverter([CanBeNull] ConverterMappingHints mappingHints = null)
     : base(
         ToString(),
         ToDateTime(),
         _defaultHints.With(mappingHints))
 {
 }
Esempio n. 7
0
 /// <summary>
 ///     Creates a new instance of this converter. This converter preserves order.
 /// </summary>
 /// <param name="mappingHints">
 ///     Hints that can be used by the <see cref="ITypeMappingSource" /> to create data types with appropriate
 ///     facets for the converted data.
 /// </param>
 public CharToStringConverter([CanBeNull] ConverterMappingHints mappingHints = null)
     : base(
         ToString(),
         ToChar(),
         _defaultHints.With(mappingHints))
 {
 }
Esempio n. 8
0
 /// <summary>
 ///     Creates a new instance of this converter. This converter does not preserve order.
 /// </summary>
 /// <param name="mappingHints">
 ///     Hints that can be used by the <see cref="ITypeMappingSource" /> to create data types with appropriate
 ///     facets for the converted data.
 /// </param>
 public EnumToStringConverter([CanBeNull] ConverterMappingHints mappingHints = null)
     : base(
         ToString(),
         ToEnum(),
         mappingHints)
 {
 }
 /// <summary>
 ///     Creates a new instance of this converter.
 /// </summary>
 /// <param name="mappingHints">
 ///     Hints that can be used by the <see cref="ITypeMappingSource" /> to create data types with appropriate
 ///     facets for the converted data.
 /// </param>
 public DateTimeToTicksConverter([CanBeNull] ConverterMappingHints mappingHints = null)
     : base(
         v => v.Ticks,
         v => new DateTime(v),
         mappingHints)
 {
 }
 /// <summary>
 ///     <para>
 ///         Creates a new instance of this converter that will convert a <c>false</c> false
 ///         to one value and a <c>true</c> to another.
 ///     </para>
 ///     <para>
 ///         Use <see cref="BoolToZeroOneConverter{TProvider}" /> for converting a <see cref="bool" /> to zero/one.
 ///     </para>
 /// </summary>
 /// <param name="falseValue"> The value to convert to for <c>false</c>. </param>
 /// <param name="trueValue"> The value to convert to for <c>true</c>. </param>
 /// <param name="fromProvider"> Optional custom translator from store. </param>
 /// <param name="mappingHints">
 ///     Hints that can be used by the <see cref="ITypeMappingSource" /> to create data types with appropriate
 ///     facets for the converted data.
 /// </param>
 public BoolToTwoValuesConverter(
     [CanBeNull] TProvider falseValue,
     [CanBeNull] TProvider trueValue,
     [CanBeNull] Expression <Func <TProvider, bool> > fromProvider = null,
     [CanBeNull] ConverterMappingHints mappingHints = null)
     : base(ToProvider(falseValue, trueValue), fromProvider ?? ToBool(trueValue), mappingHints)
 {
 }
Esempio n. 11
0
 /// <summary>
 ///     Creates a new instance of this converter.
 /// </summary>
 /// <param name="mappingHints">
 ///     Hints that can be used by the <see cref="ITypeMappingSource"/> to create data types with appropriate
 ///     facets for the converted data.
 /// </param>
 public StringToBoolConverter(
     [CanBeNull] ConverterMappingHints mappingHints = null)
     : base(
         v => Convert.ToBoolean(v),
         v => Convert.ToString(v),
         mappingHints)
 {
 }
Esempio n. 12
0
 /// <summary>
 ///     Creates a new instance of this converter.
 /// </summary>
 /// <param name="mappingHints">
 ///     Hints that can be used by the <see cref="ITypeMappingSource" /> to create data types with appropriate
 ///     facets for the converted data.
 /// </param>
 public BytesToStringConverter(
     [CanBeNull] ConverterMappingHints mappingHints = null)
     : base(
         v => v == null ? null : Convert.ToBase64String(v),
         v => v == null ? null : Convert.FromBase64String(v),
         mappingHints)
 {
 }
Esempio n. 13
0
 /// <summary>
 ///     Creates a new instance of this converter.
 /// </summary>
 /// <param name="encoding"> The string encoding to use. </param>
 /// <param name="mappingHints">
 ///     Hints that can be used by the <see cref="ITypeMappingSource" /> to create data types with appropriate
 ///     facets for the converted data.
 /// </param>
 public StringToBytesConverter(
     [NotNull] Encoding encoding,
     [CanBeNull] ConverterMappingHints mappingHints = null)
     : base(
         v => v == null ? null : encoding.GetBytes(v),
         v => v == null ? null : encoding.GetString(v),
         mappingHints)
 {
 }
Esempio n. 14
0
 /// <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 virtual ConverterMappingHints With([CanBeNull] ConverterMappingHints hints)
 => hints == null
         ? this
         : new ConverterMappingHints(
     hints.Size ?? Size,
     hints.Precision ?? Precision,
     hints.Scale ?? Scale,
     hints.IsUnicode ?? IsUnicode,
     hints.ValueGeneratorFactory ?? ValueGeneratorFactory);
Esempio n. 15
0
 /// <summary>
 ///     Creates a new instance of this converter.
 /// </summary>
 /// <param name="mappingHints">
 ///     Hints that can be used by the <see cref="ITypeMappingSource" /> to create data types with appropriate
 ///     facets for the converted data.
 /// </param>
 public DateTimeOffsetToBinaryConverter([CanBeNull] ConverterMappingHints mappingHints = null)
     : base(
         v => ((v.Ticks / 1000) << 11) | ((long)v.Offset.TotalMinutes & 0x7FF),
         v => new DateTimeOffset(
             new DateTime((v >> 11) * 1000),
             new TimeSpan(0, (int)((v << 53) >> 53), 0)),
         mappingHints)
 {
 }
Esempio n. 16
0
 /// <summary>
 ///     Initializes a new instance of the <see cref="ValueConverter{TModel,TProvider}" /> class.
 /// </summary>
 /// <param name="convertToProviderExpression"> An expression to convert objects when writing data to the store. </param>
 /// <param name="convertFromProviderExpression"> An expression to convert objects when reading data from the store. </param>
 /// <param name="mappingHints">
 ///     Hints that can be used by the <see cref="ITypeMappingSource" /> to create data types with appropriate
 ///     facets for the converted data.
 /// </param>
 public ValueConverter(
     [NotNull] Expression <Func <TModel, TProvider> > convertToProviderExpression,
     [NotNull] Expression <Func <TProvider, TModel> > convertFromProviderExpression,
     [CanBeNull] ConverterMappingHints mappingHints = null)
     : base(convertToProviderExpression, convertFromProviderExpression, mappingHints)
 {
     _convertToProvider   = SanitizeConverter(convertToProviderExpression);
     _convertFromProvider = SanitizeConverter(convertFromProviderExpression);
 }
Esempio n. 17
0
 /// <summary>
 ///     Creates a new instance of this converter. A case-insensitive first character test is used
 ///     when converting from the store.
 /// </summary>
 /// <param name="falseValue"> The string to use for <c>false</c>. </param>
 /// <param name="trueValue"> The string to use for <c>true</c>. </param>
 /// <param name="mappingHints">
 ///     Hints that can be used by the <see cref="ITypeMappingSource" /> to create data types with appropriate
 ///     facets for the converted data.
 /// </param>
 public BoolToStringConverter(
     [NotNull] string falseValue,
     [NotNull] string trueValue,
     [CanBeNull] ConverterMappingHints mappingHints = null)
     : base(
         Check.NotEmpty(falseValue, nameof(falseValue)),
         Check.NotEmpty(trueValue, nameof(trueValue)),
         FromProvider(trueValue),
         new ConverterMappingHints(size: Math.Max(falseValue.Length, trueValue.Length)).With(mappingHints))
 {
 }
Esempio n. 18
0
        /// <summary>
        ///     Initializes a new instance of the <see cref="ValueConverter" /> class.
        /// </summary>
        /// <param name="convertToProviderExpression">
        ///     The expression to convert objects when writing data to the store,
        ///     exactly as supplied and may not handle
        ///     nulls, boxing, and non-exact matches of simple types.
        /// </param>
        /// <param name="convertFromProviderExpression">
        ///     The expression to convert objects when reading data from the store,
        ///     exactly as supplied and may not handle
        ///     nulls, boxing, and non-exact matches of simple types.
        /// </param>
        /// <param name="mappingHints">
        ///     Hints that can be used by the <see cref="ITypeMappingSource" /> to create data types with appropriate
        ///     facets for the converted data.
        /// </param>
        protected ValueConverter(
            [NotNull] LambdaExpression convertToProviderExpression,
            [NotNull] LambdaExpression convertFromProviderExpression,
            [CanBeNull] ConverterMappingHints mappingHints = null)

        {
            Check.NotNull(convertToProviderExpression, nameof(convertToProviderExpression));
            Check.NotNull(convertFromProviderExpression, nameof(convertFromProviderExpression));

            ConvertToProviderExpression   = convertToProviderExpression;
            ConvertFromProviderExpression = convertFromProviderExpression;
            MappingHints = mappingHints;
        }
Esempio n. 19
0
        /// <summary>
        ///     Creates a new <see cref="ValueConverterInfo" /> instance.
        /// </summary>
        /// <param name="modelClrType"> The CLR type used in the EF model. </param>
        /// <param name="providerClrType"> The CLR type used when reading and writing from the database provider. </param>
        /// <param name="factory"> A factory to create the converter, if needed. </param>
        /// <param name="mappingHints">
        ///     Hints that can be used by the <see cref="ITypeMappingSource" /> to create data types with appropriate
        ///     facets for the converted data.
        /// </param>
        public ValueConverterInfo(
            [NotNull] Type modelClrType,
            [NotNull] Type providerClrType,
            [NotNull] Func <ValueConverterInfo, ValueConverter> factory,
            [CanBeNull] ConverterMappingHints mappingHints = null)
        {
            _factory = factory;
            Check.NotNull(modelClrType, nameof(modelClrType));
            Check.NotNull(providerClrType, nameof(providerClrType));
            Check.NotNull(factory, nameof(factory));

            ModelClrType    = modelClrType;
            ProviderClrType = providerClrType;
            MappingHints    = mappingHints;
        }
Esempio n. 20
0
 /// <summary>
 ///     Creates a new instance of this converter.
 /// </summary>
 /// <param name="mappingHints">
 ///     Hints that can be used by the <see cref="ITypeMappingSource" /> to create data types with appropriate
 ///     facets for the converted data.
 /// </param>
 public TimeSpanToTicksConverter([CanBeNull] ConverterMappingHints mappingHints = null)
     : base(v => v.Ticks, v => new TimeSpan(v), mappingHints)
 {
 }
Esempio n. 21
0
 /// <summary>
 ///     <para>
 ///         Creates a new instance of this converter.
 ///     </para>
 ///     <para>
 ///         This converter supports <see cref="double" />, <see cref="float" />, <see cref="decimal" />,
 ///         <see cref="int" />, <see cref="long" />, <see cref="short" />, <see cref="byte" />,
 ///         <see cref="uint" />, <see cref="ulong" />, <see cref="ushort" />, <see cref="sbyte" />,
 ///         and <see cref="char" />.
 ///     </para>
 /// </summary>
 /// <param name="mappingHints">
 ///     Hints that can be used by the <see cref="ITypeMappingSource" /> to create data types with appropriate
 ///     facets for the converted data.
 /// </param>
 public NumberToBytesConverter([CanBeNull] ConverterMappingHints mappingHints = null)
     : base(ToBytes(), ToNumber(), _defaultHints.With(mappingHints))
 {
 }
Esempio n. 22
0
 /// <summary>
 ///     Creates a new instance of this converter. This converter preserves order.
 /// </summary>
 /// <param name="mappingHints">
 ///     Hints that can be used by the <see cref="ITypeMappingSource" /> to create data types with appropriate
 ///     facets for the converted data.
 /// </param>
 public BoolToZeroOneConverter([CanBeNull] ConverterMappingHints mappingHints = null)
     : base(Zero(), One(), null, mappingHints)
 {
 }