private void DealWithSetValueException(ExtendedTypeSystemException e, out bool shouldThrow) { SettingValueExceptionEventArgs eventArgs = new SettingValueExceptionEventArgs(e); if (this.SettingValueException != null) { this.SettingValueException.SafeInvoke<SettingValueExceptionEventArgs>(this, eventArgs); PSObjectTypeDescriptor.typeDescriptor.WriteLine("SettingValueException event has been triggered resulting in ShouldThrow:\"{0}\".", new object[] { eventArgs.ShouldThrow }); } shouldThrow = eventArgs.ShouldThrow; }
private void DealWithSetValueException(ExtendedTypeSystemException e, out bool shouldThrow) { SettingValueExceptionEventArgs eventArgs = new SettingValueExceptionEventArgs(e); if (this.SettingValueException != null) { this.SettingValueException.SafeInvoke <SettingValueExceptionEventArgs>(this, eventArgs); PSObjectTypeDescriptor.typeDescriptor.WriteLine("SettingValueException event has been triggered resulting in ShouldThrow:\"{0}\".", new object[] { eventArgs.ShouldThrow }); } shouldThrow = eventArgs.ShouldThrow; }
private object DealWithGetValueException(ExtendedTypeSystemException e, out bool shouldThrow) { GettingValueExceptionEventArgs eventArgs = new GettingValueExceptionEventArgs(e); if (this.GettingValueException != null) { this.GettingValueException.SafeInvoke<GettingValueExceptionEventArgs>(this, eventArgs); PSObjectTypeDescriptor.typeDescriptor.WriteLine("GettingValueException event has been triggered resulting in ValueReplacement:\"{0}\".", new object[] { eventArgs.ValueReplacement }); } shouldThrow = eventArgs.ShouldThrow; return eventArgs.ValueReplacement; }
private void DealWithSetValueException(ExtendedTypeSystemException e, out bool shouldThrow) { SettingValueExceptionEventArgs e1 = new SettingValueExceptionEventArgs((Exception)e); if (this.SettingValueException != null) { this.SettingValueException((object)this, e1); PSObjectTypeDescriptor.typeDescriptor.WriteLine("SettingValueException event has been triggered resulting in ShouldThrow:\"{0}\".", (object)e1.ShouldThrow); } shouldThrow = e1.ShouldThrow; }
private object DealWithGetValueException(ExtendedTypeSystemException e, out bool shouldThrow) { GettingValueExceptionEventArgs e1 = new GettingValueExceptionEventArgs((Exception)e); if (this.GettingValueException != null) { this.GettingValueException((object)this, e1); PSObjectTypeDescriptor.typeDescriptor.WriteLine("GettingValueException event has been triggered resulting in ValueReplacement:\"{0}\".", e1.ValueReplacement); } shouldThrow = e1.ShouldThrow; return(e1.ValueReplacement); }
private object DealWithGetValueException(ExtendedTypeSystemException e, out bool shouldThrow) { GettingValueExceptionEventArgs eventArgs = new GettingValueExceptionEventArgs(e); if (this.GettingValueException != null) { this.GettingValueException.SafeInvoke <GettingValueExceptionEventArgs>(this, eventArgs); PSObjectTypeDescriptor.typeDescriptor.WriteLine("GettingValueException event has been triggered resulting in ValueReplacement:\"{0}\".", new object[] { eventArgs.ValueReplacement }); } shouldThrow = eventArgs.ShouldThrow; return(eventArgs.ValueReplacement); }
/// <summary> /// Gets the current value of the property on a component. /// </summary> /// <param name="component">The component with the property for which to retrieve the value.</param> /// <returns>The value of a property for a given component.</returns> /// <exception cref="ExtendedTypeSystemException"> /// If the property has not been found in the component or an exception has /// been thrown when getting the value of the property. /// This Exception will only be thrown if there is no event handler for the GettingValueException /// event of the <see cref="PSObjectTypeDescriptor"/> that created this <see cref="PSObjectPropertyDescriptor"/>. /// If there is an event handler, it can prevent this exception from being thrown, by changing /// the ShouldThrow property of <see cref="GettingValueExceptionEventArgs"/> from its default /// value of true to false. /// </exception> /// <exception cref="PSArgumentNullException">If <paramref name="component"/> is null.</exception> /// <exception cref="PSArgumentException">If <paramref name="component"/> is not /// an <see cref="PSObject"/> or an <see cref="PSObjectTypeDescriptor"/>.</exception> public override object GetValue(object component) { if (component == null) { throw PSTraceSource.NewArgumentNullException("component"); } PSObject mshObj = GetComponentPSObject(component); PSPropertyInfo property; try { property = mshObj.Properties[this.Name] as PSPropertyInfo; if (property == null) { PSObjectTypeDescriptor.typeDescriptor.WriteLine("Could not find property \"{0}\" to get its value.", this.Name); ExtendedTypeSystemException e = new ExtendedTypeSystemException("PropertyNotFoundInPropertyDescriptorGetValue", null, ExtendedTypeSystem.PropertyNotFoundInTypeDescriptor, this.Name); bool shouldThrow; object returnValue = DealWithGetValueException(e, out shouldThrow); if (shouldThrow) { throw e; } return(returnValue); } return(property.Value); } catch (ExtendedTypeSystemException e) { PSObjectTypeDescriptor.typeDescriptor.WriteLine("Exception getting the value of the property \"{0}\": \"{1}\".", this.Name, e.Message); bool shouldThrow; object returnValue = DealWithGetValueException(e, out shouldThrow); if (shouldThrow) { throw; } return(returnValue); } }
/// <summary> /// Sets the value of the component to a different value. /// </summary> /// <param name="component">The component with the property value that is to be set.</param> /// <param name="value">The new value.</param> /// <exception cref="ExtendedTypeSystemException"> /// If the property has not been found in the component or an exception has /// been thrown when setting the value of the property. /// This Exception will only be thrown if there is no event handler for the SettingValueException /// event of the <see cref="PSObjectTypeDescriptor"/> that created this <see cref="PSObjectPropertyDescriptor"/>. /// If there is an event handler, it can prevent this exception from being thrown, by changing /// the ShouldThrow property of <see cref="SettingValueExceptionEventArgs"/> /// from its default value of true to false. /// </exception> /// <exception cref="PSArgumentNullException">If <paramref name="component"/> is null.</exception> /// <exception cref="PSArgumentException">If <paramref name="component"/> is not an /// <see cref="PSObject"/> or an <see cref="PSObjectTypeDescriptor"/>. /// </exception> public override void SetValue(object component, object value) { if (component is null) { throw PSTraceSource.NewArgumentNullException(nameof(component)); } PSObject mshObj = GetComponentPSObject(component); try { PSPropertyInfo property = mshObj.Properties[this.Name] as PSPropertyInfo; if (property is null) { PSObjectTypeDescriptor.typeDescriptor.WriteLine("Could not find property \"{0}\" to set its value.", this.Name); ExtendedTypeSystemException e = new ExtendedTypeSystemException("PropertyNotFoundInPropertyDescriptorSetValue", null, ExtendedTypeSystem.PropertyNotFoundInTypeDescriptor, this.Name); bool shouldThrow; DealWithSetValueException(e, out shouldThrow); if (shouldThrow) { throw e; } return; } property.Value = value; } catch (ExtendedTypeSystemException e) { PSObjectTypeDescriptor.typeDescriptor.WriteLine("Exception setting the value of the property \"{0}\": \"{1}\".", this.Name, e.Message); bool shouldThrow; DealWithSetValueException(e, out shouldThrow); if (shouldThrow) { throw; } } OnValueChanged(component, EventArgs.Empty); }
public override object GetValue(object component) { if (component == null) { throw PSTraceSource.NewArgumentNullException("component"); } PSObject componentPSObject = GetComponentPSObject(component); try { PSPropertyInfo info = componentPSObject.Properties[this.Name]; if (info == null) { bool flag; PSObjectTypeDescriptor.typeDescriptor.WriteLine("Could not find property \"{0}\" to get its value.", new object[] { this.Name }); ExtendedTypeSystemException e = new ExtendedTypeSystemException("PropertyNotFoundInPropertyDescriptorGetValue", null, ExtendedTypeSystem.PropertyNotFoundInTypeDescriptor, new object[] { this.Name }); object obj3 = this.DealWithGetValueException(e, out flag); if (flag) { throw e; } return(obj3); } return(info.Value); } catch (ExtendedTypeSystemException exception2) { bool flag2; PSObjectTypeDescriptor.typeDescriptor.WriteLine("Exception getting the value of the property \"{0}\": \"{1}\".", new object[] { this.Name, exception2.Message }); object obj4 = this.DealWithGetValueException(exception2, out flag2); if (flag2) { throw; } return(obj4); } }
public override object GetValue(object component) { if (component == null) { throw PSTraceSource.NewArgumentNullException("component"); } PSObject componentPSObject = GetComponentPSObject(component); try { PSPropertyInfo info = componentPSObject.Properties[this.Name]; if (info == null) { bool flag; PSObjectTypeDescriptor.typeDescriptor.WriteLine("Could not find property \"{0}\" to get its value.", new object[] { this.Name }); ExtendedTypeSystemException e = new ExtendedTypeSystemException("PropertyNotFoundInPropertyDescriptorGetValue", null, ExtendedTypeSystem.PropertyNotFoundInTypeDescriptor, new object[] { this.Name }); object obj3 = this.DealWithGetValueException(e, out flag); if (flag) { throw e; } return obj3; } return info.Value; } catch (ExtendedTypeSystemException exception2) { bool flag2; PSObjectTypeDescriptor.typeDescriptor.WriteLine("Exception getting the value of the property \"{0}\": \"{1}\".", new object[] { this.Name, exception2.Message }); object obj4 = this.DealWithGetValueException(exception2, out flag2); if (flag2) { throw; } return obj4; } }
public override object GetValue(object component) { PSObject psObject = component != null?PSObjectPropertyDescriptor.GetComponentPSObject(component) : throw PSObjectPropertyDescriptor.tracer.NewArgumentNullException(nameof(component)); try { PSPropertyInfo property = psObject.Properties[this.Name]; if (property != null) { return(property.Value); } PSObjectTypeDescriptor.typeDescriptor.WriteLine("Could not find property \"{0}\" to get its value.", (object)this.Name); ExtendedTypeSystemException e = new ExtendedTypeSystemException("PropertyNotFoundInPropertyDescriptorGetValue", (Exception)null, "ExtendedTypeSystem", "PropertyNotFoundInTypeDescriptor", new object[1] { (object)this.Name }); bool shouldThrow; object valueException = this.DealWithGetValueException(e, out shouldThrow); if (shouldThrow) { throw e; } return(valueException); } catch (ExtendedTypeSystemException ex) { PSObjectTypeDescriptor.typeDescriptor.WriteLine("Exception getting the value of the property \"{0}\": \"{1}\".", (object)this.Name, (object)ex.Message); bool shouldThrow; object valueException = this.DealWithGetValueException(ex, out shouldThrow); if (!shouldThrow) { return(valueException); } throw; } }
/// <summary> /// Validate the names of properties /// </summary> /// <param name="names"></param> private static void ValidatePropertyNames(IList<string> names) { if (names != null) { if (names.Count == 0) { //If there are no names, it is an error } else { HashSet<string> headers = new HashSet<string>(StringComparer.OrdinalIgnoreCase); foreach (string currentHeader in names) { if (!String.IsNullOrEmpty(currentHeader)) { if (!headers.Contains(currentHeader)) { headers.Add(currentHeader); } else { // throw a terminating error as there are duplicate headers in the input. string memberAlreadyPresentMsg = String.Format(CultureInfo.InvariantCulture, ExtendedTypeSystem.MemberAlreadyPresent, currentHeader); ExtendedTypeSystemException exception = new ExtendedTypeSystemException(memberAlreadyPresentMsg); throw exception; } } } } } }
private static void ValidatePropertyNames(IList<string> names) { if ((names != null) && (names.Count != 0)) { HashSet<string> set = new HashSet<string>(StringComparer.OrdinalIgnoreCase); foreach (string str in names) { if (!string.IsNullOrEmpty(str)) { if (set.Contains(str)) { ExtendedTypeSystemException exception = new ExtendedTypeSystemException(string.Format(CultureInfo.InvariantCulture, ExtendedTypeSystem.ResourceManager.GetString("MemberAlreadyPresent"), new object[] { str })); throw exception; } set.Add(str); } } } }
/// <summary> /// Sets the value of the component to a different value. /// </summary> /// <param name="component">The component with the property value that is to be set. </param> /// <param name="value">The new value.</param> /// <exception cref="ExtendedTypeSystemException"> /// If the property has not been found in the component or an exception has /// been thrown when setting the value of the property. /// This Exception will only be thrown if there is no event handler for the SettingValueException /// event of the <see cref="PSObjectTypeDescriptor"/> that created this <see cref="PSObjectPropertyDescriptor"/>. /// If there is an event handler, it can prevent this exception from being thrown, by changing /// the ShouldThrow property of <see cref="SettingValueExceptionEventArgs"/> /// from its default value of true to false. /// </exception> /// <exception cref="PSArgumentNullException">If <paramref name="component"/> is null.</exception> /// <exception cref="PSArgumentException">if <paramref name="component"/> is not an /// <see cref="PSObject"/> or an <see cref="PSObjectTypeDescriptor"/>. /// </exception> public override void SetValue(object component, object value) { if (component == null) { throw PSTraceSource.NewArgumentNullException("component"); } PSObject mshObj = GetComponentPSObject(component); try { PSPropertyInfo property = mshObj.Properties[this.Name] as PSPropertyInfo; if (property == null) { PSObjectTypeDescriptor.typeDescriptor.WriteLine("Could not find property \"{0}\" to set its value.", this.Name); ExtendedTypeSystemException e = new ExtendedTypeSystemException("PropertyNotFoundInPropertyDescriptorSetValue", null, ExtendedTypeSystem.PropertyNotFoundInTypeDescriptor, this.Name); bool shouldThrow; DealWithSetValueException(e, out shouldThrow); if (shouldThrow) { throw e; } return; } property.Value = value; } catch (ExtendedTypeSystemException e) { PSObjectTypeDescriptor.typeDescriptor.WriteLine("Exception setting the value of the property \"{0}\": \"{1}\".", this.Name, e.Message); bool shouldThrow; DealWithSetValueException(e, out shouldThrow); if (shouldThrow) { throw; } } OnValueChanged(component, EventArgs.Empty); }