In answering this question
http://stackoverflow.com/questions/808725/why-does-a-linq-castt-operation-fail-when-i-have-an-implicit-cast-defined
I have found that there are a number of ways to implicitly cast between objects.
Consider the following two classes:
public class Class1
{
public int Test1;
}
public class Class2
{
pu...
I've just installed VS2008 and have run into a problem that I'm sure can be solved with either lambda's or delegates (or a combination!).
private string ReadData(TcpClient s, string terminator)
{
// Reads a byte steam into a string builder until either data is unavailable or the terminator has not been reached
va...
I would like to pass a parameter defined in the XAML (View) of my application to the ViewModel class by using the RelayCommand. I followed Josh Smith's excellent article on MVVM and have implemented the following.
XAML Code
<Button
Command="{Binding Path=ACommandWithAParameter}"
CommandParameter="Orange"
...
How would I do this (C#) in F#
public class MyClass
{
void Render(TextWriter textWriter)
{
Tag(() =>
{
textWriter.WriteLine("line 1");
textWriter.WriteLine("line 2");
});
Tag(value =>
{
textWriter.WriteLine...
I would like to build an Expression that would equate to expected...
Expression<Func<ReferencedEntity, bool>> expected = (ReferencedEntity referencedEntity) => foreignKeys.Contains(referencedEntity.Id);
Expression<Func<ReferencedEntity, bool>> actual;
foreignKeys type is a List<object>
Here is what I have so far and I think it would ...
I recently need to build a Expression tree so I wrote a Test method like so...
/// <summary>
///
/// </summary>
[TestMethod()]
[DeploymentItem("WATrust.Shared.Infrastructure.dll")]
public void BuildForeignKeysContainsPredicate_shoud_build_contains_predicate()
{
RemoteEntityRefLoader_Accessor<ReferencedEntity> target = CreateRe...
This is a simplified version of the original problem.
I have a class called Person:
public class Person {
public string Name { get; set; }
public int Age { get; set; }
public int Weight { get; set; }
public DateTime FavouriteDay { get; set; }
}
...and lets say an instance:
var bob = new Person(){ Name = "Bob",
...
Given a Lambda Expression:
Define(Expression<Func<T, int>> property)
and used like:
Define(x => x.Collection.Count)
What is the best method of getting the value of Count? Is there an easy way with the Expression Tree or should I use reflection to parse the tree to get the PropertyInfo and GetValue()?
...
hey guys.
Firstly I can't get my head around the functional / Lambda aspects of .NET 3.5. I use these features everyday in LINQ, but my problem is understanding the implementation, and what they really mean (Lambda? System.Func? etc etc)
With this in mind, how would the following be achieved:
As an example, I'd like to have an Extensi...
Hi,
I'd like to use the expression-based syntax for ASP.NET MVC's Html.BeginForm (e.g. Html.BeginForm<HomeController>(a => a.ActionForSubmit();) for the increased testability it gives you.
I'm unclear about what to do where the corresponding action has parameters. For example, I have a login action that is HTTP POST only and has two pa...
Hello,
I am using create_function to run some user-code at server end. I am looking for any of these two:
Is there a way to sanitize the code passed to it to prevent something harmful from executing?
Alternately, is there a way to specify this code to be run in a sandboxed environment so that the user can't play around with anything ...
I have a vector of pointers that are not owned by the container. How do I use algorithms on the targets of the pointers. I tried to use boost's ptr_vector, but it tries to delete the pointers when it goes out of scope.
Here is some code that needs to work:
vector<int*> myValues;
// ... myValues is populated
bool consistent = count(my...
I have abstract class for each Business Object in my app (BO)
Also have parent (generic) collection to store all BOs (named BOC - Business Object Collection)
What I would like to archive is created universal method iniside BOC similar to:
public T GetBusinessObject (lambda_criteria)
So I could call this method similar to:
Employe...
I have two tables Customers, Orders
Customers
CustomerID
FName
LName
Orders
OrderId
CustomerID
OrderDate
I want to make a linq statement that can join these two tables and get
FName, LName, Count of orders for each customer
...
I can get the current selected row in this way:
private void DataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e){
//Cells[0] cause CheckBoxColumn is in that index (first column)
DataGridViewCheckBoxCell temp = (DataGridViewCheckBoxCell)dgv.Rows[e.RowIndex].Cells[0];
}
So, Now I want to get all of the rows that...
I am still learning some of the features of C# 3.0 and want to know if the following can be reduced to a lambda expression.
var SomeObject = Combo.EditValue;
var ObjectProperty = SomeObject.Property;
To obtain ObjectProperty from the combo.editvalue in a single line?
Also, if you can provide me with any good references to Lambda expr...
What is the difference between the two piecees of code below. will there be any issues using the second one.
Scenario 1
private void Log(Exception e)
{
ThreadPool.QueueUserWorkItem(new WaitCallback(Log), e);
}
private void Log(object obj)
{
Exception e = (Exception)obj;
Logger.Log(e);
}
Scenario 2
private void Log(Excep...
Why does this attempt at creating a list of curried functions not work?
def p(x, num):
print x, num
def test():
a = []
for i in range(10):
a.append(lambda x: p (i, x))
return a
>>> myList = test()
>>> test[0]('test')
9 test
>>> test[5]('test')
9 test
>>> test[9]('test')
9 test
What's going on here?
A functi...
string x;
foreach(var item in collection)
{
x += item+",";
}
can I write something like this with lambdas?
...
Hi all,
How would I go about using an Expression Tree to dynamically create a predicate that looks something like...
(p.Length== 5) && (p.SomeOtherProperty == "hello")
So that I can stick the predicate into a lambda expression like so...
q.Where(myDynamicExpression)...
I just need to be pointed in the right direction.
Thanks.
Ed...