aboutsummaryrefslogtreecommitdiffhomepage
path: root/csharp/src/Google.Protobuf/Compatibility/PropertyInfoExtensions.cs
diff options
context:
space:
mode:
Diffstat (limited to 'csharp/src/Google.Protobuf/Compatibility/PropertyInfoExtensions.cs')
-rw-r--r--csharp/src/Google.Protobuf/Compatibility/PropertyInfoExtensions.cs19
1 files changed, 17 insertions, 2 deletions
diff --git a/csharp/src/Google.Protobuf/Compatibility/PropertyInfoExtensions.cs b/csharp/src/Google.Protobuf/Compatibility/PropertyInfoExtensions.cs
index 934424f8..8a6fefa7 100644
--- a/csharp/src/Google.Protobuf/Compatibility/PropertyInfoExtensions.cs
+++ b/csharp/src/Google.Protobuf/Compatibility/PropertyInfoExtensions.cs
@@ -34,16 +34,31 @@ using System.Reflection;
namespace Google.Protobuf.Compatibility
{
+ /// <summary>
+ /// Extension methods for <see cref="PropertyInfo"/>, effectively providing
+ /// the familiar members from previous desktop framework versions while
+ /// targeting the newer releases, .NET Core etc.
+ /// </summary>
internal static class PropertyInfoExtensions
{
+ /// <summary>
+ /// Returns the public getter of a property, or null if there is no such getter
+ /// (either because it's read-only, or the getter isn't public).
+ /// </summary>
internal static MethodInfo GetGetMethod(this PropertyInfo target)
{
- return target.GetMethod;
+ var method = target.GetMethod;
+ return method != null && method.IsPublic ? method : null;
}
+ /// <summary>
+ /// Returns the public setter of a property, or null if there is no such setter
+ /// (either because it's write-only, or the setter isn't public).
+ /// </summary>
internal static MethodInfo GetSetMethod(this PropertyInfo target)
{
- return target.SetMethod;
+ var method = target.SetMethod;
+ return method != null && method.IsPublic ? method : null;
}
}
}