lambda

List<T>.SelectMany(), Linq and lambda help

Hi there I have a class. public class MedicalRequest { private int id private IList<MedicalDays> Days private string MedicalUser ... } and another public class MedicalDays { private int id; private DateTime? day private MedicalRequest request ... } I'm using nhibernate to return a list of all t...

linq and contains

i have func public PageOfList<ConsaltQuestion> Filter(int? type, int pageId, EntityCollection<ConsaltCost> ConsaltRoles) { // return _dataContext.ConsaltQuestion.Where((o => o.Type == type || type == null) && (o=>o.Paid == paid)); return (from i in _dataContext.ConsaltQuestion where ((i.Type == type || type == null) &...

Using lambda expressions and linq

So I've just started working with linq as well as using lambda expressions. I've run into a small hiccup while trying to get some data that I want. This method should return a list of all projects that are open or in progress from Jira Here's the code public static List<string> getOpenIssuesListByProject(string _projectName) {...

How do you cast a string representing a Lamda Expression to an System.LINQ.Expressions.Expression

I have a class with a property of type Expression> and I want to set this property with a string like "m => m.A + m.B = m.C". If I write this as new Type(){propertyName = m => m.A + m.B = m.C} sets this property to a true return. I want to be able to do this: string s = "m => m.A + m.B = m.C"; Type<T> t = new Type<T>(){propertyName =...

lambda+for_each+delete on STL containers

I'm trying to get a simple delete every pointer in my vector/list/... function written with an ultra cool lambda function. Mind you, I don't know c**p about those things :) template <typename T> void delete_clear(T const& cont) { for_each(T.begin(), T.end(), [](???){ ???->delete() } ); } I have no clue what to fill in for the ???'...

Examining a lambda expression at runtime in C#

I have a method Get on a type MyType1 accepting a Func<MyType2, bool> as a parameter. An example of its use: mytype1Instance.Get(x => x.Guid == guid)); I would like create a stub implementation of the method Get that examines the incoming lambda expression and determines what the value of guid is. Clearly the lambda could be "anythin...

Making a Lambda Expression Target a Delegate regardless of signature

Ok, maybe the title isn't the most descriptive thing in the world, but this problem is killing me. What I'm trying to do is create an ActionLinkFor helper method, like so: public ActionResult Index() { // Does Stuff } public ActionResult SomeAction(int param1) { // Does Stuff } These are two action methods. Action methods can h...

Lambda Contains in SimpleRepository.Find

In SubSonic 3.04's SimpleRepository, I cannot seem to perform a Contains operation within a lambda expression. Here's a trivial example: SimpleRepository repo = new SimpleRepository("ConnectionString"); List<int> userIds = new List<int>(); userIds.Add(1); userIds.Add(3); List<User> users = repo.Find<User>(x => userIds.Contains(x.Id))...

Convert this Linq query from query syntax to lambda expression

I'm not sure I like linq query syntax...its just not my preference. But I don't know what this query would look like using lambda expressions, can someone help? from securityRoles in user.SecurityRoles from permissions in securityRoles.Permissions where permissions.SecurableEntity.Name == "Unit" && permissions.PermissionType.Name == "R...

VB.NET logical expression evaluator

I need to test a logical expression held in a string to see if it evaluate to TRUE or FALSE.(the strig is built dynamically) For example the resulting string may contain "'dog'<'cat' OR (1>4 AND 4<6)". There are no variables in the string, it will logically evaluate. It will only contain simple operators = > < >< >= <= and AND , OR and O...

What is the cleanest way to use anonymous functions?

I've started to use Javascript a lot more, and as a result I am writing things complex enough that organization is becoming a concern. However, this question applies to any language that allows you to nest functions. Essentially, when should you use an anonymous function over a named global or inner function? At first I thought it was t...

LINQ: How to Use RemoveAll without using For loop with Array

I currently have a log object I'd like to remove objects from, based on a LINQ query. I would like to remove all records in the log if the sum of the versions within a program are greater than 60. Currently I'm pretty confident that this'll work, but it seems kludgy: for (int index = 0; index < 4; index++) { Lo...

Lambda Expressions and Memory Management

How do the Lambda Expressions / Closures in C++0x complicate the memory management in C++? Why do some people say that closures have no place in languages with manual memory management? Is their claim valid and if yes, what are the reasons behind it? ...

Closure and nested lambdas in C++0x

Using C++0x, how do I capture a variable when I have a lambda within a lambda? For example: std::vector<int> c1; int v = 10; <--- I want to capture this variable std::for_each( c1.begin(), c1.end(), [v](int num) <--- This is fine... { std::vector<int> c2; std::for_each( c2.begin(), ...

using lambda instead of let in scheme

Hey, In SICP 1.2.1 there is a function that makes a rational number, as follow: (define (make-rat n d) (let ((g (gcd n d))) (cons (/ n g) (/ d g)))) I'm just curious how you can implement the same thing using lambda instead of let, without calling GCD twice. I couldn't figure it out myself. ...

varargs in lambda functions in Python

Is it possible a lambda function to have variable number of arguments? For example, I want to write a metaclass, which creates a method for every method of some other class and this newly created method returns the opposite value of the original method and has the same number of arguments. And I want to do this with lambda function. How...

Lambda expressions - set the value of one property in a collection of objects based on the value of another property in the collection

I'm new to lambda expressions and looking to leverage the syntax to set the value of one property in a collection based on another value in a collection Typically I would do a loop: class Item { public string Name { get; set; } public string Value { get; set; } } void Run() { Item item1 = new Item { Name = "name1" }; I...

check that int array contains !=0 value using lambda

hey, I have two-dimension array List<List<int>> boardArray How can I enumerate throw this array to check that it contains other value than 0 ? I think about boardArray.Contains and ForEach ,cause it return bool value but I don't have too much experience with lambda expression :/ Please help :) ...

LinqToXML why does my object go out of scope? Also should I be doing a group by?

Hello All, I have an IEnumerable<someClass>. I need to transform it into XML. There is a property called 'ZoneId'. I need to write some XML based on this property, then I need some decendent elements that provide data relevant to the ZoneId. I know I need some type of grouping. Here's what I have attempted thus far without much success. ...

Linq and Lamba Expressions - while walking a selected list perform an action

Hey, I'm very new to linq and lamba expressions. I'm trying to walk a collection, and when I find an item that meets some criteria I'd like to add that to another separate collection. My linq to walk the collection looks like this (this works fine): From i as MyCustomItem In MyCustomItemCollection Where i.Type = "SomeType" Select i I...