Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7191961
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T19:50:19+00:00 2026-05-28T19:50:19+00:00

I have an ICollection with objects: private ObservableCollection<ViewItem> items; The viewItems have no properties.

  • 0

I have an ICollection with objects:

private ObservableCollection<ViewItem> items;

The viewItems have no properties. The data will be accessed via an index with

public  object this[int index] {
   get{ .... }
   set {....}
}

I have a geneal class for filtering. The linq with properies will work fine. I use (the important code only):

Queryable = CreateQueryable((IEnumerable<object>)mItemsSource.SourceCollection, ItemType);
mQuery = Queryable.Where(filterString).Cast<object>();
ilteredCollection = mQuery.ToList();

with:

private static IQueryable CreateQueryable(IEnumerable<object> collection, Type itemType)
{
        if (itemType == null) return null;

        var queryableList = collection.AsQueryable();
        return queryableList.Provider.CreateQuery(
            Expression.Call(
                typeof(Queryable), "Cast",
                new Type[] { itemType },
                queryableList.Expression));
}

So I can use a filter string like: Id>10 or Name="abc"
where Id and Name are property names.

But I have also Object in another collection which only have access via index. so I have an where string like:

[0]>10 or [1]="abc"

I didn’t find any solution. The only hint I could find is to use:

new(it([idx] as Type)

where idx is element index and Type is a type of this element

e.g.

[0]>10 --> new(it[0] as object)>10

But than I get the error:

{“Operator ‘=’ incompatible with operand types ‘DynamicClass1’ and ‘Int32′”}

Useing a string in my filter like:

new(it[0] as object)>"10" 

than the error is:

{“Operator ‘=’ incompatible with operand types ‘DynamicClass1’ and ‘string'”}

So – how can I solve this problem. Because this is a general Filterclass I also don’t know the type. So in the as statement I can only use object or something like this.

I hope anyone can help me. Perhaps the dynamic keyword of C# 4.0 will help??
BTW a workaround will be to impement a wrapper in each class with indexer, but this will be a lot of stupid work. And that is something a real programmer don’t like ;). I am sure there is a solution!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T19:50:20+00:00Added an answer on May 28, 2026 at 7:50 pm

    Your usage of new keyword is wrong.
    It does not cast object (nor does as).

    Keyword new is used to create new object of anonymous class with the specified properties.
    Thus new(it[idx] as Type) will create new object with property Type having the value it[idx]. It is equivalent to C#’s: new { Type = this[idx] }.

    As I have already pointed out in Dynamic linq: Is there a way to access object data by index?, you need to cast it in the following manner: Int32(it[0]) > 10 for your pseudo-query [0] > 10.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In my application, I have three collection objects which store data. The data which
C#: I have a collection of objects . T has 2 properties. Property A
I have an data transfer object called Report . These report objects are held
In my code I have the two following collections: private ObservableCollection<Job> listOfJobs1 = new
I have a collection of custom data objects that I display in DataGrid. The
in my Silverlight 4 application, I have an ObservableCollection which consists of objects of
I have a viewModel named CarsList with main property public ObservableCollection<Car> Cars { get
I have a collection private ObservableCollection<ImageData> imageDataList = new ObservableCollection<ImageData>(); where ImageData is a
I have a object of type ICollection<string> . What is the best way to
I have two Collection objects, I want to associate each object of these two

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.