Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Obsolete IValue SetTypeUsingReflection & associated methods #3555

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/NHibernate/Cfg/XmlHbmBinding/ClassCompositeIdBinder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down Expand Up @@ -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);
}

Expand Down
2 changes: 1 addition & 1 deletion src/NHibernate/Cfg/XmlHbmBinding/ClassIdBinder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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 };

Expand Down
25 changes: 22 additions & 3 deletions src/NHibernate/Cfg/XmlHbmBinding/PropertiesBinder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -386,16 +386,35 @@ private void BindCollectionProperty(ICollectionPropertiesMapping collectionMappi
property.Cascade = collectionMapping.Cascade ?? mappings.DefaultCascade;
}

private Property CreateProperty(IEntityPropertyMapping propertyMapping, System.Type propertyOwnerType, IValue value, IDictionary<string, MetaAttribute> inheritedMetas)
private Property CreateProperty(IEntityPropertyMapping propertyMapping, System.Type propertyOwnerType, SimpleValue value, IDictionary<string, MetaAttribute> inheritedMetas)
{
var type = propertyOwnerType?.UnwrapIfNullable();
if (string.IsNullOrEmpty(propertyMapping.Name))
throw new MappingException("A property mapping must define the name attribute [" + type + "]");

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<string, MetaAttribute> 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
{
Expand Down
6 changes: 6 additions & 0 deletions src/NHibernate/Mapping/Any.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
}

/// <summary>
/// Get or set the metatype
/// </summary>
Expand Down
2 changes: 2 additions & 0 deletions src/NHibernate/Mapping/Collection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
}
Expand Down
6 changes: 6 additions & 0 deletions src/NHibernate/Mapping/Component.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
}

/// <summary></summary>
public bool IsEmbedded
{
Expand Down
3 changes: 3 additions & 0 deletions src/NHibernate/Mapping/IValue.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System;
using System.Collections.Generic;
using NHibernate.Engine;
using NHibernate.Type;
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions src/NHibernate/Mapping/OneToMany.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
}
Expand Down
21 changes: 21 additions & 0 deletions src/NHibernate/Mapping/SimpleValue.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
{
Expand Down
11 changes: 11 additions & 0 deletions src/NHibernate/Mapping/ToOne.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ public bool IsLazy
/// </summary>
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)
Expand All @@ -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)
Expand Down
4 changes: 4 additions & 0 deletions src/NHibernate/Util/ReflectHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,8 @@ public static IGetter GetGetter(System.Type theClass, string propertyName, strin
/// <returns>
/// The NHibernate <see cref="IType"/> for the named property.
/// </returns>
// 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);
Expand Down Expand Up @@ -419,6 +421,8 @@ public static System.Type ReflectedPropertyClass(System.Type theClass, string na
/// <param name="name">The name of the property/field to find in the class.</param>
/// <param name="accessorName">The name of the property accessor for the property.</param>
/// <returns>The <see cref="System.Type" /> for the named property.</returns>
// 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
Expand Down
Loading