aboutsummaryrefslogtreecommitdiff
path: root/src/ProtocolBuffers
diff options
context:
space:
mode:
authorJon Skeet <skeet@pobox.com>2012-06-04 10:35:59 +0100
committerJon Skeet <skeet@pobox.com>2012-06-04 10:35:59 +0100
commit34378b49b5b7a2cac2305cd32a041b3ec29c66f8 (patch)
tree9bdf556de3b97fcb855c30e7788fdc8ef9a4f02f /src/ProtocolBuffers
parent8f0dcf3df1548a1eff0bed54a9b992f55b8f72d5 (diff)
downloadprotobuf-34378b49b5b7a2cac2305cd32a041b3ec29c66f8.tar.gz
protobuf-34378b49b5b7a2cac2305cd32a041b3ec29c66f8.tar.bz2
protobuf-34378b49b5b7a2cac2305cd32a041b3ec29c66f8.zip
Test and fix for issue 45. When we fetch properties, explicitly state that
we don't want any arguments, to avoid ambiguity with indexers. (Also, change a few "typeof (Foo)" to "typeof(Foo)". Fuller replacement coming.)
Diffstat (limited to 'src/ProtocolBuffers')
-rw-r--r--src/ProtocolBuffers/FieldAccess/ReflectionUtil.cs5
-rw-r--r--src/ProtocolBuffers/FieldAccess/RepeatedPrimitiveAccessor.cs18
-rw-r--r--src/ProtocolBuffers/FieldAccess/SingleMessageAccessor.cs2
-rw-r--r--src/ProtocolBuffers/FieldAccess/SinglePrimitiveAccessor.cs16
4 files changed, 22 insertions, 19 deletions
diff --git a/src/ProtocolBuffers/FieldAccess/ReflectionUtil.cs b/src/ProtocolBuffers/FieldAccess/ReflectionUtil.cs
index 31ebde06..e876d9ce 100644
--- a/src/ProtocolBuffers/FieldAccess/ReflectionUtil.cs
+++ b/src/ProtocolBuffers/FieldAccess/ReflectionUtil.cs
@@ -45,6 +45,11 @@ namespace Google.ProtocolBuffers.FieldAccess
internal static class ReflectionUtil
{
/// <summary>
+ /// Empty Type[] used when calling GetProperty to force property instead of indexer fetching.
+ /// </summary>
+ internal static readonly Type[] EmptyTypes = new Type[0];
+
+ /// <summary>
/// Creates a delegate which will execute the given method and then return
/// the result as an object.
/// </summary>
diff --git a/src/ProtocolBuffers/FieldAccess/RepeatedPrimitiveAccessor.cs b/src/ProtocolBuffers/FieldAccess/RepeatedPrimitiveAccessor.cs
index 0c2cdfcf..612e4919 100644
--- a/src/ProtocolBuffers/FieldAccess/RepeatedPrimitiveAccessor.cs
+++ b/src/ProtocolBuffers/FieldAccess/RepeatedPrimitiveAccessor.cs
@@ -66,14 +66,14 @@ namespace Google.ProtocolBuffers.FieldAccess
internal RepeatedPrimitiveAccessor(string name)
{
- PropertyInfo messageProperty = typeof (TMessage).GetProperty(name + "List");
- PropertyInfo builderProperty = typeof (TBuilder).GetProperty(name + "List");
- PropertyInfo countProperty = typeof (TMessage).GetProperty(name + "Count");
- MethodInfo clearMethod = typeof (TBuilder).GetMethod("Clear" + name, EmptyTypes);
- getElementMethod = typeof (TMessage).GetMethod("Get" + name, new Type[] {typeof (int)});
+ PropertyInfo messageProperty = typeof(TMessage).GetProperty(name + "List", ReflectionUtil.EmptyTypes);
+ PropertyInfo builderProperty = typeof(TBuilder).GetProperty(name + "List", ReflectionUtil.EmptyTypes);
+ PropertyInfo countProperty = typeof(TMessage).GetProperty(name + "Count", ReflectionUtil.EmptyTypes);
+ MethodInfo clearMethod = typeof(TBuilder).GetMethod("Clear" + name, EmptyTypes);
+ getElementMethod = typeof(TMessage).GetMethod("Get" + name, new Type[] {typeof(int)});
clrType = getElementMethod.ReturnType;
- MethodInfo addMethod = typeof (TBuilder).GetMethod("Add" + name, new Type[] {ClrType});
- setElementMethod = typeof (TBuilder).GetMethod("Set" + name, new Type[] {typeof (int), ClrType});
+ MethodInfo addMethod = typeof(TBuilder).GetMethod("Add" + name, new Type[] {ClrType});
+ setElementMethod = typeof(TBuilder).GetMethod("Set" + name, new Type[] {typeof(int), ClrType});
if (messageProperty == null
|| builderProperty == null
|| countProperty == null
@@ -85,9 +85,9 @@ namespace Google.ProtocolBuffers.FieldAccess
throw new ArgumentException("Not all required properties/methods available");
}
clearDelegate =
- (Func<TBuilder, IBuilder>) Delegate.CreateDelegate(typeof (Func<TBuilder, IBuilder>), null, clearMethod);
+ (Func<TBuilder, IBuilder>) Delegate.CreateDelegate(typeof(Func<TBuilder, IBuilder>), null, clearMethod);
countDelegate = (Func<TMessage, int>) Delegate.CreateDelegate
- (typeof (Func<TMessage, int>), null, countProperty.GetGetMethod());
+ (typeof(Func<TMessage, int>), null, countProperty.GetGetMethod());
getValueDelegate = ReflectionUtil.CreateUpcastDelegate<TMessage>(messageProperty.GetGetMethod());
addValueDelegate = ReflectionUtil.CreateDowncastDelegateIgnoringReturn<TBuilder>(addMethod);
getRepeatedWrapperDelegate = ReflectionUtil.CreateUpcastDelegate<TBuilder>(builderProperty.GetGetMethod());
diff --git a/src/ProtocolBuffers/FieldAccess/SingleMessageAccessor.cs b/src/ProtocolBuffers/FieldAccess/SingleMessageAccessor.cs
index 54b99c2b..6bf48a0c 100644
--- a/src/ProtocolBuffers/FieldAccess/SingleMessageAccessor.cs
+++ b/src/ProtocolBuffers/FieldAccess/SingleMessageAccessor.cs
@@ -50,7 +50,7 @@ namespace Google.ProtocolBuffers.FieldAccess
internal SingleMessageAccessor(string name) : base(name)
{
- MethodInfo createBuilderMethod = ClrType.GetMethod("CreateBuilder", EmptyTypes);
+ MethodInfo createBuilderMethod = ClrType.GetMethod("CreateBuilder", ReflectionUtil.EmptyTypes);
if (createBuilderMethod == null)
{
throw new ArgumentException("No public static CreateBuilder method declared in " + ClrType.Name);
diff --git a/src/ProtocolBuffers/FieldAccess/SinglePrimitiveAccessor.cs b/src/ProtocolBuffers/FieldAccess/SinglePrimitiveAccessor.cs
index 26d4a5b3..088b93fc 100644
--- a/src/ProtocolBuffers/FieldAccess/SinglePrimitiveAccessor.cs
+++ b/src/ProtocolBuffers/FieldAccess/SinglePrimitiveAccessor.cs
@@ -47,8 +47,6 @@ namespace Google.ProtocolBuffers.FieldAccess
private readonly Func<TMessage, bool> hasDelegate;
private readonly Func<TBuilder, IBuilder> clearDelegate;
- internal static readonly Type[] EmptyTypes = new Type[0];
-
/// <summary>
/// The CLR type of the field (int, the enum type, ByteString, the message etc).
/// As declared by the property.
@@ -60,14 +58,14 @@ namespace Google.ProtocolBuffers.FieldAccess
internal SinglePrimitiveAccessor(string name)
{
- PropertyInfo messageProperty = typeof (TMessage).GetProperty(name);
- PropertyInfo builderProperty = typeof (TBuilder).GetProperty(name);
+ PropertyInfo messageProperty = typeof(TMessage).GetProperty(name, ReflectionUtil.EmptyTypes);
+ PropertyInfo builderProperty = typeof(TBuilder).GetProperty(name, ReflectionUtil.EmptyTypes);
if (builderProperty == null)
{
- builderProperty = typeof (TBuilder).GetProperty(name);
+ builderProperty = typeof(TBuilder).GetProperty(name, ReflectionUtil.EmptyTypes);
}
- PropertyInfo hasProperty = typeof (TMessage).GetProperty("Has" + name);
- MethodInfo clearMethod = typeof (TBuilder).GetMethod("Clear" + name, EmptyTypes);
+ PropertyInfo hasProperty = typeof(TMessage).GetProperty("Has" + name, ReflectionUtil.EmptyTypes);
+ MethodInfo clearMethod = typeof(TBuilder).GetMethod("Clear" + name, ReflectionUtil.EmptyTypes);
if (messageProperty == null || builderProperty == null || hasProperty == null || clearMethod == null)
{
throw new ArgumentException("Not all required properties/methods available");
@@ -75,9 +73,9 @@ namespace Google.ProtocolBuffers.FieldAccess
clrType = messageProperty.PropertyType;
hasDelegate =
(Func<TMessage, bool>)
- Delegate.CreateDelegate(typeof (Func<TMessage, bool>), null, hasProperty.GetGetMethod());
+ Delegate.CreateDelegate(typeof(Func<TMessage, bool>), null, hasProperty.GetGetMethod());
clearDelegate =
- (Func<TBuilder, IBuilder>) Delegate.CreateDelegate(typeof (Func<TBuilder, IBuilder>), null, clearMethod);
+ (Func<TBuilder, IBuilder>) Delegate.CreateDelegate(typeof(Func<TBuilder, IBuilder>), null, clearMethod);
getValueDelegate = ReflectionUtil.CreateUpcastDelegate<TMessage>(messageProperty.GetGetMethod());
setValueDelegate = ReflectionUtil.CreateDowncastDelegate<TBuilder>(builderProperty.GetSetMethod());
}