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 544905
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T10:42:16+00:00 2026-05-13T10:42:16+00:00

Why can reflection access protected/private member of class in C#? Is this not safe

  • 0

Why can reflection access protected/private member of class in C#?

Is this not safe for the class, why is reflection given such power? Is this an anti-pattern?

  • 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-05-13T10:42:17+00:00Added an answer on May 13, 2026 at 10:42 am

    This is necessary for scenarios such as remoting, serialization, materialization, etc. You shouldn’t use it blindly, but note that these facilities have always been available in any system (essentially, by addressing the memory directly). Reflection simply formalises it, and places controls and checks in the way – which you aren’t seeing because you are presumably running at “full trust”, so you are already stronger than the system that is being protected.

    If you try this in partial trust, you’ll see much more control over the internal state.

    Is it an anti-pattern?

    Only if your code uses it inappropriately. For example, consider the following (valid for a WCF data-contract):

    [DataMember]
    private int foo;
    
    public int Foo { get {return foo;} set {foo = value;} }
    

    Is it incorrect for WCF to support this? I suspect not… there are multiple scenarios where you want to serialize something that isn’t part of the public API, without having a separate DTO. Likewise, LINQ-to-SQL will materialize into private members if you so elect.

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

Sidebar

Related Questions

How can I test a private method of an abstract class using reflection (using
How can I access an inherited protected field from an object by reflection?
How can I access a private field of an inner class in another package
I know that we can access private constructor via reflection as @Sanjay T. Sharma
In general reflection in a base class can be put to some good and
How can I generate types like these using the System.Reflection.Emit libraries: public class Test<T>
On .NET, I can use reflection to load a DLL library at runtime. This
In .NET, using reflection how can I get class variables that are used in
So I need to get a class using reflection, because it is a private
Is there any way to access Javadoc information via reflection, the way annotations can

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.