private static bool Compare(object leftOperand, ComparisonConditionType operatorType, object rightOperand) { if (leftOperand != null && rightOperand != null) { rightOperand = TypeConverterHelper.Convert(rightOperand.ToString(), leftOperand.GetType().FullName); } IComparable comparable = leftOperand as IComparable; IComparable comparable2 = rightOperand as IComparable; if (comparable != null && comparable2 != null) { return(DataTriggerBehavior.EvaluateComparable(comparable, operatorType, comparable2)); } switch (operatorType) { case ComparisonConditionType.Equal: return(object.Equals(leftOperand, rightOperand)); case ComparisonConditionType.NotEqual: return(!object.Equals(leftOperand, rightOperand)); case ComparisonConditionType.LessThan: case ComparisonConditionType.LessThanOrEqual: case ComparisonConditionType.GreaterThan: case ComparisonConditionType.GreaterThanOrEqual: if (comparable == null && comparable2 == null) { throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, "InvalidOperands", new object[] { (leftOperand != null) ? leftOperand.GetType().Name : "null", (rightOperand != null) ? rightOperand.GetType().Name : "null", operatorType.ToString() })); } if (comparable == null) { throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, "InvalidLeftOperand", new object[] { (leftOperand != null) ? leftOperand.GetType().Name : "null", operatorType.ToString() })); } throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, "InvalidRightOperand", new object[] { (rightOperand != null) ? rightOperand.GetType().Name : "null", operatorType.ToString() })); default: return(false); } }
public static object Convert(string value, string destinationTypeFullName) { if (string.IsNullOrEmpty(destinationTypeFullName)) { throw new ArgumentNullException("destinationTypeFullName"); } string scope = TypeConverterHelper.GetScope(destinationTypeFullName); if (string.Equals(scope, "System", StringComparison.Ordinal)) { if (string.Equals(destinationTypeFullName, typeof(string).FullName, StringComparison.Ordinal)) { return(value); } if (string.Equals(destinationTypeFullName, typeof(bool).FullName, StringComparison.Ordinal)) { return(bool.Parse(value)); } if (string.Equals(destinationTypeFullName, typeof(int).FullName, StringComparison.Ordinal)) { return(int.Parse(value, CultureInfo.InvariantCulture)); } if (string.Equals(destinationTypeFullName, typeof(double).FullName, StringComparison.Ordinal)) { return(double.Parse(value, CultureInfo.CurrentCulture)); } } string type = TypeConverterHelper.GetType(destinationTypeFullName); string text = string.Format(CultureInfo.InvariantCulture, "<ContentControl xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation' xmlns:c='using:{0}'><c:{1}>{2}</c:{1}></ContentControl>", new object[] { scope, type, value }); ContentControl contentControl = XamlReader.Load(text) as ContentControl; if (contentControl != null) { return(contentControl.Content); } return(null); }