diff options
author | Jie Luo <anandolee@gmail.com> | 2015-04-30 18:19:50 -0700 |
---|---|---|
committer | Jie Luo <anandolee@gmail.com> | 2015-04-30 18:19:50 -0700 |
commit | 6e1ec5f6eaf79563aba0d220e36547afe15f0dd6 (patch) | |
tree | 2b2df2dcb2b086bbf4017bc7606a70721c04f8e6 /csharp/src/ProtocolBuffers/FieldAccess/SinglePrimitiveAccessor.cs | |
parent | 24ae5105f3bd44d39303d7e76edb659cca01f97b (diff) | |
download | protobuf-6e1ec5f6eaf79563aba0d220e36547afe15f0dd6.tar.gz protobuf-6e1ec5f6eaf79563aba0d220e36547afe15f0dd6.tar.bz2 protobuf-6e1ec5f6eaf79563aba0d220e36547afe15f0dd6.zip |
fix commends from Jon Skeet
Diffstat (limited to 'csharp/src/ProtocolBuffers/FieldAccess/SinglePrimitiveAccessor.cs')
-rw-r--r-- | csharp/src/ProtocolBuffers/FieldAccess/SinglePrimitiveAccessor.cs | 12 |
1 files changed, 5 insertions, 7 deletions
diff --git a/csharp/src/ProtocolBuffers/FieldAccess/SinglePrimitiveAccessor.cs b/csharp/src/ProtocolBuffers/FieldAccess/SinglePrimitiveAccessor.cs index b964066d..df9dedaf 100644 --- a/csharp/src/ProtocolBuffers/FieldAccess/SinglePrimitiveAccessor.cs +++ b/csharp/src/ProtocolBuffers/FieldAccess/SinglePrimitiveAccessor.cs @@ -58,9 +58,8 @@ namespace Google.ProtocolBuffers.FieldAccess get { return clrType; }
}
- internal SinglePrimitiveAccessor(FieldDescriptor fieldDesriptor, string name, bool supportFieldPresence)
+ internal SinglePrimitiveAccessor(FieldDescriptor fieldDescriptor, string name, bool supportFieldPresence)
{
- field = fieldDesriptor;
PropertyInfo messageProperty = typeof(TMessage).GetProperty(name, null, ReflectionUtil.EmptyTypes);
PropertyInfo builderProperty = typeof(TBuilder).GetProperty(name, null, ReflectionUtil.EmptyTypes);
MethodInfo clearMethod = typeof(TBuilder).GetMethod("Clear" + name);
@@ -77,8 +76,11 @@ namespace Google.ProtocolBuffers.FieldAccess throw new ArgumentException("Has properties not available");
}
hasDelegate = ReflectionUtil.CreateDelegateFunc<TMessage, bool>(hasProperty.GetGetMethod());
+ } else
+ {
+ hasDelegate = message => !GetValue(message).Equals(fieldDescriptor.DefaultValue);
}
-
+
clrType = messageProperty.PropertyType;
clearDelegate = ReflectionUtil.CreateDelegateFunc<TBuilder, IBuilder>(clearMethod);
getValueDelegate = ReflectionUtil.CreateUpcastDelegate<TMessage>(messageProperty.GetGetMethod());
@@ -87,10 +89,6 @@ namespace Google.ProtocolBuffers.FieldAccess public bool Has(TMessage message)
{
- if (hasDelegate == null)
- {
- return !GetValue(message).Equals(field.DefaultValue);
- }
return hasDelegate(message);
}
|