using System; using System.Collections.Generic; using System.Linq; using System.Reflection; using System.Text; using Google.Protobuf; using Google.Protobuf.FieldAccess; namespace Google.Protobuf.FieldAccess { /// /// Base class for field accessors. /// /// Type of message containing the field internal abstract class FieldAccessorBase : IFieldAccessor where T : IMessage { private readonly Func getValueDelegate; internal FieldAccessorBase(string name) { PropertyInfo property = typeof(T).GetProperty(name); if (property == null || !property.CanRead) { throw new ArgumentException("Not all required properties/methods available"); } getValueDelegate = ReflectionUtil.CreateUpcastDelegate(property.GetGetMethod()); } public object GetValue(T message) { return getValueDelegate(message); } public abstract bool HasValue(T message); public abstract void Clear(T message); public abstract void SetValue(T message, object value); } }