/// <summary> /// Create a Matrix by parsing the file. The MatrixFactory may try many different parsers to get a result. /// </summary> /// <param name="filename">The name of the file containing the matrix information.</param> /// <param name="missingValue">The special value that represents missing in the created matrix.</param> /// <param name="parallelOptions">A ParallelOptions instance that configures the multithreaded behavior of this operation.</param> /// <param name="result">The matrix created.</param> /// <returns>true, if some parse succeeds; otherwise, false</returns> public bool TryParse(string filename, TValue missingValue, ParallelOptions parallelOptions, out Matrix<TRowKey, TColKey, TValue> result) { result = null; TextWriter origErrorWriter = Console.Error; MFErrorWriter mfErrorWriter = new MFErrorWriter(); Console.SetError(mfErrorWriter); if (_registeredParsers.Count == 0 && _builtInParsers.Count == 0) Console.Error.WriteLine("No matching parsers found"); foreach (TryParseMatrixDelegate<TRowKey, TColKey, TValue> ParseFunc in _registeredParsers) { mfErrorWriter.SetLabel(ParseFunc.ToString()); if (ParseFunc(filename, missingValue, parallelOptions, out result)) { ErrorMessages = mfErrorWriter.ToString(); Console.SetError(origErrorWriter); return true; } } object[] methodParams4 = new object[] { filename, missingValue, parallelOptions, result }; object[] methodParams3 = new object[] { filename, missingValue, result }; foreach (MethodInfo ParseFuncMemberInfo in _builtInParsers) { mfErrorWriter.SetLabel(ParseFuncMemberInfo.DeclaringType.Name + "." + ParseFuncMemberInfo.Name); int argCount = ParseFuncMemberInfo.GetParameters().Length; Helper.CheckCondition(argCount == 3 || argCount == 4, Properties.Resource.ExpectedArgCountOfThreeOrFour); object[] methodParams = (3 == argCount) ? methodParams3 : methodParams4; bool success = (bool)ParseFuncMemberInfo.Invoke(null, methodParams); if (success) { result = (Matrix<TRowKey, TColKey, TValue>)methodParams[argCount - 1];//!!!const ErrorMessages = mfErrorWriter.ToString(); Console.SetError(origErrorWriter); return true; } } ErrorMessages = mfErrorWriter.ToString(); Console.SetError(origErrorWriter); return false; }