Skip to content

Instantly share code, notes, and snippets.

@aetos382
Created August 8, 2015 15:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aetos382/c7a626c3d2c33100c021 to your computer and use it in GitHub Desktop.
Save aetos382/c7a626c3d2c33100c021 to your computer and use it in GitHub Desktop.
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