Exemplo n.º 1
0
 public static void ThrowIfNotVisible(CommandOrigin origin, object valueToCheck)
 {
     if (!IsVisible(origin, valueToCheck))
     {
         SessionStateException exception;
         System.Management.Automation.PSVariable variable = valueToCheck as System.Management.Automation.PSVariable;
         if (variable != null)
         {
             exception = new SessionStateException(variable.Name, SessionStateCategory.Variable, "VariableIsPrivate", SessionStateStrings.VariableIsPrivate, ErrorCategory.PermissionDenied, new object[0]);
             throw exception;
         }
         CommandInfo info = valueToCheck as CommandInfo;
         if (info != null)
         {
             string itemName = null;
             if (info != null)
             {
                 itemName = info.Name;
             }
             if (itemName != null)
             {
                 exception = new SessionStateException(itemName, SessionStateCategory.Command, "NamedCommandIsPrivate", SessionStateStrings.NamedCommandIsPrivate, ErrorCategory.PermissionDenied, new object[0]);
             }
             else
             {
                 exception = new SessionStateException("", SessionStateCategory.Command, "CommandIsPrivate", SessionStateStrings.CommandIsPrivate, ErrorCategory.PermissionDenied, new object[0]);
             }
             throw exception;
         }
         exception = new SessionStateException(null, SessionStateCategory.Resource, "ResourceIsPrivate", SessionStateStrings.ResourceIsPrivate, ErrorCategory.PermissionDenied, new object[0]);
         throw exception;
     }
 }
Exemplo n.º 2
0
 public static bool IsVisible(CommandOrigin origin, System.Management.Automation.PSVariable variable)
 {
     if (origin == CommandOrigin.Internal)
     {
         return(true);
     }
     if (variable == null)
     {
         throw PSTraceSource.NewArgumentNullException("variable");
     }
     return(variable.Visibility == SessionStateEntryVisibility.Public);
 }