Created
August 8, 2015 15:27
-
-
Save aetos382/c7a626c3d2c33100c021 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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