示例#1
0
 /// <summary>
 /// For internal use only.
 /// </summary>
 /// <param name="factory"></param>
 /// <param name="receiver"></param>
 /// <param name="setter"></param>
 /// <param name="existingValue"></param>
 /// <returns></returns>
 public static EventCallback <UIChangeEventArgs> CreateBinder(
     this EventCallbackFactory factory,
     object receiver,
     Action <string> setter,
     string existingValue)
 {
     ;
     return(CreateBinderCore <string>(factory, receiver, setter, ConvertToString));
 }
 public static EventCallback <ChangeEventArgs> CreateBinder <[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)] T>(
     this EventCallbackFactory factory,
     object receiver,
     Action <T> setter,
     T existingValue,
     CultureInfo?culture = null)
 {
     return(CreateBinderCore <T>(factory, receiver, setter, culture, ParserDelegateCache.Get <T>()));
 }
 public static EventCallback <ChangeEventArgs> CreateBinder(
     this EventCallbackFactory factory,
     object receiver,
     Action <bool> setter,
     bool existingValue,
     CultureInfo?culture = null)
 {
     return(CreateBinderCore <bool>(factory, receiver, setter, culture, ConvertToBool));
 }
        /// <summary>
        /// Creates an <see cref="EventCallback"/> for the provided <paramref name="receiver"/> and
        /// <paramref name="callback"/>.
        /// </summary>
        /// <param name="factory">The <see cref="EventCallbackFactory"/>.</param>
        /// <param name="receiver">The event receiver.</param>
        /// <param name="callback">The event callback.</param>
        /// <returns>The <see cref="EventCallback"/>.</returns>
        public static EventCallback <ChangeEventArgs> Create(this EventCallbackFactory factory, object receiver, Func <ChangeEventArgs, Task> callback)
        {
            if (factory == null)
            {
                throw new ArgumentNullException(nameof(factory));
            }

            return(factory.Create <ChangeEventArgs>(receiver, callback));
        }
 /// <summary>
 /// For internal use only.
 /// </summary>
 /// <param name="factory"></param>
 /// <param name="receiver"></param>
 /// <param name="setter"></param>
 /// <param name="existingValue"></param>
 /// <param name="culture"></param>
 /// <returns></returns>
 public static EventCallback <UIChangeEventArgs> CreateBinder(
     this EventCallbackFactory factory,
     object receiver,
     Action <DateTimeOffset?> setter,
     DateTimeOffset?existingValue,
     CultureInfo culture = null)
 {
     return(CreateBinderCore <DateTimeOffset?>(factory, receiver, setter, culture, format: null, ConvertToNullableDateTimeOffsetWithFormat));
 }
 public static EventCallback <ChangeEventArgs> CreateBinder(
     this EventCallbackFactory factory,
     object receiver,
     Action <double> setter,
     double existingValue,
     CultureInfo?culture = null)
 {
     return(CreateBinderCore <double>(factory, receiver, setter, culture, ConvertToDoubleDelegate));
 }
 public static EventCallback <ChangeEventArgs> CreateBinder(
     this EventCallbackFactory factory,
     object receiver,
     Action <DateTimeOffset> setter,
     DateTimeOffset existingValue,
     CultureInfo?culture = null)
 {
     return(CreateBinderCore <DateTimeOffset>(factory, receiver, setter, culture, ConvertToDateTimeOffset));
 }
 public static EventCallback <ChangeEventArgs> CreateBinder(
     this EventCallbackFactory factory,
     object receiver,
     Action <short?> setter,
     short?existingValue,
     CultureInfo?culture = null)
 {
     return(CreateBinderCore <short?>(factory, receiver, setter, culture, ConvertToNullableShort));
 }
 /// <summary>
 /// For internal use only.
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="factory"></param>
 /// <param name="receiver"></param>
 /// <param name="setter"></param>
 /// <param name="existingValue"></param>
 /// <param name="culture"></param>
 /// <returns></returns>
 public static EventCallback <UIChangeEventArgs> CreateBinder <T>(
     this EventCallbackFactory factory,
     object receiver,
     Action <T> setter,
     T existingValue,
     CultureInfo culture = null)
 {
     return(CreateBinderCore <T>(factory, receiver, setter, culture, BinderConverterCache.Get <T>()));
 }
        /// <summary>
        /// Creates an <see cref="EventCallback"/> for the provided <paramref name="receiver"/> and
        /// <paramref name="callback"/>.
        /// </summary>
        /// <param name="factory">The <see cref="EventCallbackFactory"/>.</param>
        /// <param name="receiver">The event receiver.</param>
        /// <param name="callback">The event callback.</param>
        /// <returns>The <see cref="EventCallback"/>.</returns>
        public static EventCallback <UIErrorEventArgs> Create(this EventCallbackFactory factory, object receiver, Action <UIErrorEventArgs> callback)
        {
            if (factory == null)
            {
                throw new ArgumentNullException(nameof(factory));
            }

            return(factory.Create <UIErrorEventArgs>(receiver, callback));
        }
 /// <summary>
 /// For internal use only.
 /// </summary>
 /// <param name="factory"></param>
 /// <param name="receiver"></param>
 /// <param name="setter"></param>
 /// <param name="existingValue"></param>
 /// <param name="culture"></param>
 /// <returns></returns>
 public static EventCallback <UIChangeEventArgs> CreateBinder(
     this EventCallbackFactory factory,
     object receiver,
     Action <float> setter,
     float existingValue,
     CultureInfo culture = null)
 {
     return(CreateBinderCore <float>(factory, receiver, setter, culture, ConvertToFloat));
 }
 /// <summary>
 /// For internal use only.
 /// </summary>
 /// <param name="factory"></param>
 /// <param name="receiver"></param>
 /// <param name="setter"></param>
 /// <param name="existingValue"></param>
 /// <param name="culture"></param>
 /// <returns></returns>
 public static EventCallback <UIChangeEventArgs> CreateBinder(
     this EventCallbackFactory factory,
     object receiver,
     Action <decimal?> setter,
     decimal?existingValue,
     CultureInfo culture = null)
 {
     return(CreateBinderCore <decimal?>(factory, receiver, setter, culture, ConvertToNullableDecimal));
 }
示例#13
0
 public static EventCallback <ChangeEventArgs> CreateBinder(
     this EventCallbackFactory factory,
     object receiver,
     Action <TimeOnly?> setter,
     TimeOnly?existingValue,
     string format,
     CultureInfo?culture = null)
 {
     return(CreateBinderCore <TimeOnly?>(factory, receiver, setter, culture, format, ConvertToNullableTimeOnlyWithFormat));
 }
 /// <summary>
 /// For internal use only.
 /// </summary>
 /// <param name="factory"></param>
 /// <param name="receiver"></param>
 /// <param name="setter"></param>
 /// <param name="existingValue"></param>
 /// <param name="format"></param>
 /// <param name="culture"></param>
 /// <returns></returns>
 public static EventCallback <UIChangeEventArgs> CreateBinder(
     this EventCallbackFactory factory,
     object receiver,
     Action <DateTime> setter,
     DateTime existingValue,
     string format,
     CultureInfo culture = null)
 {
     return(CreateBinderCore <DateTime>(factory, receiver, setter, culture, format, ConvertToDateTimeWithFormat));
 }
        /// <summary>
        /// For internal use only.
        /// </summary>
        /// <param name="factory"></param>
        /// <param name="receiver"></param>
        /// <param name="setter"></param>
        /// <param name="existingValue"></param>
        /// <returns></returns>
        public static EventCallback <UIChangeEventArgs> CreateBinder(
            this EventCallbackFactory factory,
            object receiver,
            Action <DateTime> setter,
            DateTime existingValue)
        {
            // Avoiding CreateBinderCore so we can avoid an extra allocating lambda
            // when a format is used.
            Action <UIChangeEventArgs> callback = (e) =>
            {
                setter(ConvertDateTime(e.Value, format: null));
            };

            return(factory.Create <UIChangeEventArgs>(receiver, callback));
        }
示例#16
0
        /// <summary>
        /// For internal use only.
        /// </summary>
        /// <param name="factory"></param>
        /// <param name="receiver"></param>
        /// <param name="setter"></param>
        /// <param name="existingValue"></param>
        /// <returns></returns>
        public static EventCallback <UIChangeEventArgs> CreateBinder(
            this EventCallbackFactory factory,
            object receiver,
            Action <decimal?> setter,
            decimal?existingValue)
        {
            Func <object, decimal?> converter = (obj) =>
            {
                if (decimal.TryParse((string)obj, out var value))
                {
                    return(value);
                }

                return(null);
            };

            return(CreateBinderCore <decimal?>(factory, receiver, setter, ConvertToNullableDecimal));
        }
        private static EventCallback <UIChangeEventArgs> CreateBinderCore <T>(
            this EventCallbackFactory factory,
            object receiver,
            Action <T> setter,
            CultureInfo culture,
            BindConverter <T> converter)
        {
            Action <UIChangeEventArgs> callback = e =>
            {
                T   value     = default;
                var converted = false;
                try
                {
                    converted = converter(e.Value, culture, out value);
                }
                catch
                {
                }

                // We only invoke the setter if the conversion didn't throw, or if the newly-entered value is empty.
                // If the user entered some non-empty value we couldn't parse, we leave the state of the .NET field
                // unchanged, which for a two-way binding results in the UI reverting to its previous valid state
                // because the diff will see the current .NET output no longer matches the render tree since we
                // patched it to reflect the state of the UI.
                //
                // This reversion behavior is valuable because alternatives are problematic:
                // - If we assigned default(T) on failure, the user would lose whatever data they were editing,
                //   for example if they accidentally pressed an alphabetical key while editing a number with
                //   @bind:event="oninput"
                // - If the diff mechanism didn't revert to the previous good value, the user wouldn't necessarily
                //   know that the data they are submitting is different from what they think they've typed
                if (converted)
                {
                    setter(value);
                }
                else if (string.Empty.Equals(e.Value))
                {
                    setter(default);
示例#18
0
 public static EventCallback <UIChangeEventArgs> CreateBinder(
     this EventCallbackFactory factory,
     object receiver,
     Action <string> setter,
     string existingValue) => default;
 public static EventCallback <UIWheelEventArgs> Create(this EventCallbackFactory factory, object receiver, Func <UIWheelEventArgs, Task> callback) => default;
 public static EventCallback <UITouchEventArgs> Create(this EventCallbackFactory factory, object receiver, Action <UITouchEventArgs> callback) => default;
示例#21
0
 public static EventCallback <UIChangeEventArgs> CreateBinder(
     this EventCallbackFactory factory,
     object receiver,
     Action <DateTime> setter,
     DateTime existingValue,
     string format) => default;
示例#22
0
 public static EventCallback <UIChangeEventArgs> CreateBinder <T>(
     this EventCallbackFactory factory,
     object receiver,
     Action <T> setter,
     T existingValue) where T : Enum => default;