internal XmlPropertyTypeBuilder(XmlEntityTypeInfo xmlEntityTypeInfo, XmlPropertyTypeInfo xmlPropertyTypeInfo, XmlModelTypeInfo xmlModelTypeInfo, XmlDataModel xmlModelTypeBuilder)
 {
     _xmlEntityTypeInfo   = xmlEntityTypeInfo;
     _xmlPropertyTypeInfo = xmlPropertyTypeInfo;
     _xmlModelTypeInfo    = xmlModelTypeInfo;
     _xmlModelTypeBuilder = xmlModelTypeBuilder;
     _xmlModelTypeBuilder.XmlModelInfo.SerializationTypesKeyedByName[_propertyType.Name] = _propertyType;
 }
Ejemplo n.º 2
0
 public XmlPropertyTypeInfo GetOrCreatePropertyTypeInfo(string propertyName, PropertyInfo propertyInfo)
 {
     if (!PropertiesTypeInfo.TryGetValue(propertyName, out XmlPropertyTypeInfo xmlPropertyTypeInfo))
     {
         xmlPropertyTypeInfo = new XmlPropertyTypeInfo();
         xmlPropertyTypeInfo.AssociatedPropertyName = propertyName;
         xmlPropertyTypeInfo.PropertyInfo           = propertyInfo;
         PropertiesTypeInfo.Add(propertyName, xmlPropertyTypeInfo);
     }
     return(xmlPropertyTypeInfo);
 }
        /// <summary>
        /// Returns an object that can be used to configure a property of the entity type.
        /// If the specified property is not already part of the model, it will be added.
        /// </summary>
        /// <typeparam name="T">The type of the property to be configured.</typeparam>
        /// <param name="propertyExpression">A lambda expression representing the property to be configured ( blog => blog.Url).</param>
        /// <returns><see cref="XmlPropertyTypeBuilder{TEntity,TProperty}"/>An object that can be used to configure the property.</returns>
        public XmlPropertyTypeBuilder <TEntity, T> Property <T>(Expression <Func <TEntity, T> > propertyExpression)
        {
            ExpressionHelper.GetPropertyInfo(propertyExpression, out string propertyName, out PropertyInfo propertyInfo);
            if (propertyInfo.PropertyType.IsInterface && !XmlCollectionHelper.IsSupportedCollectionType(propertyInfo.PropertyType))
            {
                throw new InvalidOperationException($"Serialization/deserialization from interfaces is not allowd. Property:{propertyInfo.DeclaringType.Name}.{propertyName} of type:{propertyInfo.PropertyType.Name}. Choose a concrete type for selected property.");
            }
            XmlPropertyTypeInfo xmlPropertyTypeInfo = _xmlEntityTypeInfo.GetOrCreatePropertyTypeInfo(propertyName, propertyInfo);

            return(new XmlPropertyTypeBuilder <TEntity, T>(_xmlEntityTypeInfo, xmlPropertyTypeInfo, _xmlModelTypeInfo, _xmlModelTypeBuilder));
        }
Ejemplo n.º 4
0
 private string GetXmlObjectName(XmlPropertyTypeInfo xmlPropertyTypeInfo)
 {
     if (!string.IsNullOrWhiteSpace(xmlPropertyTypeInfo.XmlName))
     {
         return(xmlPropertyTypeInfo.XmlName);
     }
     else
     {
         return(xmlPropertyTypeInfo.AssociatedPropertyName);
     }
 }