2

Possibly really simple question, but I'm new to IronPython. I would like use IronPython to crawl an entity I pass to it, but when I try to use any extension methods, it, as sort of expected, blows up. How do I traverse my POCOs in IronPython?

delegate bool EvaluateRule(MyEntity entity);
//Keep in mind this is just to test, no actual value provided
string expression = @"entity.Flags.FirstOrDefault() == null";
MyEntity entity = new MyEntity();
PythonEngine engine = new PythonEngine();
EvaluateRule rule = engine.CreateLambda<EvaluateRule>(expression);
bool result = rule.Invoke(entity);

I get the following: 'EntityCollection[MyEntity]' object has no attribute 'FirstOrDefault'

Thanks in advance!

2
  • "it, as sort of expected, blows up"? What does this mean? 1) provide the smallest piece of code that shows the error. 2) provide the error. Our ESP isn't all that good. We can't guess what you've done or what "blows up" means. Commented Dec 2, 2010 at 18:54
  • Sorry, @S.Lott, was trying to be ambiguous as I was hoping for ideas without my implementation in mind. Commented Dec 2, 2010 at 19:14

1 Answer 1

3

You can call the extension methods as regular static methods:

string expression = @"Enumerable.FirstOrDefault(entity.Flags) == null";
Sign up to request clarification or add additional context in comments.

4 Comments

If I do that, I get "name 'Enumerable' not defined"
It's in System.Linq. You may need to reference that.
Sorry, I'm completely new to IronPython, how do I reference a namespace in my example above for IP to use?
With import

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.