using System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.Dynamic; using System.Linq; using System.Reflection; using System.Runtime.CompilerServices; using System.Windows; using System.Windows.Controls; using System.Windows.Controls.Primitives; using System.Windows.Data; using System.Windows.Media; using CurrencyTextBoxControl; using Gestor.Application.Componentes; using Gestor.Model.Helper; using Xceed.Wpf.Toolkit; using Xceed.Wpf.Toolkit.Primitives; namespace Gestor.Application.Helpers; public static class ViewHelper { [CompilerGenerated] private sealed class _003CFindAncestor_003Ed__11 : IEnumerable, IEnumerable, IEnumerator, IDisposable, IEnumerator where T : DependencyObject { private int _003C_003E1__state; private T _003C_003E2__current; private int _003C_003El__initialThreadId; private DependencyObject dependencyObject; public DependencyObject _003C_003E3__dependencyObject; private DependencyObject _003CparentReference_003E5__2; T IEnumerator.Current { [DebuggerHidden] get { return _003C_003E2__current; } } object IEnumerator.Current { [DebuggerHidden] get { return _003C_003E2__current; } } [DebuggerHidden] public _003CFindAncestor_003Ed__11(int _003C_003E1__state) { this._003C_003E1__state = _003C_003E1__state; _003C_003El__initialThreadId = Environment.CurrentManagedThreadId; } [DebuggerHidden] void IDisposable.Dispose() { _003CparentReference_003E5__2 = null; _003C_003E1__state = -2; } private bool MoveNext() { int num = _003C_003E1__state; if (num != 0) { if (num != 1) { return false; } _003C_003E1__state = -1; goto IL_005a; } _003C_003E1__state = -1; _003CparentReference_003E5__2 = VisualTreeHelper.GetParent(dependencyObject); goto IL_006b; IL_005a: _003CparentReference_003E5__2 = VisualTreeHelper.GetParent(_003CparentReference_003E5__2); goto IL_006b; IL_006b: if (_003CparentReference_003E5__2 == null) { return false; } DependencyObject obj = _003CparentReference_003E5__2; T val = (T)(object)((obj is T) ? obj : null); if (val != null) { _003C_003E2__current = val; _003C_003E1__state = 1; return true; } goto IL_005a; } bool IEnumerator.MoveNext() { //ILSpy generated this explicit interface implementation from .override directive in MoveNext return this.MoveNext(); } [DebuggerHidden] void IEnumerator.Reset() { throw new NotSupportedException(); } [DebuggerHidden] IEnumerator IEnumerable.GetEnumerator() { _003CFindAncestor_003Ed__11 _003CFindAncestor_003Ed__; if (_003C_003E1__state == -2 && _003C_003El__initialThreadId == Environment.CurrentManagedThreadId) { _003C_003E1__state = 0; _003CFindAncestor_003Ed__ = this; } else { _003CFindAncestor_003Ed__ = new _003CFindAncestor_003Ed__11(0); } _003CFindAncestor_003Ed__.dependencyObject = _003C_003E3__dependencyObject; return _003CFindAncestor_003Ed__; } [DebuggerHidden] IEnumerator IEnumerable.GetEnumerator() { return ((IEnumerable)this).GetEnumerator(); } } [CompilerGenerated] private sealed class _003CFindChildren_003Ed__2 : IEnumerable, IEnumerable, IEnumerator, IDisposable, IEnumerator where T : DependencyObject { private int _003C_003E1__state; private T _003C_003E2__current; private int _003C_003El__initialThreadId; private DependencyObject depObj; public DependencyObject _003C_003E3__depObj; private IEnumerator _003C_003E7__wrap1; private object _003Cchild_003E5__3; private IEnumerator _003C_003E7__wrap3; T IEnumerator.Current { [DebuggerHidden] get { return _003C_003E2__current; } } object IEnumerator.Current { [DebuggerHidden] get { return _003C_003E2__current; } } [DebuggerHidden] public _003CFindChildren_003Ed__2(int _003C_003E1__state) { this._003C_003E1__state = _003C_003E1__state; _003C_003El__initialThreadId = Environment.CurrentManagedThreadId; } [DebuggerHidden] void IDisposable.Dispose() { int num = _003C_003E1__state; if ((uint)(num - -4) <= 1u || (uint)(num - 1) <= 1u) { try { if (num == -4 || num == 2) { try { } finally { _003C_003Em__Finally2(); } } } finally { _003C_003Em__Finally1(); } } _003C_003E7__wrap1 = null; _003Cchild_003E5__3 = null; _003C_003E7__wrap3 = null; _003C_003E1__state = -2; } private bool MoveNext() { try { object obj; DependencyObject val; switch (_003C_003E1__state) { default: return false; case 0: _003C_003E1__state = -1; if (depObj == null) { return false; } _003C_003E7__wrap1 = LogicalTreeHelper.GetChildren(depObj).GetEnumerator(); _003C_003E1__state = -3; goto IL_012e; case 1: _003C_003E1__state = -3; goto IL_00be; case 2: { _003C_003E1__state = -4; goto IL_010d; } IL_010d: if (_003C_003E7__wrap3.MoveNext()) { T current = _003C_003E7__wrap3.Current; _003C_003E2__current = current; _003C_003E1__state = 2; return true; } _003C_003Em__Finally2(); _003C_003E7__wrap3 = null; _003Cchild_003E5__3 = null; goto IL_012e; IL_00be: obj = _003Cchild_003E5__3; val = (DependencyObject)((obj is DependencyObject) ? obj : null); _003C_003E7__wrap3 = val.FindChildren().GetEnumerator(); _003C_003E1__state = -4; goto IL_010d; IL_012e: if (_003C_003E7__wrap1.MoveNext()) { _003Cchild_003E5__3 = _003C_003E7__wrap1.Current; object obj2 = _003Cchild_003E5__3; T val2 = (T)((obj2 is T) ? obj2 : null); if (val2 != null) { object obj3 = val2; object obj4 = ((obj3 is ContentControl) ? obj3 : null); object obj5 = val2; UserControl val3 = (UserControl)((obj5 is UserControl) ? obj5 : null); if (obj4 == null || val3 != null) { _003C_003E2__current = val2; _003C_003E1__state = 1; return true; } } goto IL_00be; } _003C_003Em__Finally1(); _003C_003E7__wrap1 = null; return false; } } catch { //try-fault ((IDisposable)this).Dispose(); throw; } } bool IEnumerator.MoveNext() { //ILSpy generated this explicit interface implementation from .override directive in MoveNext return this.MoveNext(); } private void _003C_003Em__Finally1() { _003C_003E1__state = -1; if (_003C_003E7__wrap1 is IDisposable disposable) { disposable.Dispose(); } } private void _003C_003Em__Finally2() { _003C_003E1__state = -3; if (_003C_003E7__wrap3 != null) { _003C_003E7__wrap3.Dispose(); } } [DebuggerHidden] void IEnumerator.Reset() { throw new NotSupportedException(); } [DebuggerHidden] IEnumerator IEnumerable.GetEnumerator() { _003CFindChildren_003Ed__2 _003CFindChildren_003Ed__; if (_003C_003E1__state == -2 && _003C_003El__initialThreadId == Environment.CurrentManagedThreadId) { _003C_003E1__state = 0; _003CFindChildren_003Ed__ = this; } else { _003CFindChildren_003Ed__ = new _003CFindChildren_003Ed__2(0); } _003CFindChildren_003Ed__.depObj = _003C_003E3__depObj; return _003CFindChildren_003Ed__; } [DebuggerHidden] IEnumerator IEnumerable.GetEnumerator() { return ((IEnumerable)this).GetEnumerator(); } } [CompilerGenerated] private sealed class _003CFindParent_003Ed__3 : IEnumerable, IEnumerable, IEnumerator, IDisposable, IEnumerator where T : DependencyObject { private int _003C_003E1__state; private T _003C_003E2__current; private int _003C_003El__initialThreadId; private DependencyObject depObj; public DependencyObject _003C_003E3__depObj; private DependencyObject _003CfirstParent_003E5__2; private IEnumerator _003C_003E7__wrap2; T IEnumerator.Current { [DebuggerHidden] get { return _003C_003E2__current; } } object IEnumerator.Current { [DebuggerHidden] get { return _003C_003E2__current; } } [DebuggerHidden] public _003CFindParent_003Ed__3(int _003C_003E1__state) { this._003C_003E1__state = _003C_003E1__state; _003C_003El__initialThreadId = Environment.CurrentManagedThreadId; } [DebuggerHidden] void IDisposable.Dispose() { int num = _003C_003E1__state; if (num == -3 || num == 2) { try { } finally { _003C_003Em__Finally1(); } } _003CfirstParent_003E5__2 = null; _003C_003E7__wrap2 = null; _003C_003E1__state = -2; } private bool MoveNext() { try { DependencyObject val2; switch (_003C_003E1__state) { default: return false; case 0: { _003C_003E1__state = -1; if (depObj == null) { return false; } _003CfirstParent_003E5__2 = LogicalTreeHelper.GetParent(depObj); DependencyObject obj = _003CfirstParent_003E5__2; T val = (T)(object)((obj is T) ? obj : null); if (val != null) { _003C_003E2__current = val; _003C_003E1__state = 1; return true; } goto IL_0079; } case 1: _003C_003E1__state = -1; goto IL_0079; case 2: { _003C_003E1__state = -3; break; } IL_0079: val2 = _003CfirstParent_003E5__2; _003C_003E7__wrap2 = val2.FindParent().GetEnumerator(); _003C_003E1__state = -3; break; } if (_003C_003E7__wrap2.MoveNext()) { T current = _003C_003E7__wrap2.Current; _003C_003E2__current = current; _003C_003E1__state = 2; return true; } _003C_003Em__Finally1(); _003C_003E7__wrap2 = null; return false; } catch { //try-fault ((IDisposable)this).Dispose(); throw; } } bool IEnumerator.MoveNext() { //ILSpy generated this explicit interface implementation from .override directive in MoveNext return this.MoveNext(); } private void _003C_003Em__Finally1() { _003C_003E1__state = -1; if (_003C_003E7__wrap2 != null) { _003C_003E7__wrap2.Dispose(); } } [DebuggerHidden] void IEnumerator.Reset() { throw new NotSupportedException(); } [DebuggerHidden] IEnumerator IEnumerable.GetEnumerator() { _003CFindParent_003Ed__3 _003CFindParent_003Ed__; if (_003C_003E1__state == -2 && _003C_003El__initialThreadId == Environment.CurrentManagedThreadId) { _003C_003E1__state = 0; _003CFindParent_003Ed__ = this; } else { _003CFindParent_003Ed__ = new _003CFindParent_003Ed__3(0); } _003CFindParent_003Ed__.depObj = _003C_003E3__depObj; return _003CFindParent_003Ed__; } [DebuggerHidden] IEnumerator IEnumerable.GetEnumerator() { return ((IEnumerable)this).GetEnumerator(); } } public static void ControlLostFocus(object sender, RoutedEventArgs e) { //IL_00a2: Unknown result type (might be due to invalid IL or missing references) //IL_0675: Unknown result type (might be due to invalid IL or missing references) //IL_0680: Expected O, but got Unknown //IL_067b: Unknown result type (might be due to invalid IL or missing references) //IL_0680: Unknown result type (might be due to invalid IL or missing references) //IL_068a: Expected O, but got Unknown Control val = null; if (sender is CustomItemValidation) { val = ((DependencyObject)(object)(sender as CustomItemValidation)).FindChildren().FirstOrDefault((Func)((Control currentControl) => currentControl is PasswordBox || currentControl is TextBox || currentControl is ToggleButton || currentControl is DatePicker || currentControl is ComboBox || currentControl is AutoCompleteBox || currentControl is CheckComboBox || currentControl is Button || currentControl is CustomPasswordBox)); } if (sender is CustomIsReadOnlyControl) { CustomIsReadOnlyControl customIsReadOnlyControl = sender as CustomIsReadOnlyControl; val = ((!customIsReadOnlyControl.HasValidation) ? null : ((DependencyObject)(object)customIsReadOnlyControl).FindChildren().LastOrDefault((Func)((Control currentControl) => currentControl is PasswordBox || currentControl is TextBox || currentControl is ToggleButton || currentControl is DatePicker || currentControl is ComboBox || currentControl is AutoCompleteBox || currentControl is CheckComboBox || currentControl is Button))); } if (val == null) { return; } ComboBox val2 = (ComboBox)(object)((val is ComboBox) ? val : null); if ((val2 != null && val2.IsDropDownOpen) || (val is TextBox && ((TextBoxBase)(TextBox)val).IsReadOnly)) { return; } DependencyProperty dependencyProperty = GetDependencyProperty(val); if (dependencyProperty == null) { return; } BindingExpression bindingExpression = ((FrameworkElement)val).GetBindingExpression(dependencyProperty); if (bindingExpression == null) { return; } Validation.ClearInvalid((BindingExpressionBase)(object)bindingExpression); List list = bindingExpression.ParentBinding.Path.Path.Split(new char[1] { '.' }).ToList(); Type type = bindingExpression.DataItem.GetType(); if (!list.Any()) { return; } PropertyInfo property = type.GetProperty(list.First()); if (property == null) { return; } dynamic value = property.GetValue(bindingExpression.DataItem, null); List> list2 = new List>(); if ((!ViewHelper.HasMethod(value, "ValidationEvent"))) { dynamic resolvedSource = bindingExpression.ResolvedSource; if (resolvedSource is Control || ((!ViewHelper.HasMethod(resolvedSource, "ValidationEvent"))) || ((resolvedSource?.ValidationEvent == null) ? true : false)) { return; } if (resolvedSource.ValidationEvent is Func>> func) { list2 = func(); } if (list2.Count == 0) { return; } } if (list2.Count == 0) { if (value?.ValidationEvent == null) { return; } if (value.ValidationEvent is Func>> func2) { list2 = func2(); } } if (list2 == null || !list2.Any()) { return; } string text = ((list.Last() == "Id") ? list[list.Count - 2] : list.Last()); string valueExact = ValidationHelper.GetValueExact(list2, text); if (string.IsNullOrEmpty(valueExact)) { valueExact = ValidationHelper.GetValueExact(list2, text); if (string.IsNullOrEmpty(valueExact)) { return; } } ValidationError val3 = new ValidationError((ValidationRule)new ExceptionValidationRule(), (object)bindingExpression) { ErrorContent = valueExact }; Validation.MarkInvalid((BindingExpressionBase)(object)bindingExpression, val3); } public static bool IsPropertyExist(dynamic settings, string name) { if (settings is ExpandoObject) { return ((IDictionary)settings).ContainsKey(name); } return settings.GetType().GetProperty(name) != null; } [IteratorStateMachine(typeof(_003CFindChildren_003Ed__2<>))] public static IEnumerable FindChildren(this DependencyObject depObj) where T : DependencyObject { //yield-return decompiler failed: Unexpected instruction in Iterator.Dispose() return new _003CFindChildren_003Ed__2(-2) { _003C_003E3__depObj = depObj }; } [IteratorStateMachine(typeof(_003CFindParent_003Ed__3<>))] public static IEnumerable FindParent(this DependencyObject depObj) where T : DependencyObject { //yield-return decompiler failed: Unexpected instruction in Iterator.Dispose() return new _003CFindParent_003Ed__3(-2) { _003C_003E3__depObj = depObj }; } public static T Window() where T : Window { return ((IEnumerable)Application.Current.Windows).OfType().FirstOrDefault(); } public static void ValidateFields(this DependencyObject dependencyObject, List> errorMessages, bool focusField = true) { if (errorMessages == null || !errorMessages.Any()) { dependencyObject.ClearInvalid(); return; } Control val = null; foreach (Control item in dependencyObject.FindChildren()) { Control val2 = item.SetInvalid(errorMessages); if (val == null && val2 != null) { val = val2; } } if (focusField && val != null) { ((UIElement)val).Focus(); } } public static Control SetInvalid(this Control currentControl, List> errorMessages = null, string specificKey = null) { //IL_0320: Unknown result type (might be due to invalid IL or missing references) //IL_032b: Expected O, but got Unknown //IL_0326: Unknown result type (might be due to invalid IL or missing references) //IL_032b: Unknown result type (might be due to invalid IL or missing references) //IL_0335: Expected O, but got Unknown DependencyProperty dependencyProperty = GetDependencyProperty(currentControl); if (dependencyProperty == null) { return null; } BindingExpression bindingExpression = ((FrameworkElement)currentControl).GetBindingExpression(dependencyProperty); if (errorMessages == null) { dynamic val = ((bindingExpression != null) ? bindingExpression.ResolvedSource : null); if (val is Control) { return null; } if ((!ViewHelper.HasMethod(val, "ValidationEvent"))) { return null; } if (val?.ValidationEvent == null) { return null; } if (val.ValidationEvent is Func>> func) { errorMessages = func(); } } if (bindingExpression == null) { return null; } BindingExpressionBase bindingExpressionBase = BindingOperations.GetBindingExpressionBase((DependencyObject)(object)currentControl, dependencyProperty); if (bindingExpressionBase == null) { return null; } Validation.ClearInvalid(bindingExpressionBase); if (errorMessages == null || !errorMessages.Any()) { return null; } string[] array = bindingExpression.ParentBinding.Path.Path.Split(new char[1] { '.' }); string text = specificKey ?? ((array.Last() == "Id") ? array[^2] : array.Last()); string valueExact = ValidationHelper.GetValueExact(errorMessages, text); if (string.IsNullOrEmpty(valueExact)) { valueExact = ValidationHelper.GetValueExact(errorMessages, text); if (string.IsNullOrEmpty(valueExact)) { return null; } } ValidationError val2 = new ValidationError((ValidationRule)new ExceptionValidationRule(), (object)bindingExpression) { ErrorContent = valueExact }; Validation.MarkInvalid(bindingExpressionBase, val2); return currentControl; } private static DependencyProperty GetDependencyProperty(Control currentControl) { DependencyProperty result = null; if (currentControl is CheckComboBox) { result = Selector.SelectedValueProperty; } if (currentControl is DatePicker) { result = DatePicker.SelectedDateProperty; } if (currentControl is AutoCompleteBox) { result = AutoCompleteBox.SelectedItemProperty; } if (currentControl is TextBox) { result = TextBox.TextProperty; } if (currentControl is MaskedTextBox) { result = TextBox.TextProperty; } if (currentControl is ComboBox) { result = Selector.SelectedValueProperty; } if (currentControl is CurrencyTextBox) { result = CurrencyTextBox.NumberProperty; } if (currentControl is ToggleButton) { result = ToggleButton.IsCheckedProperty; } if (currentControl is CustomPasswordBox) { result = CustomPasswordBox.TextProperty; } return result; } public static bool HasMethod(object objectToCheck, string methodName) { if (objectToCheck == null) { return false; } return objectToCheck.GetType().GetProperty(methodName) != null; } public static bool IsValid(this DependencyObject obj) { if (!Validation.GetHasError(obj)) { return LogicalTreeHelper.GetChildren(obj).OfType().All(IsValid); } return false; } public static void ClearInvalid(this DependencyObject dependencyObject) { foreach (Control item in dependencyObject.FindChildren()) { item.SetInvalid(); } } [IteratorStateMachine(typeof(_003CFindAncestor_003Ed__11<>))] public static IEnumerable FindAncestor(this DependencyObject dependencyObject) where T : DependencyObject { //yield-return decompiler failed: Unexpected instruction in Iterator.Dispose() return new _003CFindAncestor_003Ed__11(-2) { _003C_003E3__dependencyObject = dependencyObject }; } private static bool Compare(Control currentControl) { DependencyProperty dependencyProperty = GetDependencyProperty(currentControl); if (dependencyProperty == null) { return false; } BindingExpression bindingExpression = ((FrameworkElement)currentControl).GetBindingExpression(dependencyProperty); dynamic val = ((bindingExpression != null) ? bindingExpression.ResolvedSource : null); return val != null && (bool)val.HasChange(); } public static bool IsWindowOpen(string name = "") where T : Window { if (!string.IsNullOrEmpty(name)) { return ((IEnumerable)Application.Current.Windows).OfType().Any((T w) => ((FrameworkElement)(object)w).Name.Equals(name)); } return ((IEnumerable)Application.Current.Windows).OfType().Any(); } public static void SetInvalid(Control control, string error, bool valid) { //IL_0017: Unknown result type (might be due to invalid IL or missing references) //IL_0022: Expected O, but got Unknown //IL_001d: Unknown result type (might be due to invalid IL or missing references) //IL_0022: Unknown result type (might be due to invalid IL or missing references) //IL_002a: Expected O, but got Unknown DependencyProperty dependencyProperty = GetDependencyProperty(control); if (dependencyProperty == null) { return; } BindingExpression bindingExpression = ((FrameworkElement)control).GetBindingExpression(dependencyProperty); if (bindingExpression == null) { return; } ValidationError val = new ValidationError((ValidationRule)new ExceptionValidationRule(), (object)bindingExpression) { ErrorContent = error }; BindingExpressionBase bindingExpressionBase = BindingOperations.GetBindingExpressionBase((DependencyObject)(object)control, dependencyProperty); if (bindingExpressionBase != null) { Validation.ClearInvalid(bindingExpressionBase); if (!valid) { Validation.MarkInvalid(bindingExpressionBase, val); } } } internal static void BindData(this CheckComboBox comboBox, bool withSelect = true, bool enumDefault = true, string defaultValue = "", bool orderByLabel = false) { DefaultBinding(comboBox, withSelect, enumDefault, defaultValue, string.Empty, orderByLabel); } private static void DefaultBinding(CheckComboBox comboBox, bool withSelect, bool enumDefault, string defaultValue = "", string defaultText = "", bool orderByLabel = false) { List> source = (List>)(((ItemsControl)comboBox).ItemsSource = BindingHelper.BindingData(withSelect, enumDefault, defaultValue, defaultText, orderByLabel)); ((Selector)comboBox).ValueMemberPath = "Key"; ((ItemsControl)comboBox).DisplayMemberPath = "Value"; ((Selector)comboBox).SelectedItem = source.First(); } }