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

The Archive Base Latest Questions

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

I am mainly interested in the design decision behind this. background information: FileSystemInfo is

  • 0

I am mainly interested in the design decision behind this.

background information:
FileSystemInfo is base class to (and only to) FileInfo and DirectoryInfo.
Both classes implement GetAccessControl(), returning a FileSecurity or DirectorySecurity object respectively.
FileSecurity and DirectorySecurity both derive from FileSystemSecurity – and again are the only classes to do so.
Neither FileSecurity nor DirectorySecurity seem to declare any methods or properties of their own – apart from constructors.

Yet still, FileSystemInfo does not contain a public FileSystemSecurity GetAccessControl() method.

Question:
Can anybody shed some light onto why FileSystemInfo does not contain this method?

example code

public static void GrantFullControlToBuiltinUsers(this FileSystemInfo fileSystemInfo)
{
    FileSystemSecurity acFile;

    if(fileSystemInfo is DirectoryInfo)
        acFile = ((DirectoryInfo) fileSystemInfo).GetAccessControl();
    else
        acFile = ((FileInfo)fileSystemInfo).GetAccessControl();


    acFile.AddAccessRule(
        new FileSystemAccessRule(GetAccountNameBuiltinUsers(),
                                    FileSystemRights.FullControl,
                                    AccessControlType.Allow));


    if (fileSystemInfo is DirectoryInfo)
        ((DirectoryInfo)fileSystemInfo).SetAccessControl((DirectorySecurity)acFile);
    else
        ((FileInfo)fileSystemInfo).SetAccessControl((FileSecurity)acFile);
}

The code is far from beautiful with all the (unnecessary) casts in it and I wondered why the library was designed in this way.

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

    My guess is that they wanted to have the two GetAccessControl methods return the proper, concrete types – FileSecurity and DirectorySecurity, respectively. If they inherited from a common GetAccessControl() method, they would be forced to return FileSystemSecurity, and the user would have to cast it manually.

    It’s an aesthetic choice, mostly.

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

Sidebar

Related Questions

UPDATE: Perhaps this wasn't clear from my original post, but I'm mainly interested in
I'm mainly asking this to professionals who know the playing field of professional developing.
This question is mainly to verify my current idea. I have a series of
I'm mainly interested in the English language characters and punctuation. I need it for
I am currently reading a book on PHP/MySQL. I'm mainly interested in the hashing
I am a novice programmer who mainly uses Java. Recently I have become interested
I'm mainly interested in the simple goal of getting a C program to I
How to detect network drive mount event using wmi ? I'm mainly interested i
I am very interested in human computer interactions and mainly web interaction. Can you
I am mainly interested in the 'integration features' between the IDE and the application

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.