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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T13:06:58+00:00 2026-05-22T13:06:58+00:00

I am having a piece of code in which i delegate certain properties of

  • 0

I am having a piece of code in which i delegate certain properties of a class to another class if the class exists. Below you see the start time being defined on the TimeProvider if it exists.

public override DateTime StartTime
{
   get
   {
       return (TimeProvider != null) ? TimeProvider.StartTime : base.StartTime;
   }
   set
   {
       if (TimeProvider != null)
       {
           TimeProvider.StartTime = value;
       }
       else
       {
           base.StartTime = value;
       }
    }
 }

Now my ‘problem’ is that i have a lot more properties (like endtime,currentime) i delegate to the TimeProvider if it is not null. So i would like to have code like:

public override DateTime StartTime
{
   get
   {
       return GetTime(()=>StartTime);
   }
   set
   {
       SetTime(()=>StartTime)
    }
 }

Where the ()=>StartTime expression is sometimes ‘evaluated’ on the TimeProvider and sometimes on the class itself (they share a baseclass). Can something like this be done? Preferably without using reflection.

  • 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-22T13:06:58+00:00Added an answer on May 22, 2026 at 1:06 pm

    Cake

    public class Foo
    {
        private string _string1;
        public Foo foo { get; set; }
    
        private T GetProperty<T>(Func<Foo,T> getter)
        {
            return foo == null
                       ? getter(this)
                       : getter(foo);
        }
    
        private void SetProperty(Action<Foo> setter)
        {
            if (foo == null)
                setter(this);
            else
                setter(foo);
        }
    
        public string String1
        {
            get { return GetProperty(a => a._string1); }
            set { SetProperty(a => a._string1 = value); }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm having some problems with a certain piece of code which sits in my
I have the below piece of code which Prefixs a string to the start
I'm having some problems with this piece of code. I've included a class declaration
I am having problem getting this piece of code to run. The class is
iam having controller like below which is not registered in routes table public class
I have the following piece of code which uses the ALAssets library to store
I have a piece of code in my game which looks a lot like
I'm having a really odd issue. I'm reusing a piece of code that was
I am having a problem with a bit of code in a piece of
I am having a bit of trouble understanding this piece of code. It is

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.