Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
using System;
using System.Linq.Expressions;
using System.Management.Automation;
internal static class PSCmdletExtensions
{
public static string GetMemberName<TType, TProperty>(
this TType obj,
Expression<Func<TType, TProperty>> expression)
{
return ((MemberExpression)expression.Body).Member.Name;
}
public static bool HasParameter<TType, TProperty>(
this TType obj,
Expression<Func<TType, TProperty>> expression)
where TType : PSCmdlet
{
string parameterName = GetMemberName(obj, expression);
return HasParameter(obj, parameterName);
}
public static bool HasParameter<TType>(
this TType obj,
string parameterName)
where TType : PSCmdlet
{
return obj.MyInvocation.BoundParameters.ContainsKey(parameterName);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment