protected virtual string CompileCondition(AbstractCondition clause) { var name = clause.GetType().Name; name = name.Substring(0, name.IndexOf("Condition")); var methodName = "Compile" + name + "Condition"; var clauseType = clause.GetType(); MethodInfo methodInfo = this.GetType().GetRuntimeMethods().Where(x => x.Name == methodName).FirstOrDefault(); if (methodInfo == null) { throw new Exception($"Failed to locate a compiler for {name}."); } if (clauseType.IsConstructedGenericType && methodInfo.GetGenericArguments().Any()) { methodInfo = methodInfo.MakeGenericMethod(clauseType.GenericTypeArguments); } var result = methodInfo.Invoke(this, new object[] { clause }); return(result as string); }
protected virtual string CompileCondition(SqlResult ctx, AbstractCondition clause) { var clauseType = clause.GetType(); var name = clauseType.Name; name = name.Substring(0, name.IndexOf("Condition")); var methodName = "Compile" + name + "Condition"; var methodInfo = FindCompilerMethodInfo(clauseType, methodName); try { var result = methodInfo.Invoke(this, new object[] { ctx, clause }); return(result as string); } catch (Exception ex) { throw new Exception($"Failed to invoke '{methodName}'", ex); } }
protected virtual string CompileCondition(AbstractCondition clause) { var name = clause.GetType().Name; name = name.Substring(0, name.IndexOf("Condition")); var methodName = "Compile" + name + "Condition"; return(dynamicCompile(methodName, clause)); }