diff --git a/src/NHibernate/Cfg/XmlHbmBinding/ClassCompositeIdBinder.cs b/src/NHibernate/Cfg/XmlHbmBinding/ClassCompositeIdBinder.cs index 00e384c5e76..99ea0ad6b3c 100644 --- a/src/NHibernate/Cfg/XmlHbmBinding/ClassCompositeIdBinder.cs +++ b/src/NHibernate/Cfg/XmlHbmBinding/ClassCompositeIdBinder.cs @@ -190,7 +190,7 @@ private Property CreateProperty(ToOne value, string propertyName, System.Type pa { if (parentClass != null && value.IsSimpleValue) { - value.SetTypeUsingReflection(parentClass.AssemblyQualifiedName, propertyName, + value.SetTypeUsingReflection(parentClass, propertyName, keyManyToOneSchema.access ?? mappings.DefaultAccess); } @@ -242,7 +242,7 @@ private Property CreateProperty(SimpleValue value, string propertyName, System.T { if (parentClass != null && value.IsSimpleValue) { - value.SetTypeUsingReflection(parentClass.AssemblyQualifiedName, propertyName, + value.SetTypeUsingReflection(parentClass, propertyName, keyPropertySchema.access ?? mappings.DefaultAccess); } diff --git a/src/NHibernate/Cfg/XmlHbmBinding/ClassIdBinder.cs b/src/NHibernate/Cfg/XmlHbmBinding/ClassIdBinder.cs index 89a7bef6faa..23618a368fc 100644 --- a/src/NHibernate/Cfg/XmlHbmBinding/ClassIdBinder.cs +++ b/src/NHibernate/Cfg/XmlHbmBinding/ClassIdBinder.cs @@ -45,7 +45,7 @@ private void CreateIdentifierProperty(HbmId idSchema, PersistentClass rootClass, if (idSchema.name != null) { string access = idSchema.access ?? mappings.DefaultAccess; - id.SetTypeUsingReflection(rootClass.MappedClass?.AssemblyQualifiedName, idSchema.name, access); + id.SetTypeUsingReflection(rootClass.MappedClass, idSchema.name, access); var property = new Property(id) { Name = idSchema.name }; diff --git a/src/NHibernate/Cfg/XmlHbmBinding/PropertiesBinder.cs b/src/NHibernate/Cfg/XmlHbmBinding/PropertiesBinder.cs index 80d4500e0fc..27106d57ea2 100644 --- a/src/NHibernate/Cfg/XmlHbmBinding/PropertiesBinder.cs +++ b/src/NHibernate/Cfg/XmlHbmBinding/PropertiesBinder.cs @@ -386,7 +386,7 @@ private void BindCollectionProperty(ICollectionPropertiesMapping collectionMappi property.Cascade = collectionMapping.Cascade ?? mappings.DefaultCascade; } - private Property CreateProperty(IEntityPropertyMapping propertyMapping, System.Type propertyOwnerType, IValue value, IDictionary inheritedMetas) + private Property CreateProperty(IEntityPropertyMapping propertyMapping, System.Type propertyOwnerType, SimpleValue value, IDictionary inheritedMetas) { var type = propertyOwnerType?.UnwrapIfNullable(); if (string.IsNullOrEmpty(propertyMapping.Name)) @@ -394,8 +394,27 @@ private Property CreateProperty(IEntityPropertyMapping propertyMapping, System.T var propertyAccessorName = GetPropertyAccessorName(propertyMapping.Access); - if (type != null && value.IsSimpleValue) - value.SetTypeUsingReflection(type.AssemblyQualifiedName, propertyMapping.Name, propertyAccessorName); + if (type != null) + value.SetTypeUsingReflection(type, propertyMapping.Name, propertyAccessorName); + + return new Property + { + Name = propertyMapping.Name, + PropertyAccessorName = propertyAccessorName, + Value = value, + IsLazy = propertyMapping.IsLazyProperty, + LazyGroup = propertyMapping.GetLazyGroup(), + IsOptimisticLocked = propertyMapping.OptimisticLock, + MetaAttributes = GetMetas(propertyMapping, inheritedMetas) + }; + } + + private Property CreateProperty(IEntityPropertyMapping propertyMapping, System.Type propertyOwnerType, Mapping.Collection value, IDictionary inheritedMetas) + { + if (string.IsNullOrEmpty(propertyMapping.Name)) + throw new MappingException("A property mapping must define the name attribute [" + propertyOwnerType + "]"); + + var propertyAccessorName = GetPropertyAccessorName(propertyMapping.Access); return new Property { diff --git a/src/NHibernate/Mapping/Any.cs b/src/NHibernate/Mapping/Any.cs index 3be627b9d6b..8fd6d421ad9 100644 --- a/src/NHibernate/Mapping/Any.cs +++ b/src/NHibernate/Mapping/Any.cs @@ -72,10 +72,16 @@ public void ResetCachedType() _type = GetLazyType(); } + // Since v5.6 + [Obsolete("This method is not used and will be removed in a future version")] public override void SetTypeUsingReflection(string className, string propertyName, string access) { } + public override void SetTypeUsingReflection(System.Type propertyOwnerType, string propertyName, string access) + { + } + /// /// Get or set the metatype /// diff --git a/src/NHibernate/Mapping/Collection.cs b/src/NHibernate/Mapping/Collection.cs index 5ebcd301ebc..769e29e814c 100644 --- a/src/NHibernate/Mapping/Collection.cs +++ b/src/NHibernate/Mapping/Collection.cs @@ -593,6 +593,8 @@ public virtual bool IsAlternateUniqueKey get { return false; } } + // Since v5.6 + [Obsolete("This method is not used and will be removed in a future version")] public void SetTypeUsingReflection(string className, string propertyName, string access) { } diff --git a/src/NHibernate/Mapping/Component.cs b/src/NHibernate/Mapping/Component.cs index c9f1409cf6f..99a395e6686 100644 --- a/src/NHibernate/Mapping/Component.cs +++ b/src/NHibernate/Mapping/Component.cs @@ -105,10 +105,16 @@ public Component(Component component) owner = component.Owner; } + // Since v5.6 + [Obsolete("This method is not used and will be removed in a future version")] public override void SetTypeUsingReflection(string className, string propertyName, string accesorName) { } + public override void SetTypeUsingReflection(System.Type propertyOwnerType, string propertyName, string accesorName) + { + } + /// public bool IsEmbedded { diff --git a/src/NHibernate/Mapping/IValue.cs b/src/NHibernate/Mapping/IValue.cs index 1941b3dc563..9bfb3522b01 100644 --- a/src/NHibernate/Mapping/IValue.cs +++ b/src/NHibernate/Mapping/IValue.cs @@ -1,3 +1,4 @@ +using System; using System.Collections.Generic; using NHibernate.Engine; using NHibernate.Type; @@ -78,6 +79,8 @@ public interface IValue FetchMode FetchMode { get; } + // Since v5.6 + [Obsolete("This method is not used and will be removed in a future version")] void SetTypeUsingReflection(string className, string propertyName, string accesorName); object Accept(IValueVisitor visitor); diff --git a/src/NHibernate/Mapping/OneToMany.cs b/src/NHibernate/Mapping/OneToMany.cs index b349e4df98b..35a82f60a43 100644 --- a/src/NHibernate/Mapping/OneToMany.cs +++ b/src/NHibernate/Mapping/OneToMany.cs @@ -125,6 +125,8 @@ public bool IsAlternateUniqueKey get { return false; } } + // Since v5.6 + [Obsolete("This method is not used and will be removed in a future version")] public void SetTypeUsingReflection(string className, string propertyName, string accesorName) { } diff --git a/src/NHibernate/Mapping/SimpleValue.cs b/src/NHibernate/Mapping/SimpleValue.cs index 29de8c8927b..7714f120fd4 100644 --- a/src/NHibernate/Mapping/SimpleValue.cs +++ b/src/NHibernate/Mapping/SimpleValue.cs @@ -341,6 +341,8 @@ public bool IsAlternateUniqueKey set { isAlternateUniqueKey = value; } } + // Since v5.6 + [Obsolete("This method is not used and will be removed in a future version")] public virtual void SetTypeUsingReflection(string className, string propertyName, string accesorName) { if (typeName == null) @@ -359,6 +361,25 @@ public virtual void SetTypeUsingReflection(string className, string propertyName } } } + + public virtual void SetTypeUsingReflection(System.Type propertyOwnerType, string propertyName, string accessorName) + { + if (typeName == null) + { + if (propertyOwnerType == null) + { + throw new MappingException("you must specify types for a dynamic entity: " + propertyName); + } + try + { + typeName = ReflectHelper.ReflectedPropertyClass(propertyOwnerType, propertyName, accessorName).AssemblyQualifiedName; + } + catch (HibernateException he) + { + throw new MappingException("Problem trying to set property type by reflection", he); + } + } + } public virtual object Accept(IValueVisitor visitor) { diff --git a/src/NHibernate/Mapping/ToOne.cs b/src/NHibernate/Mapping/ToOne.cs index c959216d4b4..a56245f32da 100644 --- a/src/NHibernate/Mapping/ToOne.cs +++ b/src/NHibernate/Mapping/ToOne.cs @@ -54,6 +54,8 @@ public bool IsLazy /// public abstract override void CreateForeignKey(); + // Since v5.6 + [Obsolete("This method is not used and will be removed in a future version")] public override void SetTypeUsingReflection(string className, string propertyName, string accesorName) { if (referencedEntityName == null) @@ -63,6 +65,15 @@ public override void SetTypeUsingReflection(string className, string propertyNam } } + public override void SetTypeUsingReflection(System.Type propertyOwnerType, string propertyName, string accessorName) + { + if (referencedEntityName == null) + { + System.Type refType = ReflectHelper.ReflectedPropertyClass(propertyOwnerType, propertyName, accessorName); + referencedEntityName = refType.FullName; + } + } + public override bool IsValid(Engine.IMapping mapping) { if (referencedEntityName == null) diff --git a/src/NHibernate/Util/ReflectHelper.cs b/src/NHibernate/Util/ReflectHelper.cs index e665a68a9c3..b693956de95 100644 --- a/src/NHibernate/Util/ReflectHelper.cs +++ b/src/NHibernate/Util/ReflectHelper.cs @@ -391,6 +391,8 @@ public static IGetter GetGetter(System.Type theClass, string propertyName, strin /// /// The NHibernate for the named property. /// + // Since v5.6 + [Obsolete("This method is not used and will be removed in a future version")] public static IType ReflectedPropertyType(System.Type theClass, string name, string access) { System.Type propertyClass = ReflectedPropertyClass(theClass, name, access); @@ -419,6 +421,8 @@ public static System.Type ReflectedPropertyClass(System.Type theClass, string na /// The name of the property/field to find in the class. /// The name of the property accessor for the property. /// The for the named property. + // Since v5.6 + [Obsolete("This method is not used and will be removed in a future version")] public static System.Type ReflectedPropertyClass(string className, string name, string accessorName) { try