示例#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);
        }
示例#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);
        }
示例#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);
        }
示例#4
0
 protected override void UpdateTarget()
 {
     _target.Value = _converter.ConvertBack(_source.Value);
 }
示例#5
0
        public async Task SendAsync(ChatActivity activity)
        {
            var converted = await converter.ConvertBack(activity);

            await connector.SendActivity(converted);
        }
示例#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);
示例#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)));
 }
示例#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()));
 }
示例#9
0
 public TSource ConvertBack(TTarget value) => first.ConvertBack(second.ConvertBack(value));