There are a lot of benefits for using lambda expression to capture property or method of some class like the following code.
void CaptureProperty<T, TProperty> (Func<T, TProperty> exp)
{
// some logic to keep exp variable
}
// So you can use below code to call above method.
CaptureProperty<string, int>(x => x.Length);
However, the...
Hi I have been looking at certain tutorials on sharparchitecture and trying to no avail (the online convertors don't seem to be able to do this):
private Action<AutoMappingExpressions> GetSetup()
{
return c =>
{
c.FindIdentity = type => type.Name == "Id";
};
}
private Action<IConventionFinder> GetConventions()
{
ret...
Say I have a class with 2 properties
class TestClass
{
public int propertyOne {get;set;}
public List<int> propertyTwo {get; private set;}
public TestClass()
{
propertyTwo = new List<int>();
}
}
Using linq, I am trying to create a list of TestClass as follows:
var results = from x in MyOtherClass
...
I am trying to do this on a method which is basically a mapper - maps old categories List to a new List. The OldCategory has fewer properties.
return categories = from c in oldCategories select new Category
{
CategoryName = c.CategoryName,
Id = c.CategoryId,
Teams = CombineTeam(c.Team, coreTeam)
};
Why can't I use CombineTeam met...
I'm generating an interface to concrete implementation copier. A later step will be to determine if I can easily add varying behaviors depending on the copy type requested (straight copy, or try, or try-catch-addToValidationDictionary). This is the main one I need/am working on is the try-catch-addToValidationDictionary. It would be love...
I need to programatically check whether a nested property/function result in a lambda expression is null or not. The problem is that the null could be in any of the nested subproperties.
Example. Function is:
public static bool HasNull<T, Y>(this T someType, Expression<Func<T, Y>> input)
{
//Determine if expression has a nul...
Hello,
I'm trying to work with lambda's in C++ after having used them a great deal in C#. I currently have a boost tuple (this is the really simplified version).
typedef shared_ptr<Foo> (*StringFooCreator)(std::string, int, bool)
typedef tuple<StringFooCreator> FooTuple
I then load a function in the global namespace into my FooTuple...
Ok, i have a need to be able to keep track of value type objects which are properties on another object, which cannot be done without having those properties implement an IObservable interface or similar. Then i thought of closures and the famous example from Jon Skeet and how that prints out 9 (or 10) a bunch of times and not an ascendi...
How can I do an update in Linq
My code is
List<Cart> objNewCartItems = (List<Cart>)Session["CartItems"];
if ((objNewCartItems != null) && (objNewCartItems.Count > 0))
{
for (int i = 0; i < dgShoppingCart.Rows.Count; i++)
{
Cart c = new Cart();
...
What do you think of the following table mapping style for domain entities?
class Customer {
public string Name;
}
class Order
{
public TotallyContainedIn<Customer> Parent { get { return null; } }
public HasReferenceTo<Person> SalesPerson { get { return new HasReferenceTo<Person>(0,1); } }
}
//...
[TableOf(typeof(Customer))]
clas...
I have a lambda expression that gets results from a Dictionary.
var sortedDict = (from entry in dctMetrics
orderby entry.Value descending
select entry);
The expression pulls back the pairs I need, I can see them in the IDE's debug mode.
How do I convert this back a dictionary of the same type as ...
I have an entity set that contains two DateTime properties. I want to order the set by the minimum value of the two properties. How can I do this with a lambda expression.
...
I'm stuck trying to map this sql:
select dt.Id, dateadd(dd,datediff(dd,0,dt.CreatedAt),0) as Ct, DId, Amount
from dt, ad
where dt.ADId = ad.ADId and ad.Id = '13B29A01-8BF0-4EC9-80CA-089BA341E93D'
order by dateadd(dd,datediff(dd,0,dt.CreatedAt),0) desc, DId asc
Into an Entity Framework-compatible lambda query expression. I'd appreciate...
I have a list like:
List<String> test = new List<String> {"Luke", "Leia"};
I would like to use something like this:
test.Select(s => String.Format("Hello {0}", s));
but it doesn't adjust the names in the list. Is there a way to use lambda expressions to alter these? Or is it because strings are immutable that this doesn't work?
...
Hi,
I'm new to Ruby and am trying to pass a sort_by lambda to a format method, like this:
sort_by_methods = [ lambda {|l, r| compare_by_gender_then_last_name(l, r)},
lambda {|l, r| compare_by_something_else(l, r)},
lambda {|l, r| compare_by_another(l, r)}]
formatted_output = ""
sort_by_methods...
I have a delegate defined in my code:
public bool delegate CutoffDateDelegate( out DateTime cutoffDate );
I would like to create delegate and initialize with a lambda or anonymous function, but neither of these compiled.
CutoffDateDelegate del1 = dt => { dt = DateTime.Now; return true; }
CutoffDateDelegate del2 = delegate( out dt ) {...
Several C# questions on StackOverflow ask how to make anonymous delegates/lambdas with out or ref parameters. See, for example:
Calling a method with ref or out parameters from an anonymous method
Write a lambda or anonymous function that accepts an out parameter
To do so, you just need to specify the type of the parameter, as in:
p...
Hi!
I wanna do something like this:
List<string> list = new List<string>();
... put some data in it ...
list.CallActionForEachMatch(x=>x.StartsWith("a"), ()=> Console.WriteLine(x + " matches!"););
Syntax: CallActionForEachMatch(Criteria, Action)
How is this possible? :)
...
Is is possible to scan a function provided as a lamba expression to figure out the nature of the function at runtime?
Example:
class Program
{
static void Main(string[] args)
{
Examples example = new Examples(x => x ^ 2 + 2);
}
}
public class Examples
{
public Examples(Func<dynamic, dynamic> func)
{
...
def funct():
x = 4
action = (lambda n: x ** n)
return action
x = funct()
print(x(2)) # prints 16
... I don't quite understand why 2 is assigned to n automatically?
...