Ejemplo n.º 1
0
        /// <summary>
        /// Attempts to get the requested fields current or original value and cast to the required type.
        /// </summary>
        /// <param name="field">The field whose value is to be fetched.</param>
        /// <param name="updatedValue">Should the current / updated value be returned or the original value?</param>
        /// <returns>The current or original field value cat to the appropriate type.</returns>
        /// <remarks>Use this method for Struct types only, use GetFieldStringValue() for String fields.</remarks>
        public object?GetFieldValue(FormField <TItem> field, bool updatedValue = true)
        {
            // point to relevant TItem instance
            if (Item is null)
            {
                return(null);
            }

            // if original value required simply return
            object?value;
            var    memberInfo = field.Field?.GetPropertyMemberInfo();

            if (memberInfo is PropertyInfo propInfo)
            {
                if (updatedValue && Delta.ContainsKey(memberInfo.Name))
                {
                    value = Delta[memberInfo.Name];
                }
                else
                {
                    value = propInfo.GetValue(Item);
                }
            }
            else
            {
                value = field.CompiledFieldFunc?.Invoke(Item);
            }

            return(value);
        }