public (bool success, string possibleError) Init(object parameter, int seed) { if (parameter == null) { this.currentMode = GenerateMode.Random; } else if (parameter.GetType() == typeof(string)) { var parsedParams = ParameterParser.GetParameterDictionary((string)parameter); if (ParameterParser.ContainsKey(parsedParams, randomAliases)) { this.currentMode = GenerateMode.Random; } } else { string error = ErrorMessages.UnsupportedParameterType(LongName, "Init", parameter.GetType()); return(success : false, possibleError : error); } // Set values based on chosen GenerateMode if (this.currentMode == GenerateMode.Random) { this.rng = new Random(seed); this.GenerateFilename(); } return(success : true, possibleError : ""); }
public (bool success, string possibleError) Init(object parameter, int seed) { if (parameter == null) { // If no parameters are given, then go with defaults } else if (parameter.GetType() == typeof(string)) { var parsedParams = ParameterParser.GetParameterDictionary((string)parameter); if (ParameterParser.ContainsKey(parsedParams, startAliases)) { string potentialStartValue = ParameterParser.GetValueWithKeys(parsedParams, startAliases); if (!long.TryParse(potentialStartValue, out this.currentValue)) { return(success : false, possibleError : $"{potentialStartValue} is not a number!"); } } if (ParameterParser.ContainsKey(parsedParams, stepAliases)) { string potentialStepValue = ParameterParser.GetValueWithKeys(parsedParams, stepAliases); if (!long.TryParse(potentialStepValue, out this.step)) { return(success : false, possibleError : $"{potentialStepValue} is not a number!"); } } } else { return(success : false, possibleError : ErrorMessages.UnsupportedParameterType(LongName, "Init", parameter.GetType())); } return(success : true, possibleError : ""); }
public (bool success, string possibleError) Init(object parameter, int seed) { if (parameter == null) { return(success : false, possibleError : ErrorMessages.UnsupportedNullParameter(LongName, "Init")); } (bool isArray, Type elementType) = ParameterParser.PrecheckPossibleArray(parameter); if (isArray) { IEnumerable enumerable = parameter as IEnumerable; object[] parameters = enumerable.Cast <object>().ToArray(); if (parameters.Length != 2) { return(success : false, ErrorMessages.ParameterArrayNotEnoughElements(LongName, "Init", 2, parameters.Length)); } this.replaceForTrue = parameters[0]; this.replaceForFalse = parameters[1]; } else if (parameter.GetType() == typeof(string)) { string[] splitted = ((string)parameter).Split(defaultValueSeparator); if (splitted.Length != 2) { return(success : false, $"{LongName} Init string needs to have {defaultValueSeparator} for separating true and false values!"); } this.replaceForTrue = splitted[0]; this.replaceForFalse = splitted[1]; } else { return(success : false, ErrorMessages.UnsupportedParameterType(LongName, "Init", parameter.GetType())); } return(success : true, possibleError : ""); }