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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T15:35:03+00:00 2026-05-23T15:35:03+00:00

I have 2 fields like private IFruit fruit; private Banana banana; An instance of

  • 0

I have 2 fields like

private IFruit fruit;
private Banana banana;

An instance of Banana is created like this:

var banana = new Banana(fruit);

I want to create an attribute for Banana fields to do the job of creating Banana instance for me!

  • 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-23T15:35:03+00:00Added an answer on May 23, 2026 at 3:35 pm

    Attributes don’t cause any code to be executed – you’ll have to use reflection to access them. If you want you could implement a base class that has this behavior, and add the reflection code to the constructor:

    abstract class AutoCreateBase
    {
        public MyBase()
        {
            // Reflection to go through the fields, find the attributes, and use Activator.CreateInstance() on each
        }
    }
    
    class MyClass : AutoCreateBase
    {
        [AutoCreate]
        private Banana banana;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this small class looking like this: private static int field1 = -
At the moment I have this code (and I don't like it): private RenderedImage
In my jsp, I have some fields like this : <html:text property=field[0] value=${fieldValue} indexed=true>
Basically, I have an arraylist declared like : private ArrayList<HashMap<String, String>> songsList = new
If I have a boolean field like: private static final boolean DEBUG = false;
like in java I have: Class.getSuperClass().getDeclaredFields() how I can know and set private field
I have few text fields like SSN , phone number and email id. I
Say i have a few fields like the following: abd738927 jaksm234234 hfk342 ndma0834 jon99322
I have fields in the column that look like so: 2/8B, 3, 3/8B, 4/8B,
I have a class with fields like firstname, age, school etc. I need 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.