Catel.Data.PropertyDataManager.IsXmlElementNameMappedToProperty C# (CSharp) Метод

IsXmlElementNameMappedToProperty() публичный Метод

Determines whether the specified XML element is mapped to a property name.
The is null. The is null or whitespace.
public IsXmlElementNameMappedToProperty ( Type type, string xmlName ) : bool
type System.Type The type.
xmlName string Name of the XML.
Результат bool
        public bool IsXmlElementNameMappedToProperty(Type type, string xmlName)
        {
            return _xmlElementMappings.IsXmlNameMappedToProperty(type, xmlName);
        }

Usage Example

Пример #1
0
        /// <summary>
        /// Generates an object from its XML representation.
        /// </summary>
        /// <param name="reader">The <see cref="T:System.Xml.XmlReader"/> stream from which the object is deserialized.</param>
        void IXmlSerializable.ReadXml(XmlReader reader)
        {
            if (reader.IsEmptyElement)
            {
                return;
            }

            var type = GetType();

            var settings = new XmlReaderSettings();

            settings.ConformanceLevel             = ConformanceLevel.Auto;
            settings.IgnoreComments               = true;
            settings.IgnoreProcessingInstructions = true;
            settings.IgnoreWhitespace             = true;
            var newReader = XmlReader.Create(reader, settings);

            //if (!string.Equals(type.Name, newReader.LocalName, StringComparison.OrdinalIgnoreCase))
            //{
            //    if (!newReader.Read())
            //    {
            //        return;
            //    }
            //}

            bool isAtXmlRoot = string.IsNullOrEmpty(newReader.LocalName) || string.Equals(newReader.LocalName, "xml", StringComparison.OrdinalIgnoreCase);

            if (isAtXmlRoot)
            {
                newReader.MoveToContent();
            }

            // Read attributes
            if (newReader.MoveToFirstAttribute())
            {
                do
                {
                    if (PropertyDataManager.IsXmlAttributeNameMappedToProperty(type, newReader.LocalName))
                    {
                        var propertyName = PropertyDataManager.MapXmlAttributeNameToPropertyName(type, reader.LocalName);
                        ReadValueFromXmlNode(newReader, propertyName);
                    }
                } while (newReader.MoveToNextAttribute());
            }

            // This might be the node itself or a wrapping node (in case of web services),
            // so check if that is true and step into child element
            if (string.IsNullOrEmpty(newReader.LocalName) || !PropertyDataManager.IsXmlElementNameMappedToProperty(type, newReader.LocalName))
            {
                newReader.Read();
                newReader.MoveToElement();
            }

            while (newReader.NodeType != XmlNodeType.EndElement)
            {
                if (string.IsNullOrEmpty(reader.LocalName))
                {
                    Log.Debug("reader.LocalName is null or empty, trying to skip current node");
                    reader.Skip();

                    if (string.IsNullOrEmpty(reader.LocalName))
                    {
                        Log.Warning("reader.LocalName is null or empty, cannot read empty xml tag");
                        continue;
                    }
                }

                if (PropertyDataManager.IsXmlElementNameMappedToProperty(type, reader.LocalName))
                {
                    var propertyName = PropertyDataManager.MapXmlElementNameToPropertyName(type, reader.LocalName);
                    ReadValueFromXmlNode(newReader, propertyName);
                }
                else
                {
                    newReader.Skip();
                }

                while (newReader.NodeType == XmlNodeType.Whitespace)
                {
                    newReader.Skip();
                }
            }

            FinishDeserialization();
        }