Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Equivalent of the C++ "friend" class modifier

Equivalent of the C++ "friend" class modifier

Scheduled Pinned Locked Moved C#
csharpc++helpquestion
4 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Q Offline
    Q Offline
    Quimbly
    wrote on last edited by
    #1

    Is there such a thing in C#? I know of the internal class modifier, but I want to grant "friend"-like access to a particular class from a different assembly. The reasons why I need this are long an involved, and the company I work for won't budge on the issue, so I need to find a way to make this work. Any ideas? Thanks.

    R S 2 Replies Last reply
    0
    • Q Quimbly

      Is there such a thing in C#? I know of the internal class modifier, but I want to grant "friend"-like access to a particular class from a different assembly. The reasons why I need this are long an involved, and the company I work for won't budge on the issue, so I need to find a way to make this work. Any ideas? Thanks.

      R Offline
      R Offline
      Rob Graham
      wrote on last edited by
      #2

      Not possible with top-level types in C#. There is no real eqivalent to c++ friend access level. Your only alternative would be to derive the class that needs access from a puplic top level class that contains the class you want to access as a protected or protected internal class, which is a kludge that sort of defeats the pupose of not making the class you need access to public in the first place. What is your employer REALLY trying to accomplish here? Do you need access to the entire class, or just a few methods? Do you need to instantiate the class in the other assembly? Would a public wrapper class containing an instance the 'protected' class and exposing only the desired methods suffice (i.e. a facade)?- expose the facade class via a public class factory... Anger is the most impotent of passions. It effects nothing it goes about, and hurts the one who is possessed by it more than the one against whom it is directed. Carl Sandburg

      1 Reply Last reply
      0
      • Q Quimbly

        Is there such a thing in C#? I know of the internal class modifier, but I want to grant "friend"-like access to a particular class from a different assembly. The reasons why I need this are long an involved, and the company I work for won't budge on the issue, so I need to find a way to make this work. Any ideas? Thanks.

        S Offline
        S Offline
        Skynyrd
        wrote on last edited by
        #3

        I'm not sure what the attribute is right now, but there is a way to make objects callable only from specified assemblies. If ur calling object is managed and u can place it in an isolated assembly then u can reach the solution u are looking for.

        A 1 Reply Last reply
        0
        • S Skynyrd

          I'm not sure what the attribute is right now, but there is a way to make objects callable only from specified assemblies. If ur calling object is managed and u can place it in an isolated assembly then u can reach the solution u are looking for.

          A Offline
          A Offline
          Anonymous
          wrote on last edited by
          #4

          Apparently, VS2005 has a new attribute [VisibleFromAssembly="ASSEMBLY_NAME"] which I'll be able to use. I'm not sure that's the exact attribute name, but it's something similar that can be applied at the class level, for instance, to an internal class.

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups