aboutsummaryrefslogtreecommitdiff
path: root/csharp/src/ProtocolBuffers/FieldAccess/SinglePrimitiveAccessor.cs
diff options
context:
space:
mode:
Diffstat (limited to 'csharp/src/ProtocolBuffers/FieldAccess/SinglePrimitiveAccessor.cs')
-rw-r--r--csharp/src/ProtocolBuffers/FieldAccess/SinglePrimitiveAccessor.cs12
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);
}