Example #1
0
        /// <summary>
        /// Function to deserialize a dependency from an XML node.
        /// </summary>
        /// <param name="files">Available files to evaluate.</param>
        /// <param name="element">Element containing the serialized dependency.</param>
        /// <returns>A dependency deserialized from the XML node.</returns>
        internal static Dependency Deserialize(EditorFileCollection files, XElement element)
        {
            XAttribute typeAttr = element.Attribute(DependencyTypeAttr);
            XElement   pathNode = element.Element(DependencyPathNode);

            if ((typeAttr == null) ||
                (pathNode == null) ||
                (string.IsNullOrWhiteSpace(typeAttr.Value)) ||
                (string.IsNullOrWhiteSpace(pathNode.Value)))
            {
                throw new GorgonException(GorgonResult.CannotRead, APIResources.GOREDIT_ERR_DEPENDENCY_CORRUPT);
            }

            EditorFile file;

            if (!files.TryGetValue(pathNode.Value, out file))
            {
                return(null);
            }

            var result = new Dependency(file, typeAttr.Value);

            XElement propertiesNode = element.Element(DependencyPropertyCollection.PropertiesNode);

            if (propertiesNode != null)
            {
                result.Properties = DependencyPropertyCollection.Deserialize(propertiesNode);
            }

            return(result);
        }
Example #2
0
        /// <summary>
        /// Function to clone an object.
        /// </summary>
        /// <returns>
        /// The cloned object.
        /// </returns>
        public DependencyPropertyCollection Clone()
        {
            var result = new DependencyPropertyCollection();

            foreach (var property in this)
            {
                result.Add(property.Clone());
            }

            return(result);
        }
Example #3
0
        /// <summary>
        /// Function to deserialize a list of properties from an XML element.
        /// </summary>
        /// <param name="propertiesNode">XML node containing the properties list.</param>
        /// <returns>A new properties collection from the XML node.</returns>
        internal static DependencyPropertyCollection Deserialize(XElement propertiesNode)
        {
            var result = new DependencyPropertyCollection();

            IEnumerable <XElement> propertyNodes = propertiesNode.Elements(DependencyProperty.PropertyNode);

            foreach (XElement propertyNode in propertyNodes)
            {
                result.Add(DependencyProperty.Deserialize(propertyNode));
            }

            return(result);
        }
Example #4
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Dependency"/> class.
        /// </summary>
        /// <param name="file">The file that has the dependency.</param>
        /// <param name="type">The type of dependency.</param>
        /// <exception cref="System.ArgumentNullException">Thrown when the <paramref name="file"/> parameter is NULL (Nothing in VB.Net).
        /// <para>-or-</para>
        /// <para>Thrown when the <paramref name="type"/> parameter is NULL.</para>
        /// </exception>
        /// <exception cref="System.ArgumentException">Thrown when the <paramref name="type"/> parameter is an empty string.</exception>
        public Dependency(EditorFile file, string type)
        {
            if (file == null)
            {
                throw new ArgumentNullException("file");
            }

            if (type == null)
            {
                throw new ArgumentNullException("type");
            }

            if (string.IsNullOrWhiteSpace(type))
            {
                throw new ArgumentException(APIResources.GOREDIT_ERR_PARAMETER_MUST_NOT_BE_EMPTY, "type");
            }

            Properties = new DependencyPropertyCollection();
            Type       = type;
            EditorFile = file;
        }