public static IVariableCollection SetupVariables(IParameterSet parameters, IVariableConfig variableConfig) { IVariableCollection variables = Root(); Dictionary <string, VariableCollection> collections = new Dictionary <string, VariableCollection>(); foreach (KeyValuePair <string, string> source in variableConfig.Sources) { VariableCollection variablesForSource = null; string format = source.Value; switch (source.Key) { case "environment": variablesForSource = VariableCollection.Environment(format); if (variableConfig.FallbackFormat != null) { variablesForSource = VariableCollection.Environment(variablesForSource, variableConfig.FallbackFormat); } break; case "user": variablesForSource = VariableCollectionFromParameters(parameters, format); if (variableConfig.FallbackFormat != null) { VariableCollection variablesFallback = VariableCollectionFromParameters(parameters, variableConfig.FallbackFormat); variablesFallback.Parent = variablesForSource; variablesForSource = variablesFallback; } break; } collections[source.Key] = variablesForSource; } foreach (string order in variableConfig.Order) { IVariableCollection current = collections[order.ToString()]; IVariableCollection tmp = current; while (tmp.Parent != null) { tmp = tmp.Parent; } tmp.Parent = variables; variables = current; } return(variables); }
private static IVariableCollection SetupVariables(IEngineEnvironmentSettings environmentSettings, IParameterSet parameters, IVariableConfig variableConfig) { IVariableCollection variables = VariableCollection.SetupVariables(environmentSettings, parameters, variableConfig); foreach (Parameter param in parameters.ParameterDefinitions.OfType <Parameter>()) { // Add choice values to variables - to allow them to be recognizable unquoted if (param.EnableQuotelessLiterals && param.IsChoice()) { foreach (string choiceKey in param.Choices.Keys) { if ( variables.TryGetValue(choiceKey, out object existingValueObj) && existingValueObj is string existingValue && !string.Equals(choiceKey, existingValue, StringComparison.CurrentCulture) ) { throw new InvalidOperationException(string.Format(LocalizableStrings.RunnableProjectGenerator_CannotAddImplicitChoice, choiceKey, existingValue)); } variables[choiceKey] = choiceKey; } } } return(variables); }