Home All Groups Group Topic Archive Search About

LINQ Where extension override

Author
29 Oct 2007 8:46 PM
Jason Dentler
I have created a two classes to wrap some COM interfaces. I don't have any
control, influence, source-code, etc. for these COM interfaces.

The first class, Media, is an individual data item and exposes some
read-only properties of the underlying COM interface with return values of
basic data types like string, int, datetime, etc. It's all straight-forward
stuff.

The other, MediaCollection, wraps a COM interface that basically acts as a
collection of the first COM interface. The wrapper for this COM interface
implements an IEnumerable of the first.

I have a simple LINQ query:

Var Q = From M in Media Where M.Name="Media Name 1" Select M

To work around a huge performance problem in the underlying COM components,
I need to use some custom "Where" logic instead of baked-in LINQ to Objects
Where operator.

I've decorated the properties of the Media class with custom attributes that
tell me the underlying COM interface property they expose. I need to be able
to recognize when I'm performing an equality (or inequality, eventually)
comparison between one of these decorated properties and a constant value.
When I detect that scenario, I want to use a different mechanism on the
underlying COM interfaces to get my Where result.

I've already tried creating a function:
Public Shared Function Where(Source As IEnumerable(Of Media), Predicate As
Func(Of Media, Boolean)) AS IEnumerable(Of Media)

That didn't work because Predicate points to a method like __lambda$__
something or other... I assume this is an anonymous method. I was hoping to
somehow get to the expression tree and find an equality operation with my
decorated property and a constant for arguments.

I can read C# if you prefer, but I think in VB for the same reason I think
in English - it was my first language. Thanks in advance for your help!!!!

AddThis Social Bookmark Button