How to check if property setter is public
Master System Design with Codemia
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.
Introduction
In C#, checking whether a property setter is public is a reflection question, not a CanWrite question. CanWrite only tells you that some setter exists; it does not tell you whether that setter is public, private, protected, or internal.
Why CanWrite Is Not Enough
Consider this property:
Reflection will report that the property is writable in the sense that a setter exists. But that setter is not public.
So this:
is not the same as:
"Can outside callers invoke the setter?"
To answer that second question, inspect the setter method itself.
The Basic Reflection Pattern
Use PropertyInfo.GetSetMethod:
This asks reflection for the setter even if it is non-public, then inspects IsPublic.
Why GetSetMethod(true) Matters
If you call:
without arguments, reflection returns only the public setter. That can be enough if all you care about is a boolean yes or no:
But if you want to distinguish between:
- no setter at all,
- non-public setter,
- and public setter,
then GetSetMethod(nonPublic: true) gives you the full picture.
A Reusable Helper
You can wrap this in a helper method:
Usage:
This is often cleaner in validation frameworks or metadata-driven code.
Other Setter Access Levels
The same setter method also exposes other access flags:
- '
IsPrivate' - '
IsFamilyforprotected' - '
IsAssemblyforinternal'
So if your real question is not just "public or not," you can inspect the exact access level:
That is useful in serializers, mappers, and tooling that treat internal or protected setters specially.
Auto-Properties and Manual Properties Work the Same Way
Reflection does not care whether the property is an auto-property or a hand-written property with a backing field. The setter still compiles into a method, and that method still carries accessibility information.
So the same reflection logic applies to:
- '
public string Name { get; set; }' - '
public string Name { get; private set; }' - or a property with a fully custom setter body.
When This Is Useful
Typical use cases include:
- serializer configuration,
- testing and code validation,
- generic UI editors,
- plugin systems,
- and runtime mapping tools.
Whenever behavior depends on whether a caller can assign through a property, the setter method is the source of truth.
Common Pitfalls
The biggest pitfall is using CanWrite and assuming it means "publicly writable." It does not.
Another mistake is calling GetSetMethod() without nonPublic: true and then being unable to tell whether the setter is missing or merely non-public.
Developers also sometimes inspect property attributes or naming conventions instead of the actual reflected setter method. The method access flags are the authoritative answer.
Finally, remember that reflection answers runtime metadata questions. It does not override language accessibility rules for ordinary code.
Summary
- '
PropertyInfo.CanWriteonly means a setter exists somewhere.' - To check public accessibility, inspect the setter method.
- '
property.GetSetMethod(nonPublic: true)plussetter.IsPublicis the reliable pattern.' - Use the same method flags to distinguish private, protected, and internal setters.
- Reflection works the same way for auto-properties and custom property implementations.

