8000 Revert "Remove FormObject.cs and FormObjectCollection.cs (#19383)" (#… · PowerShell/PowerShell@098be48 · GitHub
[go: up one dir, main page]

Skip to content

Commit 098be48

Browse files
authored
Revert "Remove FormObject.cs and FormObjectCollection.cs (#19383)" (#19387)
This reverts commit 190c99a.
1 parent 18f0c5a commit 098be48

File tree

3 files changed

+95
-0
lines changed

3 files changed

+95
-0
lines changed

src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/Common/WebRequestPSCmdlet.Common.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1157,6 +1157,9 @@ internal virtual void FillRequestStream(HttpRequestMessage request)
11571157

11581158
switch (content)
11591159
{
1160+
case FormObject form:
1161+
SetRequestContent(request, form.Fields);
1162+
break;
11601163
case IDictionary dictionary when request.Method != HttpMethod.Get:
11611164
SetRequestContent(request, dictionary);
11621165
break;
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
// Copyright (c) Microsoft Corporation.
2+
// Licensed under the MIT License.
3+
4+
using System.Collections.Generic;
5+
6+
namespace Microsoft.PowerShell.Commands
7+
{
8+
/// <summary>
9+
/// FormObject used in HtmlWebResponseObject.
10+
/// </summary>
11+
public class FormObject
12+
{
13+
/// <summary>
14+
/// Gets the Id property.
15+
/// </summary>
16+
public string Id { get; }
17+
18+
/// <summary>
19+
/// Gets the Method property.
20+
/// </summary>
21+
public string Method { get; }
22+
23+
/// <summary>
24+
/// Gets the Action property.
25+
/// </summary>
26+
public string Action { get; }
27+
28+
/// <summary>
29+
/// Gets the Fields property.
30+
/// </summary>
31+
public Dictionary<string, string> Fields { get; }
32+
33+
/// <summary>
34+
/// Initializes a new instance of the <see cref="FormObject"/> class.
35+
/// </summary>
36+
/// <param name="id"></param>
37+
/// <param name="method"></param>
38+
/// <param name="action"></param>
39+
public FormObject(string id, string method, string action)
40+
{
41+
Id = id;
42+
Method = method;
43+
Action = action;
44+
Fields = new Dictionary<string, string>();
45+
}
46+
47+
internal void AddField(string key, string value)
48+
{
49+
if (key is not null && !Fields.TryGetValue(key, out string test))
50+
{
51+
Fields[key] = value;
52+
}
53+
}
54+
}
55+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// Copyright (c) Microsoft Corporation.
2+
// Licensed under the MIT License.
3+
4+
using System;
5+
using System.Collections.ObjectModel;
6+
7+
namespace Microsoft.PowerShell.Commands
8+
{
9+
/// <summary>
10+
/// FormObjectCollection used in HtmlWebResponseObject.
11+
/// </summary>
12+
public class FormObjectCollection : Collection<FormObject>
13+
{
14+
/// <summary>
15+
/// Gets the FormObject from the key.
16+
/// </summary>
17+
/// <param name="key"></param>
18+
/// <returns></returns>
19+
public FormObject this[string key]
20+
{
21+
get
22+
{
23+
FormObject form = null;
24+
foreach (FormObject f in this)
25+
{
26+
if (string.Equals(key, f.Id, StringComparison.OrdinalIgnoreCase))
27+
{
28+
form = f;
29+
break;
30+
}
31+
}
32+
33+
return form;
34+
}
35+
}
36+
}
37+
}

0 commit comments

Comments
 (0)
0