public ClassDefinition GetClassDefinition(string classID, Func <string, Exception> missingClassDefinitionExceptionFactory) { ArgumentUtility.CheckNotNullOrEmpty("classID", classID); ArgumentUtility.CheckNotNull("missingClassDefinitionExceptionFactory", missingClassDefinitionExceptionFactory); var classDefinition = _classDefinitions.GetValueOrDefault(classID); if (classDefinition == null) { throw missingClassDefinitionExceptionFactory(classID); } return(classDefinition); }
public ClassDefinition GetTypeDefinition(Type classType, Func <Type, Exception> missingTypeDefinitionExceptionFactory) { ArgumentUtility.CheckNotNull("classType", classType); ArgumentUtility.CheckNotNull("missingTypeDefinitionExceptionFactory", missingTypeDefinitionExceptionFactory); var classDefinition = _typeDefinitions.GetValueOrDefault(classType); if (classDefinition == null) { throw missingTypeDefinitionExceptionFactory(classType); } return(classDefinition); }
public static TValue GetValueOrDefault <TKey, TValue>( this ReadOnlyDictionary <TKey, TValue> dictionary, TKey key ) where TKey : notnull { // Validate parameters. if (dictionary == null) { throw new ArgumentNullException(nameof(dictionary)); } if (key == null) { throw new ArgumentNullException(nameof(key)); } // Call the overload. return(dictionary.GetValueOrDefault(key, default)); }
private static SpecificAnalysisResult AnalyzeScore( ScoreUtilityType?scoreUtilityType, PageSpeedStrategy?pageSpeedStrategy, string inputFilePath, string outputFilePath) { if (!scoreUtilityType.HasValue) { throw new ArgumentNullException(nameof(scoreUtilityType)); } if (scoreUtilityType.Value != ScoreUtilityType.PageSpeed) { throw scoreUtilityType.Value.CreateEnumValueNotImplementedException(); } if (!pageSpeedStrategy.HasValue) { throw new ArgumentNullException(nameof(pageSpeedStrategy)); } var strategyParameter = PageSpeedStrategyToToolParameterMap.GetValueOrDefault(pageSpeedStrategy.Value); if (strategyParameter.IsNullOrWhiteSpace()) { throw new NotSupportedException( $@"The strategy '{pageSpeedStrategy.Value.GetQualifiedName()}' is not mapped."); } var arguments = $@"-input_file ""{inputFilePath}"" -output_file ""{outputFilePath }"" -output_format formatted_json -strategy ""{strategyParameter}"""; var startInfo = new ProcessStartInfo(PageSpeedExecutablePath, arguments) { CreateNoWindow = true, ErrorDialog = false, UseShellExecute = false, WindowStyle = ProcessWindowStyle.Hidden }; using (var process = Process.Start(startInfo)) { if (process == null) { throw new InvalidOperationException( $@"Unable to run the required tool ""{PageSpeedExecutablePath}""."); } var waitResult = process.WaitForExit((int)PageSpeedRunTimeout.TotalMilliseconds); if (!waitResult) { process.KillNoThrow(); throw new InvalidOperationException( $@"The tool ""{PageSpeedExecutablePath}"" has not exited after {PageSpeedRunTimeout}."); } var exitCode = process.ExitCode; if (exitCode != 0) { throw new InvalidOperationException( $@"The tool ""{PageSpeedExecutablePath}"" has exited with the code {exitCode}."); } } var pageSpeedOutput = PageSpeedOutput.DeserializeFromFile(outputFilePath); return(pageSpeedOutput); }
public static string AsDdl(DbType t) => _ddlMap.GetValueOrDefault(t) ?? throw new Exception($"Database type not supported: {Enum.GetName(typeof(DbType), t)}");
public static DbType?Map(Type t) => _map.GetValueOrDefault(t, null);
/// <summary> /// Gets the <see cref="IRuntimeConfiguration"/> instance for the specified REST resource type. /// </summary> /// <param name="type">The REST resource Type.</param> public TRuntimeConfiguration GetRuntimeConfigurationForType(Type type) { return(_runtimeConfigurations.GetValueOrDefault(type)); }