Skip to content

Instantly share code, notes, and snippets.

@TheFlyingCorpse
Last active March 29, 2017 19:49
Show Gist options
  • Save TheFlyingCorpse/ff1352c105a3ae9b82fd4da8f88baf7f to your computer and use it in GitHub Desktop.
Save TheFlyingCorpse/ff1352c105a3ae9b82fd4da8f88baf7f to your computer and use it in GitHub Desktop.
....
#region Method
/// <summary>
/// gets or sets the Method property
/// </summary>
[Parameter(parametersetname="StandardMethod")]
[Parameter(parametersetname="StandardMethodNoProxy")]
public virtual WebRequestMethod Method
{
get { return _method; }
set { _method = value; }
}
private WebRequestMethod _method = WebRequestMethod.Default;
/// <summary>
/// gets or sets the CustomMethod property
/// </summary>
[Parameter(parametersetname="CustomMethod")]
[Parameter(parametersetname="CustomMethodNoProxy")]
[Alias("CM")]
[ValidateNotNullOrEmpty]
public virtual string CustomMethod
{
get { return _customMethod; }
set { _customMethod = value; }
}
private string _customMethod;
#endregion
#region NoProxy
/// <summary>
/// gets or sets the NoProxy property
/// </summary>
[Parameter(mandatory=true,parametersetname="CustomMethodNoProxy")]
[Parameter(mandatory=true,parametersetname="StandardMethodNoProxy")]
public virtual SwitchParameter NoProxy { get; set; }
#endregion
#region Proxy
/// <summary>
/// gets or sets the Proxy property
/// </summary>
[Parameter(parametersetname="StandardMethod")]
[Parameter(parametersetname="CustomMethod")]
public virtual Uri Proxy { get; set; }
/// <summary>
/// gets or sets the ProxyCredential property
/// </summary>
[Parameter(parametersetname="StandardMethod")]
[Parameter(parametersetname="CustomMethod")]
[Credential]
public virtual PSCredential ProxyCredential { get; set; }
/// <summary>
/// gets or sets the ProxyUseDefaultCredentials property
/// </summary>
[Parameter(parametersetname="StandardMethod")]
[Parameter(parametersetname="CustomMethod")]
public virtual SwitchParameter ProxyUseDefaultCredentials { get; set; }
#endregion
....
....
internal virtual HttpRequestMessage GetRequest(Uri uri)
{
Uri requestUri = PrepareUri(uri);
HttpMethod httpMethod = null;
switch (ParameterSetName)
{
case "StandardMethodNoProxy":
goto case "StandardMethod";
case "StandardMethod":
// set the method if the parameter was provided
httpMethod = GetHttpMethod(Method);
break;
case "CustomMethodNoProxy":
goto case "CustomMethod";
case "CustomMethod":
if (!string.IsNullOrEmpty(CustomMethod))
{
// set the method if the parameter was provided
httpMethod = new HttpMethod(CustomMethod.ToString().ToUpperInvariant());
}
break;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment