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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T04:32:29+00:00 2026-05-21T04:32:29+00:00

As a part of learning process, I am writing simple IM app, using Remoting

  • 0

As a part of learning process, I am writing simple IM app, using Remoting in .NET. As of now it is simple console app and it works as i expect. Thinking about next features/functionalities, I’ve stuck in a situation represented by the code below:

public static class UserManager {
  public static started { get; private set; }
  private static List<User> users;
  static UserManager() {
    users = List<User>();
    started = true;
  }
  public static addUser(int _userID) {}
  public static activateUser(int _userID) {
    foreach (User u in users) {
      if (u.userID == _userID) {
        u.setActive();
        break;
      }
    }
  }
}

class User {
  public int userID { get; private set; }
  public bool active { get; private set; }
  public User(int _userID) {
    userID = _userID;
  }
  public void setActive() {
    // only UserManager should be allowed to modify user state
  }
}

I want to make only UserManager static class be allowed to modify states of it’s users list. I was thinking about “friend” clause but as I understand, there is no such construct in C#. Would it be enough just checking (inside User class methods), if calling “object” is of class UserManager?

I would appreciate any input/advice, including those saying “don’t do that as You try to do, better make it using..”

PS. Didn’t know which Title should i choose, feel free (more experienced programmers/so users) to change it if ther is more accurate.

  • 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-21T04:32:30+00:00Added an answer on May 21, 2026 at 4:32 am

    You can put the UserManager and User classes in their own assembly and mark parts of the API as internal (which is the equivalent of VB’s Friend). This enables you to restrict access from outside that assembly.

    Another way to restrict access is by doing role based security. .NET has the PrincipalPermissionAttribute for this:

    public static class UserManager 
    {
        [PrincipalPermission(SecurityAction.Demand, 
            Role = "Administrators")]
        public static void AddUser(int userId) { }
    }
    

    Note that this will only work when you know the role of the user, but it is especially useful in scenario’s such as web sites (ASP.NET WebForms / MVC) and web services (WCF) were users normally log on.

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

Sidebar

Related Questions

I'm learning about change listeners and would like to find out why a part
I'm trying to pick up Python. As part of the learning process I'm porting
I've put off using generated code as part of the build process for fear
As part of my learning process, I thought it would be good if I
As part of my EXTJS 4 learning process, I am trying to establish a
As part of learning ruby/rails, I'm trying to implement http://github.com/professionalnerd/simple-private-messages into my application from
As a part of learning CSS (& practically applying it — by creating simple
I'm trying to be a bit sneeky and as part of a learning process
I just started learning Scala, and as part of the process, I've been trying
I am new to ASP MVC and as part of learning i was developing

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.