/// <summary> /// Determines if the property is read only. /// </summary> /// <param name="propertyInfo">The property information.</param> /// <param name="attribute">The attribute.</param> /// <returns><c>true</c> if the property is read only, <c>false</c> otherwise.</returns> /// <exception cref="NotSupportedException">The value ({userOptions}) specified for {nameof(TsPropertyAttribute.IsReadOnly)} on the {propertyInfo.Name}</exception> private static bool GetIsReadOnly(PropertyInfo propertyInfo, TsPropertyAttribute attribute) { TsPropertyValueOptions userOptions = attribute?.IsReadOnly ?? TsPropertyValueOptions.Auto; switch (userOptions) { case TsPropertyValueOptions.Auto: return(propertyInfo.SetMethod == null); case TsPropertyValueOptions.No: return(false); case TsPropertyValueOptions.Yes: return(true); default: throw new NotSupportedException($"The value ({userOptions}) specified for {nameof(TsPropertyAttribute.IsReadOnly)} on the {propertyInfo.Name} property is not supported."); } }
/// <summary> /// Determines if the property is optional. /// </summary> /// <param name="propertyInfo">The property information.</param> /// <param name="attribute">The attribute.</param> /// <returns><c>true</c> if the property is optional, <c>false</c> otherwise.</returns> /// <exception cref="NotSupportedException">The value ({userOptions}) specified for {nameof(TsPropertyAttribute.IsOptional)} on the {propertyInfo.Name}</exception> private static bool GetIsOptional(PropertyInfo propertyInfo, TsPropertyAttribute attribute) { TsPropertyValueOptions userOptions = attribute?.IsOptional ?? TsPropertyValueOptions.Auto; switch (userOptions) { case TsPropertyValueOptions.Auto: return(propertyInfo.PropertyType.IsClass || Nullable.GetUnderlyingType(propertyInfo.PropertyType) != null); case TsPropertyValueOptions.No: return(false); case TsPropertyValueOptions.Yes: return(true); default: throw new NotSupportedException($"The value ({userOptions}) specified for {nameof(TsPropertyAttribute.IsOptional)} on the {propertyInfo.Name} property is not supported."); } }