public override IEnumerable <Type> GetRequestsCore(Type type) { FactoryResult result = ResultFor(type); try { var str = (string)_mining.CreateType(type); result.FactoryCode = str; } catch (StaticCompilerWarning ex) { result.Ex = ex; } if (typeof(IFactory).IsAssignableFrom(type)) { // get IFactory<T> var iface = type.GetInterfaces().FirstOrDefault(x => x.IsGenericType && x.GetGenericTypeDefinition() == typeof(IFactory <,>)); if (iface != null) { var args = iface.GetGenericArguments(); var targetRequest = args[0]; var targetResult = args[1]; result = ResultFor(targetResult); result.FactoryFactoryCode = string.Format("c => c.Get<{0}>().Create()", type.CSharpTypeIdentifier()); } } return(Enumerable.Empty <Type>()); // requests from miner }
FactoryResult ResultFor(Type type) { FactoryResult result; if (!_result.TryGetValue(type, out result)) { _result[type] = result = new FactoryResult(); } return(result); }
/* * https://en.wikipedia.org/wiki/Shunting-yard_algorithm * http://wcipeg.com/wiki/Shunting_yard_algorithm#Unary_operators * http://tutplusplus.blogspot.com/2011/12/c-tutorial-arithmetic-expression.html * http://tutplusplus.blogspot.com/2010/12/c-tutorial-equation-calculator.html */ /// <summary> /// Using Shunting yard algorithm /// </summary> /// <param name="equationString"></param> /// <param name="varFinder"></param> /// <returns></returns> private Queue <IEquationMember> CreateReversePolishNotationQueue(string equationString, IList <string> parameterNames) { if (string.IsNullOrEmpty(equationString)) { throw new ArgumentNullException(nameof(equationString)); } Stack <IPrecedenceMember> precedenceStack = new Stack <IPrecedenceMember>(); Stack <Function> functionStack = new Stack <Function>(); Queue <IEquationMember> outputQueue = new Queue <IEquationMember>(); IEquationMember previousToken = null; int totalNumbers = 0; int totalBinaryOpts = 0; while (equationString.Length > 0 && !string.IsNullOrWhiteSpace(equationString)) { int startingLength = equationString.Length; FactoryResult result = EquationMemberFactory.CreateEquationMember(equationString, previousToken, parameterNames); previousToken = result?.Member; equationString = result?.RemainingString; if (previousToken is Number || previousToken is Variable) { totalNumbers++; } if (previousToken is BinaryOperator) { totalBinaryOpts++; } previousToken = HandleToken(precedenceStack, functionStack, outputQueue, previousToken); // if we didn't do anything in a loop, then there are unsupported strings if (equationString == null || startingLength == equationString.Length) { throw new ArgumentException(); } } if (totalNumbers != totalBinaryOpts + 1 && totalBinaryOpts > 0) { throw new ArgumentException("Binary Operators must have at 2 numbers to interact with"); } while (precedenceStack.Count > 0) { if (precedenceStack.Peek() is Bracket) { throw new ArgumentException(); } outputQueue.Enqueue(precedenceStack.Pop()); } EquationArguments = (IReadOnlyList <string>)parameterNames; return(outputQueue); }
/// <summary> /// Converts the string into a sequence of tokens. /// </summary> /// <param name="function">The string that contains the functions and operators.</param> /// <returns>The sequence of tokens.</returns> /// <seealso cref="IToken"/> /// <exception cref="ArgumentNullException">Throws when the <paramref name="function"/> parameter is null or empty.</exception> /// <exception cref="TokenizeException">Throws when <paramref name="function"/> has the not supported symbol.</exception> public IEnumerable <IToken> Tokenize(string function) { if (string.IsNullOrWhiteSpace(function)) { throw new ArgumentNullException(nameof(function), Resource.NotSpecifiedFunction); } if (!IsBalanced(function)) { throw new TokenizeException(Resource.NotBalanced); } var tokens = new List <IToken>(); var readOnlyTokensList = new ReadOnlyCollection <IToken>(tokens); for (var i = 0; i < function.Length;) { FactoryResult result = null; foreach (var factory in factories) { result = factory.CreateToken(function, i, readOnlyTokensList); if (result == null) { continue; } i += result.ProcessedLength; if (result.Token != null) { tokens.Add(result.Token); } break; } if (result == null) { throw new TokenizeException(string.Format(Resource.NotSupportedSymbol, function)); } } foreach (var postProcessor in postProcessors) { postProcessor.Process(tokens); } return(tokens); }
internal ApplicationInitializationFailedEventArgs(string displayName, string executableName, FactoryResult result) { DisplayName = displayName; ExecutableName = executableName; Result = result; }