Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Linq.Expression in generic method #232

Open
igor-tkachev opened this issue Jan 6, 2012 · 4 comments
Open

Linq.Expression in generic method #232

igor-tkachev opened this issue Jan 6, 2012 · 4 comments
Assignees

Comments

@igor-tkachev
Copy link
Member

The following code:

    module TestGen[TFrom,TTo]
    {
        public GetExpr() : System.Linq.Expressions.Expression[System.Func[TFrom,TTo]]
        {
            Nemerle.Linq.ToExpression((o : TFrom) => System.Convert.ChangeType(o, typeof(TTo)) :> TTo)
        }
    }

    public Test() : void
    {
        TestGen[int,string].GetExpr().Compile()(1)
    }

results at run-time

System.ArgumentException : Expression of type 'System.Int32' cannot be used for parameter of type 'System.Object' of method 'System.Object ChangeType(System.Object, System.Type)'
@igor-tkachev
Copy link
Member Author

The following change works fine:

    System.Convert.ChangeType(o : __object__, typeof(TTo))

@ghost ghost assigned VladD2 Jan 7, 2012
@VladD2
Copy link
Member

VladD2 commented Jan 7, 2012

Эта проблема возникает только с object?

@VladD2
Copy link
Member

VladD2 commented Jan 7, 2012

Вставил проверку на object и аргументы отличного от него типа. Если это не то что нужно, просьба сообщить.

@VladD2 VladD2 closed this as completed in 14de5f1 Jan 7, 2012
@igor-tkachev
Copy link
Member Author

This code works fine:

    (ToExpression((o : TFrom) => o : object) : object) :> Expression[Func[TFrom,TTo]]

The following does not:

    (ToExpression(fun(o : TFrom) : object { o }) : object) :> Expression[Func[TFrom,TTo]]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants