Issue with processing properties of type 'byte'.

0 views
Skip to first unread message

tmulgrew

unread,
Dec 15, 2009, 10:52:21 PM12/15/09
to NhLambdaExtensionsUsers
Very cool project by the way.

I've come across an issue with processing expressions that compare
byte properties to byte values.
For some reason the BinaryExpression evaluates the right hand side to
an integer, which then cannot be converted to a byte, leading to a
"Cannot convert '10' to Byte" exception in
ExpressionProcessor.ConvertType.

This is the simplest example I can think of:

public class TestClass
{
public byte Value { get; set; }
}

[TestFixture]
public class MyTest
{
[Test]
public void Test()
{
TestClass c1 = new TestClass { Value = 10 };
ExpressionProcessor.ProcessExpression<TestClass>(c =>
c.Value == c1.Value);
}
}

I fixed it by dropping this into the ConvertType method:
if (value is int && type == typeof(byte))
return value;

But it feels very hardwired to my particular case. Perhaps there's a
better way to determine that integer and byte values (or other similar
numeric types) can be compared to each other..?

Richard Brown (gmail)

unread,
Dec 28, 2009, 11:54:09 AM12/28/09
to NhLambdaExtensionsUsers
Hi Tom,

I appear to have missed this, and just found it again this morning while
clearing out some spam from the group!

I've raised Issue 13 for this:
http://code.google.com/p/nhlambdaextensions/issues/detail?id=13

I've released version 1.0.10.0 with the fix:
http://code.google.com/p/nhlambdaextensions/downloads/list

Sorry for the delay, and thanks for your patience.

Cheers,
Richard

--------------------------------------------------
From: "tmulgrew" <t...@ams.co.nz>
Sent: Wednesday, December 16, 2009 3:52 AM
To: "NhLambdaExtensionsUsers" <nhlambdaext...@googlegroups.com>
Subject: Issue with processing properties of type 'byte'.

Reply all
Reply to author
Forward
0 new messages