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

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

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

Usage Example

Пример #1
0
        /// <summary>
        /// Writes the XML elements to the xml writer.
        /// </summary>
        /// <param name="writer">The writer.</param>
        /// <param name="type">The type.</param>
        private void WriteXmlElements(XmlWriter writer, Type type)
        {
            IEnumerable <KeyValuePair <string, object> > propertiesAsElements;

            lock (_propertyValuesLock)
            {
                propertiesAsElements = (from propertyValue in _propertyBag.GetAllProperties()
                                        where PropertyDataManager.IsPropertyNameMappedToXmlElement(type, propertyValue.Key)
                                        select propertyValue);
            }

            foreach (var propertyAsElement in propertiesAsElements)
            {
                var propertyInfo = GetPropertyInfo(propertyAsElement.Key);
                if (propertyInfo == null)
                {
                    continue;
                }

                if (propertyAsElement.Value == null)
                {
                    continue;
                }

                string serializationPropertyName = propertyAsElement.Key;
                serializationPropertyName = PropertyDataManager.MapPropertyNameToXmlElementName(type, serializationPropertyName);

                var propertyType            = propertyInfo.PropertyType;
                var propertyTypeToSerialize = propertyAsElement.Value.GetType();

                var serializer = SerializationHelper.GetDataContractSerializer(GetType(), propertyTypeToSerialize, serializationPropertyName, propertyAsElement.Value);

                if (propertyType != propertyTypeToSerialize)
                {
                    Log.Debug("Property type for property '{0}' is '{1}' but registered as '{2}', adding type info for deserialization",
                              propertyInfo.Name, propertyTypeToSerialize.FullName, propertyType.FullName);

                    serializer.WriteStartObject(writer, propertyAsElement.Value);

                    writer.WriteAttributeString("ctl", "type", null, propertyTypeToSerialize.FullName);

                    serializer.WriteObjectContent(writer, propertyAsElement.Value);

                    serializer.WriteEndObject(writer);
                }
                else
                {
                    serializer.WriteObject(writer, propertyAsElement.Value);
                }
            }
        }