diff options
author | Jon Skeet <skeet@pobox.com> | 2009-11-03 16:51:01 +0000 |
---|---|---|
committer | Jon Skeet <skeet@pobox.com> | 2009-11-03 16:51:01 +0000 |
commit | b49d3c7834c9448e137d88c510f30963661ff7d9 (patch) | |
tree | 621c1e2306bfb99a98b7c29aa723327f7d137c51 /src/ProtocolBuffers/FieldAccess/RepeatedPrimitiveAccessor.cs | |
parent | 0aac0e4fe3a329431fa58710c780b02748c07301 (diff) | |
download | protobuf-b49d3c7834c9448e137d88c510f30963661ff7d9.tar.gz protobuf-b49d3c7834c9448e137d88c510f30963661ff7d9.tar.bz2 protobuf-b49d3c7834c9448e137d88c510f30963661ff7d9.zip |
Support Compact Framework 3.5
Diffstat (limited to 'src/ProtocolBuffers/FieldAccess/RepeatedPrimitiveAccessor.cs')
-rw-r--r-- | src/ProtocolBuffers/FieldAccess/RepeatedPrimitiveAccessor.cs | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/src/ProtocolBuffers/FieldAccess/RepeatedPrimitiveAccessor.cs b/src/ProtocolBuffers/FieldAccess/RepeatedPrimitiveAccessor.cs index e5bb411a..6bae59cb 100644 --- a/src/ProtocolBuffers/FieldAccess/RepeatedPrimitiveAccessor.cs +++ b/src/ProtocolBuffers/FieldAccess/RepeatedPrimitiveAccessor.cs @@ -35,7 +35,7 @@ using System.Reflection; namespace Google.ProtocolBuffers.FieldAccess { /// <summary> - /// Accesor for a repeated field of type int, ByteString etc. + /// Accessor for a repeated field of type int, ByteString etc. /// </summary> internal class RepeatedPrimitiveAccessor<TMessage, TBuilder> : IFieldAccessor<TMessage, TBuilder> where TMessage : IMessage<TMessage, TBuilder> @@ -49,7 +49,9 @@ namespace Google.ProtocolBuffers.FieldAccess { private readonly Func<TMessage, int> countDelegate; private readonly MethodInfo getElementMethod; private readonly MethodInfo setElementMethod; - + + // Replacement for Type.EmptyTypes which apparently isn't available on the compact framework + internal static readonly Type[] EmptyTypes = new Type[0]; /// <summary> /// The CLR type of the field (int, the enum type, ByteString, the message etc). @@ -64,7 +66,7 @@ namespace Google.ProtocolBuffers.FieldAccess { 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, Type.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 }); @@ -78,9 +80,9 @@ namespace Google.ProtocolBuffers.FieldAccess { || setElementMethod == null) { throw new ArgumentException("Not all required properties/methods available"); } - clearDelegate = (Func<TBuilder, IBuilder>)Delegate.CreateDelegate(typeof(Func<TBuilder, IBuilder>), clearMethod); + clearDelegate = (Func<TBuilder, IBuilder>)Delegate.CreateDelegate(typeof(Func<TBuilder, IBuilder>), null, clearMethod); countDelegate = (Func<TMessage, int>)Delegate.CreateDelegate - (typeof(Func<TMessage, int>), 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()); |