Skip to content

Commit 8c0a664

Browse files
authored
Fix exception accessing indexer property for field interceptor proxy (#3358)
Fixes #3354
1 parent 2cd54e6 commit 8c0a664

File tree

4 files changed

+14
-2
lines changed

4 files changed

+14
-2
lines changed

src/NHibernate.Test/Async/LazyProperty/LazyPropertyFixture.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,9 @@ public async Task CanGetValueForNonLazyPropertyAsync()
230230
Assert.That(book.Name, Is.EqualTo("some name"));
231231
Assert.That(book.FieldInterceptor, Is.EqualTo("Why not that name?"));
232232
Assert.That(NHibernateUtil.IsPropertyInitialized(book, "ALotOfText"), Is.False);
233+
//GH-3354 Exception accessing indexer property
234+
Assert.That(book[0], Is.EqualTo(0));
235+
Assert.DoesNotThrow(() => book[0] = 0);
233236
}
234237
}
235238

src/NHibernate.Test/LazyProperty/Book.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,11 @@ public virtual byte[] NoSetterImage
2828
public virtual string FieldInterceptor { get; set; }
2929

3030
public virtual IList<Word> Words { get; set; }
31+
32+
public virtual int this[int i]
33+
{
34+
get { return i;}
35+
set { }
36+
}
3137
}
3238
}

src/NHibernate.Test/LazyProperty/LazyPropertyFixture.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,9 @@ public void CanGetValueForNonLazyProperty()
225225
Assert.That(book.Name, Is.EqualTo("some name"));
226226
Assert.That(book.FieldInterceptor, Is.EqualTo("Why not that name?"));
227227
Assert.That(NHibernateUtil.IsPropertyInitialized(book, "ALotOfText"), Is.False);
228+
//GH-3354 Exception accessing indexer property
229+
Assert.That(book[0], Is.EqualTo(0));
230+
Assert.DoesNotThrow(() => book[0] = 0);
228231
}
229232
}
230233

src/NHibernate/Proxy/FieldInterceptorProxyBuilder.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,11 +94,11 @@ public static TypeInfo CreateProxyType(System.Type baseType)
9494

9595
private static void CreateProxiedMethod(TypeBuilder typeBuilder, MethodInfo method, FieldInfo fieldInterceptorField)
9696
{
97-
if (ReflectHelper.IsPropertyGet(method))
97+
if (ReflectHelper.IsPropertyGet(method) && method.GetParameters().Length == 0)
9898
{
9999
ImplementGet(typeBuilder, method, fieldInterceptorField);
100100
}
101-
else if (ReflectHelper.IsPropertySet(method))
101+
else if (ReflectHelper.IsPropertySet(method) && method.GetParameters().Length == 1)
102102
{
103103
ImplementSet(typeBuilder, method, fieldInterceptorField);
104104
}

0 commit comments

Comments
 (0)