Revert "Remove FormObject.cs and FormObjectCollection.cs (#19383)" (#19387)

This reverts commit 190c99a416.
This commit is contained in:
CarloToso
2023-03-22 22:22:29 +05:00
committed by GitHub
parent 18f0c5ad4b
commit 098be48033
3 changed files with 95 additions and 0 deletions
@@ -1157,6 +1157,9 @@ namespace Microsoft.PowerShell.Commands
switch (content)
{
case FormObject form:
SetRequestContent(request, form.Fields);
break;
case IDictionary dictionary when request.Method != HttpMethod.Get:
SetRequestContent(request, dictionary);
break;
@@ -0,0 +1,55 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
using System.Collections.Generic;
namespace Microsoft.PowerShell.Commands
{
/// <summary>
/// FormObject used in HtmlWebResponseObject.
/// </summary>
public class FormObject
{
/// <summary>
/// Gets the Id property.
/// </summary>
public string Id { get; }
/// <summary>
/// Gets the Method property.
/// </summary>
public string Method { get; }
/// <summary>
/// Gets the Action property.
/// </summary>
public string Action { get; }
/// <summary>
/// Gets the Fields property.
/// </summary>
public Dictionary<string, string> Fields { get; }
/// <summary>
/// Initializes a new instance of the <see cref="FormObject"/> class.
/// </summary>
/// <param name="id"></param>
/// <param name="method"></param>
/// <param name="action"></param>
public FormObject(string id, string method, string action)
{
Id = id;
Method = method;
Action = action;
Fields = new Dictionary<string, string>();
}
internal void AddField(string key, string value)
{
if (key is not null && !Fields.TryGetValue(key, out string test))
{
Fields[key] = value;
}
}
}
}
@@ -0,0 +1,37 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
using System;
using System.Collections.ObjectModel;
namespace Microsoft.PowerShell.Commands
{
/// <summary>
/// FormObjectCollection used in HtmlWebResponseObject.
/// </summary>
public class FormObjectCollection : Collection<FormObject>
{
/// <summary>
/// Gets the FormObject from the key.
/// </summary>
/// <param name="key"></param>
/// <returns></returns>
public FormObject this[string key]
{
get
{
FormObject form = null;
foreach (FormObject f in this)
{
if (string.Equals(key, f.Id, StringComparison.OrdinalIgnoreCase))
{
form = f;
break;
}
}
return form;
}
}
}
}