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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T05:45:50+00:00 2026-06-13T05:45:50+00:00

I have a static helper clone method of a specific base type which doesn’t

  • 0

I have a static helper clone method of a specific base type which doesn’t allow me to set a base property setter.

public static T Clone<T>(this T source, DomainKey cloneKey)
    where T : DomainObjectWithKey
{
    T clone = source.Clone(); // binary formatter returns object of type T
    clone.Key = cloneKey; // this does not compile
    return (T)clone;
}

public class DomainObjectWithKey
{
    public DomainKey Key { get; protected set; }

The alternative solution was to put the Clone method inside the class itself, which then allowed me to use the protected setter. However, I then have to specify when calling Clone from my derived objects, which seemed pointless.

Therefore my question is, is it due to encapsulation that I can’t call the protected setter method from a static method?

Example of the alternative solution but why do I have to specify the type?

category.Clone<Category>(otherCategory.Key); // why do I have to specify <Category> here?

public class Category : DomainObjectWithKey
{
    public long CategoryId { get { return ((IdDomainKey)Key).Id; } }

    public Category(long categoryId)
    {
        Key = new IdDomainKey(categoryId);
    }
}

Solution

I ended up with having a public property so the Key could be accessed from an instance of a derived class but protected internal for the setter which allowed the static helper method to set the property.

public class DomainObjectWithKey
{
    public DomainKey Key { get; protected internal set; }
  • 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-13T05:45:51+00:00Added an answer on June 13, 2026 at 5:45 am

    protected means that it is visible to the subclasses of DomainObjectWithKey. Your Clone method appears to be outside of DomainObjectWithKey.

    Maybe you’re looking for internal? internal allows you access to the member from within the same DLL.

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

Sidebar

Related Questions

I have an object obj that is passed into a helper method. public static
I have static method which returns me as it's name says data from domain
I have a static helper method that I wrap around SMTPClient to send email.
I currently have a helper class that I am using to obfuscate a static
Why can we have static final members but cant have static method in an
I intended to create a class which only have static members and static functions.
I have the following function call: public static MvcHtmlString NavLinks( this HtmlHelper helper, IList<MenuItem>
I have written an ASP.NET HttpModule and I have a static helper class that
I have built a database helper class with an open() method and extended sqlite
I have this static helper function: public static DependencyObject GetParentObject(DependencyObject child) { if (child

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.