BO4E/UserPropertiesExtensions.cs
/// <summary>
///     test if the <paramref name="parent" />.UserProperty value under key <paramref name="userPropertyKey" /> equals
///     <paramref name="other" />.
/// </summary>
/// <typeparam name="TParent">class implementing <see cref="IUserProperties" /></typeparam>
/// <typeparam name="TUserProperty">
///     type expected to be found in the User Property with key
///     <paramref name="userPropertyKey" />
/// </typeparam>
/// <param name="parent">object implementing <see cref="IUserProperties" /></param>
/// <param name="userPropertyKey">key under which the value is expected</param>
/// <param name="other">comparison value</param>
/// <param name="ignoreWrongType">
///     set true to automatically catch <see cref="FormatException" /> if the cast to
///     <typeparamref name="TUserProperty" /> fails
/// </param>
/// <returns>
///     true iff <paramref name="parent" />.UserProperties!=null and the value stored under key
///     <paramref name="userPropertyKey" /> == <paramref name="other" />
/// </returns>
/// <exception cref="ArgumentNullException">iff <paramref name="userPropertyKey" /> is null or whitespace</exception>
test if the .UserProperty value under key  equals
.
test if the . UserProperty value under key equals .
public static bool UserPropertyEquals<TUserProperty, TParent>(this TParent parent, string userPropertyKey,
            TUserProperty other, bool ignoreWrongType = true) where TParent : IUserProperties
        {
            if (parent.UserProperties == null) return false;
            try
            {
                return parent.EvaluateUserProperty<TUserProperty, bool, TParent>(userPropertyKey, value =>
                    {
                        if (value == null && other != null) return false;
                        return value == null || value.Equals(other);
                    }
                );
            }
            catch (FormatException) when (ignoreWrongType)
            {
                return false;
            }
        }
public static bool UserPropertyEquals < TUserProperty , TParent > ( this TParent parent , string userPropertyKey , TUserProperty other , bool ignoreWrongType = true ) where TParent : IUserProperties { if ( parent . UserProperties == null ) return false ; try { return parent . EvaluateUserProperty < TUserProperty , bool , TParent > ( userPropertyKey , value => { if ( value == null && other != null ) return false ; return value == null || value . Equals ( other ) ; } ) ; } catch ( FormatException ) when ( ignoreWrongType ) { return false ; } }
test if the .UserProperty value under key  equals
.
test if the . UserProperty value under key equals .
true iff .UserProperties!=null and the value stored under key
true iff . UserProperties! = null and the value stored under key
iff  is null or whitespace
iff is null or whitespace
TParent
this
userPropertyKey
string
key under which the value is expected
key under which the value is expected
other
TUserProperty
None
ignoreWrongType
bool
set true to automatically catch  if the cast to
fails
set true to automatically catch if the cast to fails
parent
None
typeparam
None
typeparam
type expected to be found in the User Property with key
type expected to be found in the User Property with key