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

  • Home
  • SEARCH
  • 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 8535319
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T10:24:14+00:00 2026-06-11T10:24:14+00:00

So I have a c# class with three properties on it. public class ClassA

  • 0

So I have a c# class with three properties on it.

public class ClassA
{
    public bool IsBool1;
    public bool IsBool2;
    public bool IsBool3;
}

I have a method that does the following.

public void MethodA()
{
    ClassA c = GetCurrentClassA();
    c.IsBool1 = !c.IsBool1;
    ClassADataAccess.Update(c);
    this.BindClassADetails(c);
}

Now to keep from writing MethodA over for the other two properties is there a way to write a method that can handle all three?

Something maybe like this?

public void UpdateAndBind(bool value)
{
    ClassA c = GetCurrentClassA();

    ///what to do here to set the property?

    ClassADataAccess.Update(c);
    this.BindClassADetails();
}
  • 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-11T10:24:15+00:00Added an answer on June 11, 2026 at 10:24 am

    In response to your comment:

    That could work perfectly fine, I was just curious as to whether or not there is a way to tell a method which property on a passed in object to set. – Chris Whisenhunt

    There is a way using reflection:

        // using a generic method, you can specify the name of the property you want to set, 
        // the instance you want it set on, and the value to set it to...
        private T SetProperty<T>(T instance, string propertyName, object value)
        {
            Type t = typeof(T);
            PropertyInfo prop = t.GetProperty(propertyName);
            prop.SetValue(instance, value, null);
            return instance;
        }
    

    Now…you may want to use try/catch, also perhaps inspect what’s being passed in before using it in various ways to ensure it will not jut blow up…but generally, and most simplistically, that is the way you’d do it.
    Good Luck!

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

Sidebar

Related Questions

Say I have a class with three string properties: public class Foo { public
I have a following class structure: public class A { public bool Property1 {
Basically I have some class objects, each with three properties. Once one class object
Say I have a class with three constructors, like the one below: public class
Assume that I have three class; UserAccount, UserGroup and Role. UserGroup and Role are
I have a Query class that has a number of properties that are collections
Suppose I have a definition for a door: class Door { public void Lock()
I have an object with 2 properties: public class Request { public int TypeId
I have a model that looks something like this: public class SampleModel { public
I have a library base class ( Controller ) and three sub-classes that inherit

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.