// Token: 0x06000962 RID: 2402 RVA: 0x00020E34 File Offset: 0x0001F034 internal bool ConvertAndMatch(object state) { object obj = this.Value; string text = obj as string; Type type = (state != null) ? state.GetType() : null; if (text != null && type != null && type != typeof(string)) { BindingValueCache bindingValueCache = this.BindingValueCache; Type bindingValueType = bindingValueCache.BindingValueType; object obj2 = bindingValueCache.ValueAsBindingValueType; if (type != bindingValueType) { obj2 = obj; TypeConverter converter = DefaultValueConverter.GetConverter(type); if (converter != null && converter.CanConvertFrom(typeof(string))) { try { obj2 = converter.ConvertFromString(null, TypeConverterHelper.InvariantEnglishUS, text); } catch (Exception ex) { if (CriticalExceptions.IsCriticalApplicationException(ex)) { throw; } } catch { } } bindingValueCache = new BindingValueCache(type, obj2); this.BindingValueCache = bindingValueCache; } obj = obj2; } return(this.Match(state, obj)); }
internal TriggerCondition(BindingBase binding, LogicalOp logicalOp, object value, string sourceName) { Property = null; Binding = binding; LogicalOp = logicalOp; Value = value; SourceName = sourceName; SourceChildIndex = 0; BindingValueCache = new BindingValueCache(null, null); }
// Check for match, after converting the reference value to the type // of the state value. (Used by data triggers) internal bool ConvertAndMatch(object state) { // convert the reference value to the type of 'state', // provided the reference value is a string and the // state isn't null or a string. (Otherwise, we can // compare the state and reference values directly.) object referenceValue = Value; string referenceString = referenceValue as String; Type stateType = (state != null) ? state.GetType() : null; if (referenceString != null && stateType != null && stateType != typeof(String)) { // the most recent type and value are cached in the // TriggerCondition, since it's very likely the // condition's Binding produces the same type of // value every time. The cached values can be used // on any thread, so we must synchronize access. BindingValueCache bindingValueCache = BindingValueCache; Type cachedType = bindingValueCache.BindingValueType; object cachedValue = bindingValueCache.ValueAsBindingValueType; if (stateType != cachedType) { // the cached type isn't the current type - refresh the cache cachedValue = referenceValue; // in case of failure TypeConverter typeConverter = DefaultValueConverter.GetConverter(stateType); if (typeConverter != null && typeConverter.CanConvertFrom(typeof(String))) { // PreSharp uses message numbers that the C# compiler doesn't know about. // Disable the C# complaints, per the PreSharp documentation. #pragma warning disable 1634, 1691 // PreSharp complains about catching NullReference (and other) exceptions. // It doesn't recognize that IsCritical[Application]Exception() handles these correctly. #pragma warning disable 56500 try { cachedValue = typeConverter.ConvertFromString(null, System.Windows.Markup.TypeConverterHelper.InvariantEnglishUS, referenceString); } catch (Exception ex) { if (CriticalExceptions.IsCriticalApplicationException(ex)) throw; // if the conversion failed, just use the unconverted value } catch // non CLS compliant exception { // if the conversion failed, just use the unconverted value } #pragma warning restore 56500 #pragma warning restore 1634, 1691 } // cache the converted value bindingValueCache = new BindingValueCache(stateType, cachedValue); BindingValueCache = bindingValueCache; } referenceValue = cachedValue; } return Match(state, referenceValue); }
internal TriggerCondition(DependencyProperty dp, LogicalOp logicalOp, object value, string sourceName) { Property = dp; Binding = null; LogicalOp = logicalOp; Value = value; SourceName = sourceName; SourceChildIndex = 0; BindingValueCache = new BindingValueCache(null, null); }