protected override bool CanHandle(HandlerParams param) { if (InChat != InChat.All && param.InChat != InChat) { return(false); } if (UpdateFlags.HasFlag(UpdateFlag.All)) { return(true); } return(param.Type switch { UpdateType.Message => UpdateFlags.HasFlag(UpdateFlag.Message), UpdateType.InlineQuery => UpdateFlags.HasFlag(UpdateFlag.InlineQuery), UpdateType.ChosenInlineResult => UpdateFlags.HasFlag(UpdateFlag.ChosenInlineResult), UpdateType.CallbackQuery => UpdateFlags.HasFlag(UpdateFlag.CallbackQuery), UpdateType.EditedMessage => UpdateFlags.HasFlag(UpdateFlag.EditedMessage), UpdateType.ChannelPost => UpdateFlags.HasFlag(UpdateFlag.ChannelPost), UpdateType.EditedChannelPost => UpdateFlags.HasFlag(UpdateFlag.EditedChannelPost), UpdateType.ShippingQuery => UpdateFlags.HasFlag(UpdateFlag.ShippingQuery), UpdateType.PreCheckoutQuery => UpdateFlags.HasFlag(UpdateFlag.PreCheckoutQuery), UpdateType.Poll => UpdateFlags.HasFlag(UpdateFlag.Poll), UpdateType.PollAnswer => UpdateFlags.HasFlag(UpdateFlag.PollAnswer), UpdateType.MyChatMember => UpdateFlags.HasFlag(UpdateFlag.MyChatMember), UpdateType.ChatMember => UpdateFlags.HasFlag(UpdateFlag.ChatMember), _ => false });
/// <summary> /// Copies the values of properties from the source object to the target object through reflection and returns a collection of updated properties. /// The source object and the target object need not to be of the same type. /// </summary> /// <param name="source">The source object containing the properties you wish to copy</param> /// <param name="target">The target object(destination) where the values are copied to. The source</param> /// <param name="bindingFlags">Indicates how properties are discovered within source object type</param> /// <param name="updateFlags">Additional flags that determine how the target object properties are updated</param> /// <param name="only">When this paramerter is set, only matching properties are used</param> /// <param name="exclude">When set, properties matching any member is ignored</param> /// <returns>The updated properties</returns> public static string[] CopyPropertiesTo(object source, object target, UpdateFlag updateFlags = UpdateFlag.None, string[] only = null, string[] exclude = null, BindingFlags bindingFlags = BindingFlags.Instance | BindingFlags.Public) { var targetType = target.GetType(); var srcType = source.GetType(); var properties = targetType.GetProperties(bindingFlags); if (only != null) { properties = properties.Where(x => only.Contains(x.Name)).ToArray(); } if (exclude != null) { properties = properties.Where(x => !exclude.Contains(x.Name)).ToArray(); } List <string> updatedProperties = new List <string>(properties.Count() + 1); if (srcType == targetType) { foreach (var property in properties) { var val = property.GetValue(source); if ((updateFlags.HasFlag(UpdateFlag.DeferUpdateOnNull) && val == null) || (updateFlags.HasFlag(UpdateFlag.DenoteEmptyStringsAsNull) && property.PropertyType == typeof(string) && string.IsNullOrEmpty(val?.ToString()))) { continue; } if (val?.Equals(property.GetValue(target)) == false) { property.SetValue(target, property.GetValue(source)); updatedProperties.Add(property.Name); } } } else { foreach (var property in properties) { var equivalent = srcType.GetProperty(property.Name, bindingFlags); if (equivalent != null) { var val = equivalent.GetValue(source); if ((updateFlags.HasFlag(UpdateFlag.DeferUpdateOnNull) && val == null) || (updateFlags.HasFlag(UpdateFlag.DenoteEmptyStringsAsNull) && property.PropertyType == typeof(string) && string.IsNullOrEmpty(val?.ToString()))) { continue; } if (val?.Equals(property.GetValue(target)) == false) { property.SetValue(target, equivalent.GetValue(source)); updatedProperties.Add(property.Name); } } } } return(updatedProperties.ToArray()); }