Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7880193
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T04:05:07+00:00 2026-06-03T04:05:07+00:00

I am writing a class that generates WPF bindings for properties based on their

  • 0

I am writing a class that generates WPF bindings for properties based on their accessibility. Here is the key method:

static Binding getBinding(PropertyInfo prop)
{
    var bn = new Binding(prop.Name);
    bn.UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged;
    if (prop.CanRead && prop.CanWrite)
        bn.Mode = BindingMode.TwoWay;
    else if (prop.CanRead)
        bn.Mode = BindingMode.OneWay;
    else if (prop.CanWrite)
        bn.Mode = BindingMode.OneWayToSource;
    return bn;
}

However, this is not working as expected. CanWrite is true when it should be false. For instance, for this property:

abstract class AbstractViewModel {
    public virtual string DisplayName { get; protected set; }
}

class ListViewModel : AbstractViewModel {
    //does not override DisplayName
}

I find that the DisplayName property of a ListViewModel is both CanRead and CanWrite. However, if I call prop.GetAccessors(), only the get_DisplayName() accessor is listed.

What is going on here? What do CanRead and CanWrite indicate, if not the protection level of the property? What would be the correct implementation of my method?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T04:05:09+00:00Added an answer on June 3, 2026 at 4:05 am

    What do CanRead and CanWrite indicate?

    If you have a question like that you should first look at the documentation.

    CanRead:

    If the property does not have a get accessor, it cannot be read.

    CanWrite:

    If the property does not have a set accessor, it cannot be written to.

    So, the properties indicate whether there is a get and set accessor, not what their protection level is. One reason for this is that Reflection doesn’t know where are you calling it from, so it doesn’t know whether you can actually access the accessors.

    What you can do is to find out whether you can access the accessors is to call GetGetMethod() and GetSetMethod(). If the property doesn’t have public get/set accessors, they will return null.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've got a method in a class that's writing to some string, which calls
I'm writing a compiler that generates Jasmin code and want to invoke a method
I'm writing an Android app and I have a class that generates and maintains
I am writing a class that I know that needs a lock, because the
I'm writing a class that returns both a DataTable and a IEnumerable. I cannot
I'm writing a class that extends a UIScrollView to display a large tiled image,
I am writing a class that inherits from IHttpHandler for script and css combining.
I am writing a class that inherits from IHttpHandler for script and css combining.
I'm writing a factory class that should be able to return singleton instances of
I'm writing a class in C++ that I cannot debug by using F5. The

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.