Re: Enabling Access to Private Fields

From: Jeff Benson (blaster151_at_hotmail.com)
Date: 10/27/03


Date: Mon, 27 Oct 2003 09:18:28 -0600

Thanks for replying. I want to make them available for writing *only* to
the newly fabricated assembly. They should still be private to everything
else. :)

Basically, what I'm trying to do is dynamically create a data access object
(that knows how to perform direct field read/sets) based on metadata. It's
working perfectly except for the unfortunate fact that the new object
doesn't have permissions to actually do what it's supposed to do.

Jeff
blaster151@hotmail.com

"Russell B. Eggen" <NOreggen@gte.netSPAM> wrote in message
news:%23%23SW1n9mDHA.2080@TK2MSFTNGP10.phx.gbl...
> Why not add a method to return the value of your private fields? I would
> not bother with methods that could write to them, otherwise, what would be
> the point of making them private? <g>
>
> --
> Russ Eggen
> www.radfusion.com
>
>
> "Jeff Benson" <blaster151@hotmail.com> wrote in message
> news:uJAdfi9mDHA.684@TK2MSFTNGP09.phx.gbl...
> Hello,
>
> I am wondering if it is possible to use declarative security permissions
(or
> some other technique) to allow a dynamically synthesized assembly (one
that
> I'm compiling on-the-fly from C# code I've built myself at runtime) to
> access private fields on classes in the assembly that's performing the
> dynamic compilation.
>
> In other words, code in Assembly A wants to dynamically compile a new
> Assembly B (using the System.CodeDom.Compiler namespace) and allow
Assembly
> B to access private fields in Assembly A. (I could probably make them
> "protected" or "internal" if I had to, but would prefer to let them remain
> private.)
>
> Since I know that Assembly B could access Assembly A's private fields
> through reflection (just much more slowly), it seems to me that it must be
> possible to enable it to access them directly. I've done some preliminary
> reading about code-level permissions, but haven't found the solution. Any
> advice or even pointers in the right direction would be tremendously
> appreciated!
>
> Thanks in advance,
>
> Jeff Benson
> blaster151@hotmail.com
>
>
>



Relevant Pages

  • Re: camelCase
    ... When naming private fields the C# guidelines say to use camel casing ... public class SomeObject ... Fortunately, private members are private, so no compiler or client will care ...
    (microsoft.public.dotnet.languages.csharp)
  • Structural question regarding scope of variables
    ... Private Fields ... Private Instance Methods ... different connection strings, based on where the data will need to ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Assigning "this"
    ... Define a private inner-class to hold all of your private fields (I ... Suppose I have two functions called DoubleSizes() and Double. ...
    (microsoft.public.dotnet.languages.csharp)
  • private field and public property naming conventions
    ... Has anyone found any naming convention guidelines for private fields ... public string MyVariable ... Public Property MyVariable() As String ...
    (microsoft.public.dotnet.framework)
  • Re: Enabling Access to Private Fields
    ... These internal methods would then safely, ... > access private fields on classes in the assembly that's performing the ... > dynamic compilation. ...
    (microsoft.public.dotnet.security)