T ==, object.Equals() .
To do the conversion, you can use Convert.ChangeType():
case CriteriaOperator.Equal:
return x => object.Equals(
Convert.ChangeType(x.Attribute(criterion.PropertyName).Value, typeof(T)),
criterion.PropertyValue);
The problem is that in some cases, XML uses different rules for conversions (for example, it Double.PositiveInfinityappears like INF).
To solve this problem, you can use a classXmlConvert that is used by internal conversion operators. In addition, it does not have a βgeneralβ method, such as Convert.ChangeType(), so you will need to create your own:
private static object Convert(string value, Type targetType)
{
if (targetType == typeof(double))
return XmlConvert.ToDouble(value);
β¦
throw new ArgumentException();
}
β¦
case CriteriaOperator.Equal:
return x => object.Equals(
Convert(x.Attribute(criterion.PropertyName).Value, typeof(T)),
criterion.PropertyValue);
svick source
share