10000 Revert "Remove FormObject.cs and FormObjectCollection.cs" by CarloToso · Pull Request #19387 · PowerShell/PowerShell · GitHub
[go: up one dir, main page]

Skip to content

Revert "Remove FormObject.cs and FormObjectCollection.cs" #19387

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1157,6 +1157,9 @@ internal virtual void FillRequestStream(HttpRequestMessage request)

switch (content)
{
case FormObject form:
SetRequestContent(request, form.Fields);
break;
case IDictionary dictionary when request.Method != HttpMethod.Get:
SetRequestContent(request, dictionary);
break;
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
}
}
}
}
3A4E
Original file line number Diff line number Diff line change
@@ -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;
}
}
}
}
0