/// <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)); } }
/// <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); } }
/// <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); }
/// <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)); }