public PSVariable(string name, object value, ScopedItemOptions options, Collection <Attribute> attributes) { this.name = string.Empty; this.description = string.Empty; if (string.IsNullOrEmpty(name)) { throw PSTraceSource.NewArgumentException("name"); } this.name = name; this.attributes = new PSVariableAttributeCollection(this); this.SetValueRawImpl(value, true); if (attributes != null) { foreach (Attribute attribute in attributes) { this.attributes.Add(attribute); } } this.options = options; if (this.IsAllScope) { VariableAnalysis.NoteAllScopeVariable(name); } }
/// <summary> /// Constructs a variable with the given name, value, options, and attributes /// </summary> /// <param name="name"> /// The name of the variable. /// </param> /// <param name="value"> /// The value of the variable. /// </param> /// <param name="options"> /// The constraints of the variable. Note, variables can only be made constant /// in the constructor. /// </param> /// <param name="attributes"> /// The attributes for the variable. ValidateArgumentsAttribute and derived types /// will be used to validate a value before setting it. /// </param> /// <exception cref="ArgumentException"> /// If <paramref name="name"/> is null or empty. /// </exception> /// <exception cref="ValidationMetadataException"> /// If the validation metadata identified in <paramref name="attributes"/> /// throws an exception. /// </exception> public PSVariable( string name, object value, ScopedItemOptions options, Collection <Attribute> attributes) { if (String.IsNullOrEmpty(name)) { throw PSTraceSource.NewArgumentException("name"); } Name = name; _attributes = new PSVariableAttributeCollection(this); // Note, it is OK to set the value before setting the attributes // because each attribute will be validated as it is set. SetValueRawImpl(value, true); if (attributes != null) { foreach (Attribute attribute in attributes) { _attributes.Add(attribute); } } // Set the options after setting the initial value. _options = options; if (IsAllScope) { Language.VariableAnalysis.NoteAllScopeVariable(name); } }