BO4E/UserPropertiesExtensions.cs
/// <summary>
///     set the value of flag <paramref name="flagKey" /> to <paramref name="flagValue" />.
///     If there is no such flag or not user properties yet, they will be created.
/// </summary>
/// <remarks>
///     "having a flag set" means that the Business Object has a UserProperty entry that has
///     <paramref name="flagKey" /> as key and the value of the user property is true.
/// </remarks>
/// <param name="parent">
///     object that implements <see cref="IUserProperties" /> (so either inheriting from
///     <see cref="BO4E.BO.BusinessObject" /> or <see cref="BO4E.COM.COM" />
/// </param>
/// <param name="flagKey">key in the userproperties that should hold the value <paramref name="flagValue" /></param>
/// <param name="flagValue">flag value, use null to remove the flag</param>
/// <returns>true iff userProperties had been modified, false if not</returns>
set the value of flag  to .
If there is no such flag or not user properties yet, they will be created.
set the value of flag to . If there is no such flag or not user properties yet they will be created .
public static bool SetFlag<TParent>(this TParent parent, string flagKey, bool? flagValue = true)
            where TParent : class, IUserProperties
        {
            if (string.IsNullOrWhiteSpace(flagKey)) throw new ArgumentNullException(nameof(flagKey));
            if (parent.UserProperties == null)
            {
                parent.UserProperties = new Dictionary<string, object>();
                if (!flagValue.HasValue) return false;
            }
            else if (flagValue.HasValue && flagValue.Value == parent.HasFlagSet(flagKey))
            {
                return false;
            }
            if (!flagValue.HasValue)
            {
                if (!parent.UserProperties.ContainsKey(flagKey)) return false;
                parent.UserProperties.Remove(flagKey);
                return true;
            }
            if (parent.TryGetUserProperty<bool?, TParent>(flagKey, out var existingValue) &&
                existingValue == flagValue.Value)
                return false;
            parent.UserProperties[flagKey] = flagValue.Value;
            return true;
        }
public static bool SetFlag < TParent > ( this TParent parent , string flagKey , bool ? flagValue = true ) where TParent : class , IUserProperties { if ( string . IsNullOrWhiteSpace ( flagKey ) ) throw new ArgumentNullException ( nameof ( flagKey ) ) ; if ( parent . UserProperties == null ) { parent . UserProperties = new Dictionary < string , object > ( ) ; if ( ! flagValue . HasValue ) return false ; } else if ( flagValue . HasValue && flagValue . Value == parent . HasFlagSet ( flagKey ) ) { return false ; } if ( ! flagValue . HasValue ) { if ( ! parent . UserProperties . ContainsKey ( flagKey ) ) return false ; parent . UserProperties . Remove ( flagKey ) ; return true ; } if ( parent . TryGetUserProperty < bool ? , TParent > ( flagKey , out var existingValue ) && existingValue == flagValue . Value ) return false ; parent . UserProperties [ flagKey ] = flagValue . Value ; return true ; }
set the value of flag  to .
set the value of flag to .
true iff userProperties had been modified, false if not
true iff userProperties had been modified false if not
TParent
this
flagKey
string
key in the userproperties that should hold the value
key in the userproperties that should hold the value
flagValue
bool?
flag value, use null to remove the flag
flag value use null to remove the flag
parent
object that implements  (so either inheriting from
or
object that implements ( so either inheriting from or
remarks
"having a flag set" means that the Business Object has a UserProperty entry that has
as key and the value of the user property is true.
" having a flag set " means that the Business Object has a UserProperty entry that has as key and the value of the user property is true .