"Fossies" - the Fresh Open Source Software Archive

Member "selenium-selenium-4.8.1/dotnet/src/webdriver/DevTools/CommandResponseTypeMap.cs" (17 Feb 2023, 2632 Bytes) of package /linux/www/selenium-selenium-4.8.1.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C# source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "CommandResponseTypeMap.cs" see the Fossies "Dox" file reference documentation.

    1 // <copyright file="CommandResponseTypeMap.cs" company="WebDriver Committers">
    2 // Licensed to the Software Freedom Conservancy (SFC) under one
    3 // or more contributor license agreements. See the NOTICE file
    4 // distributed with this work for additional information
    5 // regarding copyright ownership. The SFC licenses this file
    6 // to you under the Apache License, Version 2.0 (the "License");
    7 // you may not use this file except in compliance with the License.
    8 // You may obtain a copy of the License at
    9 //
   10 //     http://www.apache.org/licenses/LICENSE-2.0
   11 //
   12 // Unless required by applicable law or agreed to in writing, software
   13 // distributed under the License is distributed on an "AS IS" BASIS,
   14 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   15 // See the License for the specific language governing permissions and
   16 // limitations under the License.
   17 // </copyright>
   18 
   19 using System;
   20 using System.Collections.Generic;
   21 
   22 namespace OpenQA.Selenium.DevTools
   23 {
   24     /// <summary>
   25     /// Class that maps a DevTools Protocol command's type to the type of object returned by the command.
   26     /// </summary>
   27     public class CommandResponseTypeMap
   28     {
   29         private readonly IDictionary<Type, Type> commandResponseTypeDictionary = new Dictionary<Type, Type>();
   30 
   31         /// <summary>
   32         /// Adds mapping to a response type for a specified command type.
   33         /// </summary>
   34         /// <param name="commandSettingsType">The type of command to add the mapping for.</param>
   35         /// <param name="commandResponseType">The type of response object corresponding to the command.</param>
   36         public void AddCommandResponseType(Type commandSettingsType, Type commandResponseType)
   37         {
   38             if (!commandResponseTypeDictionary.ContainsKey(commandSettingsType))
   39             {
   40                 commandResponseTypeDictionary.Add(commandSettingsType, commandResponseType);
   41             }
   42         }
   43 
   44         /// <summary>
   45         /// Gets the command response type corresponding to the specified command type.
   46         /// </summary>
   47         /// <typeparam name="T">The type of command for which to retrieve the response type.</typeparam>
   48         /// <param name="commandResponseType">The returned response type.</param>
   49         /// <returns><see langword="true"/> if the specified command type has a mapped response type; otherwise, <see langword="false"/>.</returns>
   50         public bool TryGetCommandResponseType<T>(out Type commandResponseType)
   51             where T : ICommand
   52         {
   53             return commandResponseTypeDictionary.TryGetValue(typeof(T), out commandResponseType);
   54         }
   55     }
   56 }