Maya .NET API: wpfexamples

I have been exploring the C# plugin examples for Maya 2014. Now I am looking at the example in the “wpfexamples” folder called “DAGExplorer”. When I run the command, the window pops up fine; but when I click the “Search DAG” button, I get an error like the following:

Search Condition is invalid:
pk0qoeo1.0.cs(20,82) : error CS1594: Delegate 'Script.QueryFunc' has some invalid arguments
pk0qoeo1.0.cs(20,91) : error CS1503: Argument 1: cannot convert from 'Autodesk.Maya.OpenMaya.MItDag' to 'Autodesk.Maya.OpenMaya.MDagPath'
pk0qoeo1.0.cs(22,48) : error CS0266: Cannot implicitly convert type 'System.Collections.Generic.IEnumerable<Autodesk.Maya.OpenMaya.MItDag>' to 'System.Collections.Generic.IEnumerable<Autodesk.Maya.OpenMaya.MDagPath>'. An explicit conversion exists (are you missing a cast?)

Here is the code it is having a problem with:

string MyScript = @"using System;
                    using System.Collections.Generic;
                    using System.Linq;
                    using System.Text;

                    using Autodesk.Maya.Runtime;
                    using Autodesk.Maya.OpenMaya;
                    using Autodesk.Maya;
            
                    public class Script
                    {
                        delegate bool QueryFunc(MDagPath dp);

                        public System.Collections.Generic.IEnumerable<MDagPath> Main()
                        {
                            var dag = new MCDag();

                            QueryFunc myLambda = (dagpath) => " + textBox1.Text.Trim() + @";

                            var elements = from dagpath in dag where myLambda(dagpath) select dagpath;  // Here it doesn't like "myLambda(dagpath)"

                            return elements;  // Here it doesn't like "elements"
                        }
                    }";

(This code is a string that gets executed later. When it is executed, the error appears.) Does anyone know what the problem is? I am not really familiar with this LINQ query syntax, so I am not sure what the “from-where-select” line is returning. Also, I am not familiar with the MCDag class.

I just figured it out. The line:

var elements = from dagpath in dag where myLambda(dagpath) select dagpath;

needs to be changed to:

var elements = from dagpath in dag[B].DagPaths[/B] where myLambda(dagpath) select dagpath;

In that line “dag” is of type MCDag. The default enumerator for MCDag gives you an MItDag for each item. So where the line says “from dagpath in dag”, “dagpath” was expecting to be of type MItDag. But reading the rest of the code, it seems an MDagPath is what we really want. The type of the item in the iteration can be changed by using one MCDag’s other options.

Here is some pseudo-code showing the other options:

var dag = new MCDag();

from dagpath in dag ...   // dagpath will be of type MItDag
from dagpath in dag.DagPaths ...  // dagpath will be of type MDagPath
from dagpath in dag.Objects ...  // dagpath will be of type MObject