Exemple #1
0
        public async Task Handle(TModel model)
        {
            var activity = await converter.ConvertBack(model);

            var key = activity.Chat.Id;

            var state = await storage.GetValue(key) ?? chatState;

            var newState = await state.HandleActivity(activity, context);

            await storage.SaveChanges(key, newState);
        }
Exemple #2
0
        public static object ConvertWith(string s, IConverter converter)
        {
            if (s == null)
            {
                return(null);
            }
            var res = converter.ConvertBack(s);

            if (res == null)
            {
                throw new ArgumentException("Failed to parse.");
            }
            return(res);
        }
Exemple #3
0
        // made public for reflection
        public void SetInternal <T>(object toSet, string propertyName, IConverter converter)
        {
            if (toSet == null)
            {
                toSet = default(T);
            }

            if (converter != null)
            {
                toSet = converter.ConvertBack(toSet);
            }

            Set <T>((T)toSet, propertyName);
        }
Exemple #4
0
 protected override void UpdateTarget()
 {
     _target.Value = _converter.ConvertBack(_source.Value);
 }
Exemple #5
0
        public async Task SendAsync(ChatActivity activity)
        {
            var converted = await converter.ConvertBack(activity);

            await connector.SendActivity(converted);
        }
Exemple #6
0
        public static TValue?ConvertBackTypeSafe <TValue>(this IConverter converter, object?value)
        {
            var result = converter.ConvertBack(value, typeof(TValue));

            return(result is TValue castedResult ? castedResult : default);
Exemple #7
0
 /// <summary>
 /// Invert the given converter by interchanging convert and convert back.
 /// </summary>
 /// <param name="target">Target.</param>
 /// <typeparam name="TSource">The 1st type parameter.</typeparam>
 /// <typeparam name="TTarget">The 2nd type parameter.</typeparam>
 public static IConverter <TTarget, TSource> Inverse <TSource, TTarget>(this IConverter <TSource, TTarget> target)
 {
     return(new RelayConverter <TTarget, TSource>(v => target.ConvertBack(v), v => target.Convert(v)));
 }
Exemple #8
0
 public static IConverter <TSource[], TTarget[]> ArrayToArray <TSource, TTarget>(IConverter <TSource, TTarget> elementConverter = null)
 {
     elementConverter = elementConverter ?? Default <TSource, TTarget>();
     return(new RelayConverter <TSource[], TTarget[]>((arg) => arg.Select(a => elementConverter.Convert(a)).ToArray(), (arg) => arg.Select(a => elementConverter.ConvertBack(a)).ToArray()));
 }
Exemple #9
0
 public TSource ConvertBack(TTarget value) => first.ConvertBack(second.ConvertBack(value));