Expression Convert(IType expectedType, Expression argument)
{
if (IsStandaloneMethodReference(argument))
{
if (IsCallableType(expectedType))
{
ICallableType argumentType = (ICallableType)GetExpressionType(argument);
if (argumentType.GetSignature() !=
((ICallableType)expectedType).GetSignature())
{
return Adapt((ICallableType)expectedType,
CreateDelegate(GetConcreteExpressionType(argument), argument));
}
return CreateDelegate(expectedType, argument);
}
else
{
return CreateDelegate(GetConcreteExpressionType(argument), argument);
}
}
else
{
if (IsCallableType(expectedType))
{
IType argumentType = GetExpressionType(argument);
if (Null.Default != argumentType &&
expectedType != argumentType)
{
return Adapt((ICallableType)expectedType, argument);
}
}
}
return null;
}