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

  • Home
  • SEARCH
  • 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 494563
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T05:30:29+00:00 2026-05-13T05:30:29+00:00

I have a public class I’m defining that will eventually be part of an

  • 0

I have a public class I’m defining that will eventually be part of an API, so it has to have certain public properties. However, I also want some of the properties to be read-only unless they’re created from within my own projects (e.g., if a user has our API, they can create a User object, but they can’t write to its ID field, which will be filled in only if we pull it from the database).

My thought was to have two separate assemblies using the same namespace, the “public” DLL and the “private” DLL. The prototype in the public DLL will look like:

namespace CompanyName
{
  public partial class User
  {
    public Id { get; }
    public Name { get; set; }
  }
}

and the private DLL will have this:

namespace CompanyName
{
  public partial class User
  {
    public Id { set; }
  }
}

Would this work? If not, what’s a better way to do this?

  • 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-13T05:30:29+00:00Added an answer on May 13, 2026 at 5:30 am

    Partial classes cannot span assemblies, so this will not work.

    You could define your class as:

    namespace CompanyName
    {
        public class User
        {
            public Id {get;internal set;}
            public Name {get;set;}
        }
    }
    

    This would mean that only code with internal access to your class could set the value of Id property. If you need to set it from outside your assembly, make sure your assemblies are strong-named and you can then use the InternalsVisibleTo attribute to give internal access to your assembly to another one of your assemblies (the one setting the value of Id).


    I’ve recently had to do something very similar to this for an API I work on. Our API is defined mainly using interfaces, so I was able to achieve this by having a Public API project that is the public part, and an Internal API project that forms the API used by our internal code, with internal interfaces deriving from the public ones. The implementations of the API interfaces implement both interfaces, meaning our internal code can then access parts of the API that are not public.

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

Sidebar

Related Questions

Here is the domain that I wish to have: public class Person { public
I have a user defined class that I want to create a public List
I have a class that has a Generic type G In my class model
I have public class ViewModel1 { // some properties here public List<ViewModel2> ViewModel2 {get;
I have public properties of a class and my output detail line is being
Suppose I have: public class foobar { public int lorem; public int ipsum; }
Suppose I have public class Product: Entity { public IList<Item> Items { get; set;
In c# you can have public class Foo { public Foo(string name) { //do
For example is it better to have: public class Case : EntityIdentifiable { public
I have in my WPF project file RssInfo.cs in which I have public class

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.