System.Management.Automation.SessionStateUnauthorizedAccessException.CreateVariableNotWritableError C# (CSharp) Method

CreateVariableNotWritableError() static private method

static private CreateVariableNotWritableError ( PSVariable variable ) : SessionStateUnauthorizedAccessException
variable PSVariable
return SessionStateUnauthorizedAccessException
        internal static SessionStateUnauthorizedAccessException CreateVariableNotWritableError(PSVariable variable)
        {
            string message = String.Format("Cannot overwrite variable {0} because it is read-only or constant.", variable.Name);
            return CreateError(variable, message, "VariableNotWritable");
        }

Usage Example

Ejemplo n.º 1
0
        private static void CheckVariableCanBeChanged(PSVariable variable, bool force = false)
        {
            if ((variable.ItemOptions.HasFlag(ScopedItemOptions.ReadOnly) && !force) ||
                variable.ItemOptions.HasFlag(ScopedItemOptions.Constant))
            {
                var ex = SessionStateUnauthorizedAccessException.CreateVariableNotWritableError(variable);
                throw ex;
            }

            ThrowIfVariableIsPrivate(variable);
        }