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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T22:53:39+00:00 2026-05-26T22:53:39+00:00

I got a list of different objects that I defined in different classes and

  • 0

I got a list of different objects that I defined in different classes and I’d like to add a string property “Name” to all these objects. Is that possible ?

I don’t have that much code to provide as my classes are very simple/classic ones.

Thanks in advance for any help !

(edit : I don’t want to inherit from an abstract class that adds this property ! In fact, I don’t want to modify at all my class that define my object. That’s what i call “Dynamically” in the title.

What I want is something like :

myObject.AddProperty(string, "Name");

or

myObject.AddAttribute(string, "Name");

(I don’t know how it is exactly called)

and then I can do :

myObject.Name = "blaaa";
  • 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-26T22:53:39+00:00Added an answer on May 26, 2026 at 10:53 pm

    Create an abstract class that all of your other classes could inherit:

    public abstract class MyBaseClass
    {
        public string MyCommonString { get; set; }
    }
    
    public class Foo : MyBaseClass
    {
        public MyBaseClass() { }
    }
    
    //Create instance of foo
    Foo myFoo = new Foo();
    
    //MyCommonString is accessible since you inherited from base
    string commonString = myFoo.MyCommonString;
    

    EDIT (per new requirement)

    Since you don’t want to touch the original classes in the DLL, I’d take this [similar] approach:

    public abstract class MyBaseClass
    {
        public string MyCommonString { get; set; }
    }
    
    //This class definition lives in the DLL and remains untouched
    public class Foo
    {
        public Foo() { }
    }
    
    //This partial class definition lives in [insert new project name here]
    public partial class Foo : MyBaseClass
    {
        public Foo () { }
    }
    

    Notice that Foo is now a partial class. You’re not touching the existing class definition in the DLL, you’re extending it.

    EDIT (per newer new requirement)

    Given your requirements (no editing of original class), what you’re asking is not possible.

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

Sidebar

Related Questions

I've got a repeater looping through a list of objects that are of different
I've got two List<Name> s: public class Name { public string NameText {get;set;} public
I've got a list of frequently used hex colors that I'd like to list
I've got a function that checks a list of objects to see if they've
I've got an XML response that looks like: <?xml version=1.0 encoding=utf-8?> <response> <scheme> <name>name_1</name>
I got a list that contains al the status items of each order. The
I've got a list in a Python program that contains a series of numbers,
I've got a list of points, and a route that an external provider has
I've got a list of People that are returned from an external app and
I've got a list of UserControl objects; when a menu option is clicked to

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.