• Code
  • Tags
  • Users
  • Titles
  • Log in
  • Feedback
  • FAQ
Share Code
Welcome to ForkCan.com

ForkCan is all about sharing code in a social way.

Discuss, debate or argue with other devs about their or your own code.

Give other devs feedback or make a Fork (Make a better version of a shared code).

Rate the code, if you use the code mark it as used so others can see if the shared code is used by someone.

Help each other to be better devs and to be more productive.


Features not working yet:

Flag a post


QR Code

Tiny Url

http://4kcan.com/s/MzEx

Related Code
Generic Entity Framework 4.0 Base Repository
ForEach Extension method for IEnumerable<T>
Invoke Extension Method
Use of Extension methods to hide "infrastructure code"
Unity Service Locator for ASP.NET MVC 3.0 Beta 1
Null Dot "Operator" Extension Method
Generic Entity Framework 4.0 Base Repository with Paging
Generic linq-to-sql repository
WCF RIA Services Unity 2.0 DomainService Factory
A Default Entity Framework 4.0 ObjectContext Factory
UnitOfWork Action filter for ASP.NET MVC and nHibernate
Make sure the web.config pages/namespace can be used together with ASP.NET MVC 3 P1 and Razor
Custom C# exception class
Email validation with Regular Expression
Url Validation with Regular Expression
Method to hash passwords
Number of sealed / unsealed types in the framework
Extension to the HttpClient

Reflection dynamically get private fields or properties

Use Reflection to dynamically get private fields or properties. The BindingFlags are important on private fields.

0
553 0 0 0 0 0

class ReflectionTest
{
    //Private fields
    private String stringField = "stringField string";
    private Int32 int32Field = 12345;

    //Public properties
    public String StringProperty { get; set; }
    public Int32 Int32Property { get; set; }

    public Object GetFieldFromName(String fieldName)
    {
        return this.GetType().GetField(fieldName, BindingFlags.NonPublic | BindingFlags.Instance).GetValue(this);
    }

    public Object GetPropertyFromName(String propertyName)
    {
        return this.GetType().GetProperty(propertyName).GetValue(this, null);
    }
}

Share: twitter | facebook   Action: used | fork | flag

.net

Mark '.net' tag as 'like'

Mark '.net' tag as 'ignore'

c#

Mark 'c#' tag as 'like'

Mark 'c#' tag as 'ignore'

reflection

Mark 'reflection' tag as 'like'

Mark 'reflection' tag as 'ignore'


 @najklord
100
October 13, 2010 7:23 PM

Fork

 Reflection dynamically get private fields or properties -  @najklord Wednesday 13, 2010 7:23 PM


0 Feedback


You must log in before you can give any feedback


0 Discussion(s)

Newest Oldest

You must log in before you can post a comment

Squeed
Made by: Fredrik Normén 2010