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

  • SEARCH
  • Home
  • 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 7038011
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T01:37:04+00:00 2026-05-28T01:37:04+00:00

I have been experimenting with Dynamic LINQ as a solution to a scenario, whereby

  • 0

I have been experimenting with Dynamic LINQ as a solution to a scenario, whereby I need to allow a user to select a series of files based upon a “tag” that is assigned to it. E.g.

File A - tagged as "a",
File B - tagged as "b",
File C - tagged as "c",
File D - tagged as "d" and "a"

So if I want to find all files tagged as “a”, I would type:

tag = "a"

I would get file a and file d. But I could also type

tag = "a" OR tag = "b"

So I would retrieve file a, b and d

This is just an example by the way!

So, given this scenario, I am able to achieve this by using the following code:

List<FileMeta.Filetag> tags = fetchAllTags(file); //this fetches the tags from the file and places them in a list
            if (tags != null) //just in case
            {
                //declare the type of parameter we are looking for - in this case a "tag"
                var p = Expression.Parameter(typeof(string), "Tag");
                //setup the lambda parser to accept the param type, and use the expression
                var z = System.Linq.Dynamic.DynamicExpression.ParseLambda(new[] { p }, null, equation);

                //for each tag in this file
                foreach (FileMeta.Filetag t in tags)
                {
                    //if it hasn't been found yet
                    if (!bFound)
                    {
                        bFound = (bool)z.Compile().DynamicInvoke(t.tag);
                    }
                }
            }

So here I am retrieving the tags from the file, and enumerating them to check to see if they fulfil the equation entered. This is all OK, works fine.

What I have a problem with, is the following scenario.

The “tags” for these files are actually stored in the alternate stream info for a file, along with other information that is effectively “meta” information about the file. A file may have 1 or more pieces of meta info. Because of this, everything is serialised to a single stream with the file as XML data from typed objects – you may have noticed that the List in the above code is of type FileMeta.Filetag. All of the objects inherit from a base object called Filemetabaseobject.

So what I can’t get my head around, is if I want to look at a different type of object, e.g. a Filedate object, at the same time as the Filetag object, is it possible with Dynamic LINQ to pass, say, each object in of it’s base type (Filemetabaseobject) and somehow do some casting?

I ask, because in a perfect scenario, I would like to be able to query this meta info as, e.g. tag = “a” AND date = “01/01/2012” for example, but the problem I have is that the “tag” would be in a Filetag object, and the “date” would be in a Filedate object obviously as properties: e.g. in a simplistic scenario:

public class Filemetabaseobject
{

}
public class Filetag : Filemetabaseobject
    {
        public string tag { get; set; }
    }
public class Filedate : Filemetabaseobject
{
    public string date { get; set; }
}

Is there a solution to this?

Thanks in advance!

Sorry, I have added, the user can type pretty much any type of query, e.g (tag=”a” AND tag=”b”) OR tag=”c” or they may then type (tag=”a” AND tag=”b” AND tag=”c”) for example.

  • 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-28T01:37:05+00:00Added an answer on May 28, 2026 at 1:37 am

    With the help of the suggestion made by sq33G above regarding having abstract classes that expose a value property, I have been able to solve this.

    Basically as all types (tags included) inherit from Filemetabaseobject, having an overrideable property called “value” that is set to whatever you want to expose for searching, you can from the inherited object set the get value to retrieve whatever you want that object to be found for.

    Then using the following implementation of the Dynamic LINQ ParseLambda method, you can pass the inherited object type in as it’s base class equivalent, and it is still able to consult any type of inherited object, based upon being able to see this overridden property:

    //If we pass in type of filemetabaseobject, because all file metas inherit from it, and we have exposed an overridde property of "value" to all objects, we can just consult that on all types (where lequation is the string representing the equation):
    var z = System.Linq.Dynamic.DynamicExpression.ParseLambda(typeof(FileMeta.Filemetabaseobject), typeof(bool), lequation);
    //invoke the query - true will be returned if the query is valid against the property(ies) exposes
    bFound = (bool)z.Compile().DynamicInvoke(t); //where t is my filetag that I'm querying against, but could be anything that inherits from filemetabaseobject
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been experimenting with LINQ to XML and have run across a very
I have been experimenting with a simple XOR-based text obfuscation algorithm. Supposedly, when the
I have been experimenting with woopra.com A web analytics tool. Which requires a piece
I have been experimenting with WPF and rendering strict XAML markup in a web
I have been experimenting with Lambda expressions in Oxygene. Very simple recursive lambda expression
I have been experimenting with a lot of web development apps like Drupal, Moodle,
I have been experimenting with writing applications that use a local SQL Database to
I have been experimenting with sending messages from two .NET Windows Forms applications using
I have been experimenting with TMask in Delphi 2010 and it seems to work
I'm working on building a tree structure in MySQL and have been experimenting with

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.