Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeAccessor.WriteSetter throws exception, if property setter is not public #2

Open
GoogleCodeExporter opened this issue Oct 15, 2015 · 4 comments

Comments

@GoogleCodeExporter
Copy link

The method TypeAccessor.WriteSetter throws an ArgumentNullException, if the 
target type has a property with a non-public setter. (Line 141: 
http://code.google.com/p/fast-member/source/browse/FastMember/TypeAccessor.cs#14
1)

Example:
class TestTarget
{
    public int Id { get; private set; }
}


I am not sure why `prop.GetSetMethod()` returns `null`, although 
`prop.CanWrite` obviously returned `true` in line 129.

Original issue reported on code.google.com by [email protected] on 27 Jan 2012 at 8:22

@GoogleCodeExporter
Copy link
Author

Not sure if this is the best (fastest) way, but adding this at line 130 fixes 
this:

var setMethod = prop.GetSetMethod();
if (setMethod == null || !setMethod.IsPublic) continue;

http://code.google.com/p/fast-member/source/browse/FastMember/TypeAccessor.cs#13
0

Original comment by [email protected] on 5 Feb 2012 at 10:30

@GoogleCodeExporter
Copy link
Author

[deleted comment]

@GoogleCodeExporter
Copy link
Author

I think this line:

   if (prop.GetIndexParameters().Length != 0 || !prop.CanWrite) continue;

should be:

   if (prop.GetIndexParameters().Length != 0 || !prop.CanWrite || !prop.GetSetMethod().IsPublic) continue;

It seems the intention there is that CanWrite would return false if the 
property is not writeable, in fact all that CanWrite checks for is the 
existence of a set method, it does not however check the availability of that 
method.

Original comment by [email protected] on 28 Feb 2012 at 8:17

@GoogleCodeExporter
Copy link
Author

I added a simple test that verifies this issue, and a fairly simple fix as 
well.  I wasn't sure how to contribute (or if I could) code to this project, so 
I created a couple of diff files (using hg diff) and I've attached them here.

Original comment by [email protected] on 28 Feb 2012 at 8:42

Attachments:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant