private bool parsePredicatItem(ref Type predicateSource, ref MethodInfo method, ref List <string> errors) { PrdicatMethodInfo predicat = new PrdicatMethodInfo(); predicat.name = method.Name.Replace(Consts.predicateMethodPrefix, ""); predicat.method = method; ParameterInfo[] parameters = method.GetParameters(); foreach (ParameterInfo p in parameters) { predicat.argsNames.Add(p.Name); predicat.arsTypes.Add(p.ParameterType); } MethodInfo predicatDataSource; string predicatDataSourceName; for (int i = 0; i < predicat.argsNames.Count; i++) { var name = predicat.argsNames[i]; predicatDataSourceName = Consts.argumentMethidPrefix + name + "Of" + predicat.name; if ((predicatDataSource = predicateSource.GetMethod(predicatDataSourceName)) == null) { errors.Add("Can not found method with name " + predicatDataSourceName + "that will be used as " + "data source for predicat witn name " + predicat.name + " to argument with name " + name); return(false); } Type t = predicat.arsTypes[i]; Type targetType = typeof(IEnumerable <>).MakeGenericType(t); Type sourceType = predicatDataSource.ReturnType; bool isInstance = targetType.IsInstanceOfType(Activator.CreateInstance(sourceType)); if (!isInstance) { errors.Add("method " + predicatDataSourceName + " must habe return tupe that will be instance of" + "IEnumerator<" + t.FullName + ">"); return(false); } predicat.argsValueGenerator.Add(name, predicatDataSource); } prediactsList.Add(predicat); return(true); }
public List <KeyValuePair <List <object>, bool> > getAllDataForTruth(String methodSignature) { List <List <object> > result = new List <List <object> >(); List <KeyValuePair <List <object>, bool> > functionResult = new List <KeyValuePair <List <object>, bool> >(); PrdicatMethodInfo currentPredicat = null; foreach (var p in prediactsList) { if (p.ToString() == methodSignature) { currentPredicat = p; break; } } if (currentPredicat == null) { return(functionResult); } object predicatObject = results.CompiledAssembly.CreateInstance(Consts.rootClassName); List <IEnumerable <object> > sourceData = new List <IEnumerable <object> >(); foreach (var n in currentPredicat.argsNames) { MethodInfo method = currentPredicat.argsValueGenerator[n]; object methodResult = method.Invoke(predicatObject, new object[] { }); sourceData.Add((IEnumerable <object>)methodResult); } result = getAllCombination(sourceData); foreach (var i in result) { MethodInfo method = currentPredicat.method; bool methodResult = (bool)method.Invoke(predicatObject, i.ToArray()); functionResult.Add(new KeyValuePair <List <object>, bool>(i, methodResult)); } return(functionResult); }