public static Func <string, T1, TResult> Compile <T1, TResult>(Action <StdfFile> stdfFileInit, Expression <Func <StdfFile, T1, TResult> > query) { var rnf = ExpressionInspector.Inspect(query); var compiled = query.Compile(); RecordConverterFactory factory = null; return((path, t1) => { StdfFile stdf; if (factory == null) { stdf = new StdfFile(new StdfFileStreamManager(path), false, rnf) { EnableCaching = false }; factory = stdf.ConverterFactory; } else { stdf = new StdfFile(new StdfFileStreamManager(path), factory) { EnableCaching = false }; } if (stdfFileInit != null) { stdfFileInit(stdf); } return compiled(stdf, t1); }); }
/// <summary> /// Compiles an argument-less query, allowing you to do some initialization on the <see cref="StdfFile"/> /// object before the query runs. This allows you to set options or add filters or seek algorithms. /// </summary> /// <typeparam name="TResult">The type of the result (in most cases, this can be inferred)</typeparam> /// <param name="stdfFileInit">An action that will initialize the <see cref="StdfFile"/>.</param> /// <param name="query">The expression tree representing the query.</param> /// <returns>The results of the query</returns> public static Func <string, TResult> Compile <TResult>(Action <StdfFile> stdfFileInit, Expression <Func <StdfFile, TResult> > query) { var rnf = ExpressionInspector.Inspect(query); var compiled = query.Compile(); RecordConverterFactory factory = null; return((path) => { StdfFile stdf; if (factory == null) { stdf = new StdfFile(new StdfFileStreamManager(path), false, rnf) { IndexingStrategy = new NonCachingStrategy() }; factory = stdf.ConverterFactory; } else { stdf = new StdfFile(new StdfFileStreamManager(path), factory) { IndexingStrategy = new NonCachingStrategy() }; } stdfFileInit?.Invoke(stdf); return compiled(stdf); }); }
public IMemberAccessor CreateFor <TObject, TProperty>(Expression <Func <TObject, TProperty> > expression) { MemberExpression memberExpression = new ExpressionInspector <TObject>().GetMemberExpression(expression); MemberInfo member = memberExpression.Member; //We have a field. Return a simple field accessor if (member is FieldInfo) { return(new FieldAccessor((FieldInfo)member)); } //We have a property. If the property is read write, we can simply return a property accessor var propertyInfo = member as PropertyInfo; if (propertyInfo == null) { throw new MemberAccessException(member); } if (propertyInfo.CanWrite) { return(new ReadWritePropertyAccessor(propertyInfo)); } //we have a readonly property. Try to find a backing field corresponding to the property var fieldInfos = typeof(TObject).AllFields().Where(mi => privateMemberMatchesNamingConventions(mi, member.Name)).ToList(); //we found one, return the property accessor if (fieldInfos.Count == 1) { return(new ReadOnlyPropertyWithPrivateFieldAccesor(propertyInfo, fieldInfos[0])); } //last try: Find a property that might be read only and return it var propertyInfos = typeof(TObject).AllProperties().Where(prop => prop.Name == member.Name).ToList(); if (propertyInfos.Count == 1) { propertyInfo = propertyInfos[0]; } if (propertyInfo.CanWrite) { return(new ReadWritePropertyAccessor(propertyInfo)); } return(new ReadOnlyPropertyAccessor(propertyInfo)); }
protected override void Context() { sut = new ExpressionInspector <TypeOfParameter>(); }