Exemplo n.º 1
0
        /// <summary>
        /// Determines whether the value of the property along the source path has a value or not.
        /// </summary>
        /// <param name="root"></param>
        /// <returns>True if the source path has an assigned value, otherwise false.</returns>
        /// <remarks>
        /// If any value along the source path is null, false will be returned.
        /// If the source property is a list, false will be returned if the list is empty.
        /// </remarks>
        public bool HasValue(ModelInstance root)
        {
            // Get the source
            IModelPropertySource source = GetSource(root);

            // Return false if the source is null
            if (source == null)
            {
                return(false);
            }

            // Get the property off of the source to evaluate
            ModelProperty property = source.Properties[SourceProperty];

            // If the property is a list, determine if the list has items
            if (property is ModelReferenceProperty && property.IsList)
            {
                return(source.GetList((ModelReferenceProperty)property).Count > 0);
            }

            // Otherwise, just determine if the property has an assigned value
            else
            {
                return(source[property] != null);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Gets the serializable value of a <see cref="ModelProperty"/>.
        /// </summary>
        /// <param name="property"></param>
        /// <param name="source"></param>
        /// <returns></returns>
        internal static object GetPropertyValue(ModelProperty property, IModelPropertySource source)
        {
            ModelReferenceProperty reference = property as ModelReferenceProperty;

            if (reference != null)
            {
                // Serialize lists
                if (reference.IsList)
                {
                    return(source.GetList(reference).Select(item => GetReference(reference, item)));
                }

                // Serialize references
                else
                {
                    return(GetReference(reference, source.GetReference(reference)));
                }
            }

            // Serialize values
            else
            {
                return(source.GetValue((ModelValueProperty)property));
            }
        }
Exemplo n.º 3
0
        public bool SetValue(ModelInstance root, object value, Func <ModelInstance, ModelReferenceProperty, int, bool> whenNull, Action <ModelInstance, ModelReferenceProperty, int, ModelInstance> whenNotNull)
        {
            IModelPropertySource sourceInstance = GetSource(root, whenNull, whenNotNull);

            sourceInstance[SourceProperty] = value;
            return(true);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Gets the formatted value of the property for the current source path.
        /// </summary>
        public string GetFormattedValue(ModelInstance root, string format, IFormatProvider provider, out object rawValue)
        {
            IModelPropertySource source = GetSource(root);

            if (source == null)
            {
                rawValue = null;
                return(null);
            }

            rawValue = source[SourceProperty];
            return(source.GetFormattedValue(SourceProperty, format));
        }
Exemplo n.º 5
0
        /// <summary>
        /// Gets the serializable value of a <see cref="ModelProperty"/>.
        /// </summary>
        /// <param name="property"></param>
        /// <param name="source"></param>
        /// <returns></returns>
        internal static object GetPropertyValue(ModelProperty property, IModelPropertySource source)
        {
            ModelReferenceProperty reference = property as ModelReferenceProperty;
            if (reference != null)
            {
                // Serialize lists
                if (reference.IsList)
                    return source.GetList(reference).Select(item => GetReference(reference, item));

                // Serialize references
                else
                    return GetReference(reference, source.GetReference(reference));
            }

            // Serialize values
            else
                return source.GetValue((ModelValueProperty)property);
        }
Exemplo n.º 6
0
        /// <summary>
        /// Gets the <see cref="ModelInstance"/> defined by specified source path.
        /// </summary>
        /// <param name="root"></param>
        /// <returns></returns>
        public ModelInstance GetReference(ModelInstance root)
        {
            IModelPropertySource source = GetSource(root);

            return(source == null ? null : source.GetReference(SourceProperty));
        }
Exemplo n.º 7
0
        /// <summary>
        /// Gets the <see cref="ModelInstanceList"/> defined by specified source path.
        /// </summary>
        /// <param name="root"></param>
        /// <returns></returns>
        public ModelInstanceList GetList(ModelInstance root)
        {
            IModelPropertySource source = GetSource(root);

            return(source == null ? null : source.GetList(SourceProperty));
        }
Exemplo n.º 8
0
        /// <summary>
        /// Gets the formatted value of the property for the current source path.
        /// </summary>
        /// <param name="root"></param>
        /// <param name="format">The specific format to use</param>
        /// <returns></returns>
        public string GetFormattedValue(ModelInstance root, string format)
        {
            IModelPropertySource source = GetSource(root);

            return(source == null ? null : source.GetFormattedValue(SourceProperty, format));
        }
Exemplo n.º 9
0
        /// <summary>
        /// Gets the underlying value of the property for the current source path.
        /// </summary>
        /// <param name="root"></param>
        /// <returns></returns>
        public object GetValue(ModelInstance root)
        {
            IModelPropertySource source = GetSource(root);

            return(source == null ? null : source[SourceProperty]);
        }