Skip to content

Commit dd77529

Browse files
authored
Obsolete IValue SetTypeUsingReflection & associated methods (#3555)
1 parent 55490c9 commit dd77529

File tree

11 files changed

+80
-6
lines changed

11 files changed

+80
-6
lines changed

src/NHibernate/Cfg/XmlHbmBinding/ClassCompositeIdBinder.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ private Property CreateProperty(ToOne value, string propertyName, System.Type pa
190190
{
191191
if (parentClass != null && value.IsSimpleValue)
192192
{
193-
value.SetTypeUsingReflection(parentClass.AssemblyQualifiedName, propertyName,
193+
value.SetTypeUsingReflection(parentClass, propertyName,
194194
keyManyToOneSchema.access ?? mappings.DefaultAccess);
195195
}
196196

@@ -242,7 +242,7 @@ private Property CreateProperty(SimpleValue value, string propertyName, System.T
242242
{
243243
if (parentClass != null && value.IsSimpleValue)
244244
{
245-
value.SetTypeUsingReflection(parentClass.AssemblyQualifiedName, propertyName,
245+
value.SetTypeUsingReflection(parentClass, propertyName,
246246
keyPropertySchema.access ?? mappings.DefaultAccess);
247247
}
248248

src/NHibernate/Cfg/XmlHbmBinding/ClassIdBinder.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ private void CreateIdentifierProperty(HbmId idSchema, PersistentClass rootClass,
4545
if (idSchema.name != null)
4646
{
4747
string access = idSchema.access ?? mappings.DefaultAccess;
48-
id.SetTypeUsingReflection(rootClass.MappedClass?.AssemblyQualifiedName, idSchema.name, access);
48+
id.SetTypeUsingReflection(rootClass.MappedClass, idSchema.name, access);
4949

5050
var property = new Property(id) { Name = idSchema.name };
5151

src/NHibernate/Cfg/XmlHbmBinding/PropertiesBinder.cs

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -386,16 +386,35 @@ private void BindCollectionProperty(ICollectionPropertiesMapping collectionMappi
386386
property.Cascade = collectionMapping.Cascade ?? mappings.DefaultCascade;
387387
}
388388

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

395395
var propertyAccessorName = GetPropertyAccessorName(propertyMapping.Access);
396396

397-
if (type != null && value.IsSimpleValue)
398-
value.SetTypeUsingReflection(type.AssemblyQualifiedName, propertyMapping.Name, propertyAccessorName);
397+
if (type != null)
398+
value.SetTypeUsingReflection(type, propertyMapping.Name, propertyAccessorName);
399+
400+
return new Property
401+
{
402+
Name = propertyMapping.Name,
403+
PropertyAccessorName = propertyAccessorName,
404+
Value = value,
405+
IsLazy = propertyMapping.IsLazyProperty,
406+
LazyGroup = propertyMapping.GetLazyGroup(),
407+
IsOptimisticLocked = propertyMapping.OptimisticLock,
408+
MetaAttributes = GetMetas(propertyMapping, inheritedMetas)
409+
};
410+
}
411+
412+
private Property CreateProperty(IEntityPropertyMapping propertyMapping, System.Type propertyOwnerType, Mapping.Collection value, IDictionary<string, MetaAttribute> inheritedMetas)
413+
{
414+
if (string.IsNullOrEmpty(propertyMapping.Name))
415+
throw new MappingException("A property mapping must define the name attribute [" + propertyOwnerType + "]");
416+
417+
var propertyAccessorName = GetPropertyAccessorName(propertyMapping.Access);
399418

400419
return new Property
401420
{

src/NHibernate/Mapping/Any.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,16 @@ public void ResetCachedType()
7272
_type = GetLazyType();
7373
}
7474

75+
// Since v5.6
76+
[Obsolete("This method is not used and will be removed in a future version")]
7577
public override void SetTypeUsingReflection(string className, string propertyName, string access)
7678
{
7779
}
7880

81+
public override void SetTypeUsingReflection(System.Type propertyOwnerType, string propertyName, string access)
82+
{
83+
}
84+
7985
/// <summary>
8086
/// Get or set the metatype
8187
/// </summary>

src/NHibernate/Mapping/Collection.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -593,6 +593,8 @@ public virtual bool IsAlternateUniqueKey
593593
get { return false; }
594594
}
595595

596+
// Since v5.6
597+
[Obsolete("This method is not used and will be removed in a future version")]
596598
public void SetTypeUsingReflection(string className, string propertyName, string access)
597599
{
598600
}

src/NHibernate/Mapping/Component.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,10 +105,16 @@ public Component(Component component)
105105
owner = component.Owner;
106106
}
107107

108+
// Since v5.6
109+
[Obsolete("This method is not used and will be removed in a future version")]
108110
public override void SetTypeUsingReflection(string className, string propertyName, string accesorName)
109111
{
110112
}
111113

114+
public override void SetTypeUsingReflection(System.Type propertyOwnerType, string propertyName, string accesorName)
115+
{
116+
}
117+
112118
/// <summary></summary>
113119
public bool IsEmbedded
114120
{

src/NHibernate/Mapping/IValue.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using System;
12
using System.Collections.Generic;
23
using NHibernate.Engine;
34
using NHibernate.Type;
@@ -78,6 +79,8 @@ public interface IValue
7879

7980
FetchMode FetchMode { get; }
8081

82+
// Since v5.6
83+
[Obsolete("This method is not used and will be removed in a future version")]
8184
void SetTypeUsingReflection(string className, string propertyName, string accesorName);
8285

8386
object Accept(IValueVisitor visitor);

src/NHibernate/Mapping/OneToMany.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,8 @@ public bool IsAlternateUniqueKey
125125
get { return false; }
126126
}
127127

128+
// Since v5.6
129+
[Obsolete("This method is not used and will be removed in a future version")]
128130
public void SetTypeUsingReflection(string className, string propertyName, string accesorName)
129131
{
130132
}

src/NHibernate/Mapping/SimpleValue.cs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,8 @@ public bool IsAlternateUniqueKey
341341
set { isAlternateUniqueKey = value; }
342342
}
343343

344+
// Since v5.6
345+
[Obsolete("This method is not used and will be removed in a future version")]
344346
public virtual void SetTypeUsingReflection(string className, string propertyName, string accesorName)
345347
{
346348
if (typeName == null)
@@ -359,6 +361,25 @@ public virtual void SetTypeUsingReflection(string className, string propertyName
359361
}
360362
}
361363
}
364+
365+
public virtual void SetTypeUsingReflection(System.Type propertyOwnerType, string propertyName, string accessorName)
366+
{
367+
if (typeName == null)
368+
{
369+
if (propertyOwnerType == null)
370+
{
371+
throw new MappingException("you must specify types for a dynamic entity: " + propertyName);
372+
}
373+
try
374+
{
375+
typeName = ReflectHelper.ReflectedPropertyClass(propertyOwnerType, propertyName, accessorName).AssemblyQualifiedName;
376+
}
377+
catch (HibernateException he)
378+
{
379+
throw new MappingException("Problem trying to set property type by reflection", he);
380+
}
381+
}
382+
}
362383

363384
public virtual object Accept(IValueVisitor visitor)
364385
{

src/NHibernate/Mapping/ToOne.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ public bool IsLazy
5454
/// </summary>
5555
public abstract override void CreateForeignKey();
5656

57+
// Since v5.6
58+
[Obsolete("This method is not used and will be removed in a future version")]
5759
public override void SetTypeUsingReflection(string className, string propertyName, string accesorName)
5860
{
5961
if (referencedEntityName == null)
@@ -63,6 +65,15 @@ public override void SetTypeUsingReflection(string className, string propertyNam
6365
}
6466
}
6567

68+
public override void SetTypeUsingReflection(System.Type propertyOwnerType, string propertyName, string accessorName)
69+
{
70+
if (referencedEntityName == null)
71+
{
72+
System.Type refType = ReflectHelper.ReflectedPropertyClass(propertyOwnerType, propertyName, accessorName);
73+
referencedEntityName = refType.FullName;
74+
}
75+
}
76+
6677
public override bool IsValid(Engine.IMapping mapping)
6778
{
6879
if (referencedEntityName == null)

src/NHibernate/Util/ReflectHelper.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -391,6 +391,8 @@ public static IGetter GetGetter(System.Type theClass, string propertyName, strin
391391
/// <returns>
392392
/// The NHibernate <see cref="IType"/> for the named property.
393393
/// </returns>
394+
// Since v5.6
395+
[Obsolete("This method is not used and will be removed in a future version")]
394396
public static IType ReflectedPropertyType(System.Type theClass, string name, string access)
395397
{
396398
System.Type propertyClass = ReflectedPropertyClass(theClass, name, access);
@@ -419,6 +421,8 @@ public static System.Type ReflectedPropertyClass(System.Type theClass, string na
419421
/// <param name="name">The name of the property/field to find in the class.</param>
420422
/// <param name="accessorName">The name of the property accessor for the property.</param>
421423
/// <returns>The <see cref="System.Type" /> for the named property.</returns>
424+
// Since v5.6
425+
[Obsolete("This method is not used and will be removed in a future version")]
422426
public static System.Type ReflectedPropertyClass(string className, string name, string accessorName)
423427
{
424428
try

0 commit comments

Comments
 (0)