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); }
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); }
// 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); }
protected override void UpdateTarget() { _target.Value = _converter.ConvertBack(_source.Value); }
public async Task SendAsync(ChatActivity activity) { var converted = await converter.ConvertBack(activity); await connector.SendActivity(converted); }
public static TValue?ConvertBackTypeSafe <TValue>(this IConverter converter, object?value) { var result = converter.ConvertBack(value, typeof(TValue)); return(result is TValue castedResult ? castedResult : default);
/// <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))); }
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())); }
public TSource ConvertBack(TTarget value) => first.ConvertBack(second.ConvertBack(value));