var s = File.ReadAllLines(@"E:\test.csv");
var nomsChamp = s.First().Split(';');
var l = from ligne in s.Skip(1) select ligne.Split(';');
//ajouté dans la méthode FindPropertyOrField de la classe ExpressionParser
if (type.IsArray)
{
foreach (MethodInfo m in type.GetMethods())
if (m.Name == "Get")
return m;
}
return null;
//ajouté dans la méthode ParseMemberAccess de la classe ExpressionParser
if (member is MethodInfo && type.IsArray)
int valeur = int.Parse(id.Split(new string[] { "[", "]" }, StringSplitOptions.None)[1]);
//Ajout à l'arbre d'expression
return Expression.Call(instance, (MethodInfo)member, Expression.Constant(valeur));
var t = l.Select("new( it[0] as Versement, it[2] as Periodicite, it[15] as Taux, it[5] as Police)");
var t = l.Select("new( Convert.ToDecimal(it[0]) as Versement, it[2] as Periodicite, it[15] as Taux, it[5] as Police)");
var t = l.Where("Convert.ToDecimal(it[0]) > 10000")
.Select("new( Convert.ToDecimal(it[0]) as Versement, it[2] as Periodicite, it[15] as Taux, it[5] as Police)");
public class ContratENT
public int Periodicite {get; set;}
public decimal Versement {get; set;}
public decimal Taux {get; set;}
public string Police { get; set; }
.Select(@"new( Convert.ToDecimal(it[0]) as Versement, Convert.ToInt32(it[2]) as Periodicite,
Convert.ToDecimal(it[15]) as Taux, it[5] as Police)",typeof(ContratENT));
public static IEnumerable<object> Select<T>(this IEnumerable<T> source, string selector,
Type objectToFill, params object[] values)
if (source == null) throw new ArgumentNullException("source");
if (selector == null) throw new ArgumentNullException("selector");
return Select((IQueryable)source.AsQueryable(), selector, objectToFill, values).Cast<object>();
public static IQueryable Select(this IQueryable source, string selector, Type objectToFill, params object[] values)
LambdaExpression lambda = DynamicExpression.ParseLambdaObjectToFill(new ParameterExpression[]
{ Expression.Parameter(source.ElementType, "") }, objectToFill, selector, values);
return source.Provider.CreateQuery(
Expression.Call(
typeof(Queryable), "Select",
new Type[] { source.ElementType, lambda.Body.Type },
source.Expression, Expression.Quote(lambda)));
public static LambdaExpression ParseLambdaObjectToFill(ParameterExpression[] parameters,
Type objectToFill, string expression, params object[] values)
ExpressionParser parser = new ExpressionParser(parameters, expression, values, objectToFill);
return Expression.Lambda(parser.Parse(null), parameters);
public ExpressionParser(ParameterExpression[] parameters, string expression, object[] values) {
if (expression == null) throw new ArgumentNullException("expression");
if (keywords == null) keywords = CreateKeywords();
symbols = new Dictionary<string, object>(StringComparer.OrdinalIgnoreCase);
literals = new Dictionary<Expression, string>();
if (parameters != null) ProcessParameters(parameters);
if (values != null) ProcessValues(values);
text = expression;
textLen = text.Length;
SetTextPos(0);
NextToken();
Type _objectToFill;
public ExpressionParser(ParameterExpression[] parameters, string expression, object[] values, Type objectToFill)
_objectToFill = objectToFill;
Parser(parameters, expression, values);
public ExpressionParser(ParameterExpression[] parameters, string expression, object[] values)
void Parser(ParameterExpression[] parameters, string expression, object[] values)
Type type = DynamicExpression.CreateClass(properties);
Type type = _objectToFill as Type;
if (_objectToFill == null)
type = DynamicExpression.CreateClass(properties);
it[5].Substring(it[5].Length -2,2) as Version
static readonly Type[] predefinedTypes = {
typeof(Object),
typeof(Boolean),
typeof(Char),
typeof(String),
typeof(SByte),
typeof(Byte),
typeof(Int16),
typeof(UInt16),
typeof(Int32),
typeof(UInt32),
typeof(Int64),
typeof(UInt64),
typeof(Single),
typeof(Double),
typeof(Decimal),
typeof(DateTime),
typeof(TimeSpan),
typeof(Guid),
typeof(Math),
typeof(Convert)
};
typeof(Convert),
typeof(Fx) //Ajout de Fx
//Exemples de fonctions simples pour la démonstration :
static class Fx
public static string Left(string chaine, int pos)
return chaine.Substring(0, pos);
public static string Right(string chaine, int pos)
return chaine.Substring(chaine.Length - pos, pos);
Fx.Right(it[5],2) as Version