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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T18:07:51+00:00 2026-05-16T18:07:51+00:00

If I have some types e.g: public class SomeType //Generated by some codegen i

  • 0

If I have some types e.g:

public class SomeType //Generated by some codegen i won't to change that.
{
    string C { get; set; }        
}

public class AnotherType : SomeType
{
    string A { get; set; }
    string B { get; set; }
}

Is it possible to assign property C automatically? For example when properties A and B get assigned or when I am Casting this type to some another type, or somehow else?

Basically for example I want to execute some logic to automatically assign property C according to values A and B at some point when properties values A and B get populated.

Is there any another ways of doing that rather than using standard properties?

I was thinking that it is possible to do some king of magic when i may cast type AnotherType to SomeType, but i cant implement implicit operator where i may put this conversion logic “from A+B to C” because compiler doesn’t allow implicit operator for related types.

Now Only way i see it is remove inheritance and implement implicit operator for AnotherType to SomeType conversion, but the evil in that case i need to duplicate all properties of type SomeType within type AnotherType and i need to change type AnotherType manually every time when SomeType getting changed.

  • 1 1 Answer
  • 2 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-16T18:07:51+00:00Added an answer on May 16, 2026 at 6:07 pm

    This is possible using auto-implemented properties. You could use the setter of B to assign a value to C:

    public class SomeType
    {
        public string A { get; set; }
        public string C { get; set; }
    
        private string _b;
        public string B 
        { 
            get { return _b; } 
            set 
            { 
                // Set B to some new value
                _b = value; 
    
                // Assign C
                C = string.Format("B has been set to {0}", value);
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some custom type: [RdfSerializable] public class Item { [RdfProperty(true)] public string Name
I think I'm asking about covariant return types. I have some generated code that
Lets say I have an object class Person { public string Name { get;
I have some types which are generated by a web service reference. I want
Suppose I have objects that have a parent-child relationship like this: public class Node
I have some types with a sequence inside, which does restrict the order of
I have some complex types here so I decided to use nifty trick to
I need to develop a site on Drupal 7. I have some content types
I have some problems with OpenCV s cvCanny(...) and the Image data types it
I currently have some action associated with when the user types something in a

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.