Click here to Skip to main content
15,897,891 members
Home / Discussions / C#
   

C#

 
AnswerRe: showing password ****** Pin
Abhinav S15-Feb-10 0:52
Abhinav S15-Feb-10 0:52 
AnswerRe: showing password ****** [modified] Pin
OriginalGriff15-Feb-10 1:13
mveOriginalGriff15-Feb-10 1:13 
GeneralRe: showing password ****** Pin
Abhinav S15-Feb-10 4:43
Abhinav S15-Feb-10 4:43 
Questionshow a webcam photo Pin
naghoumeh1415-Feb-10 0:21
naghoumeh1415-Feb-10 0:21 
AnswerRe: show a webcam photo Pin
Nematjon Rahmanov15-Feb-10 0:33
Nematjon Rahmanov15-Feb-10 0:33 
GeneralRe: show a webcam photo Pin
naghoumeh1415-Feb-10 0:59
naghoumeh1415-Feb-10 0:59 
GeneralRe: show a webcam photo Pin
Nematjon Rahmanov15-Feb-10 1:31
Nematjon Rahmanov15-Feb-10 1:31 
Question[NOT SOLVED ANYMORE] Renaming fields / Controlling access to fields [modified] Pin
blackblizzard15-Feb-10 0:10
blackblizzard15-Feb-10 0:10 
Hi everyone. I'm a newbie to C# and I'm having trouble with the following -- I'd like to know whether it's possible, or learn some alternative way of doing it:

I'm writing a system that underlies applications and manages access to shared data to ensure concurrent accesses don't end up making a mess. Basically, I'd like application programmers to be able to write their code as they normally would, without worrying about concurrence, and then simply tag their methods with [Atomic] if they want the system to treat them as such. Now, my question isn't how to make the methods be atomic -- I have already implemented all that. What I want to know is how I can control access to the fields of atomic objects. I'll explain.

Say they define following class:

class MyClass {

   private int x;
   private int y;

   public void doStuff() {
       x = y + 10;
   }

}


I don't want them to access x and y like that. What I want to do use ILGenerator to create an extended version of MyClass in which I handle the access to fields safely:
* I modify the names of the fields to FORBIDDEN_x and FORBIDDEN_y.
* I define properties x and y (i.e., with the old name of the fields), so that where the application programmer used to directly access a field, he will now access the corresponding property.
* I define the methods get and set of each property so that they handle the accesses safely.

So, once again (sorry for the insistence):
* I want the programmer to be able to write their code as seen above, with unsafe access to fields.
* I then want to go and hack the names of the fields and add properties so that I can handle the access safely.
This way the programmer doesn't need to make any special effort in their code, because I'll hack it later.

And now for the problem: I cannot change the name of the fields. It's read-only.
So, is there any way in which I can do this, or something similar, so that the programmer still has the illusion that he's accessing the fields directly? The only thing I can think of is that the programmer defines the properties himself like so:

class MyClass {

   private int x;
   private int y;

   public int xProp {
      get {  return x;  }
      set {  this.x = value;  }
   }

   public int yProp {
      get {  return y;  }
      set {  this.y = value;  }
   }

   public void doStuff() {
       xProp = yProp + 10;
   }

}


and then I'll go in and hack xProp and yProp's get and set methods, but now the programmer has to make the extra effort to define the properties and to never forget to use them instead of the fields. Is there any way I can achieve what I originally intented to do?
modified on Monday, February 22, 2010 9:23 AM

AnswerRe: Renaming fields / Controlling access to fields Pin
Luc Pattyn15-Feb-10 0:32
sitebuilderLuc Pattyn15-Feb-10 0:32 
GeneralRe: Renaming fields / Controlling access to fields Pin
blackblizzard15-Feb-10 1:15
blackblizzard15-Feb-10 1:15 
QuestionThe suggested solution doesn't work: help, please Pin
blackblizzard22-Feb-10 3:23
blackblizzard22-Feb-10 3:23 
AnswerRe: The suggested solution doesn't work: help, please Pin
Luc Pattyn22-Feb-10 10:49
sitebuilderLuc Pattyn22-Feb-10 10:49 
GeneralRe: The suggested solution doesn't work: help, please Pin
blackblizzard22-Feb-10 22:38
blackblizzard22-Feb-10 22:38 
GeneralRe: The suggested solution doesn't work: help, please Pin
blackblizzard25-Feb-10 22:03
blackblizzard25-Feb-10 22:03 
QuestionComboBox Column Pin
spankyleo12314-Feb-10 23:49
spankyleo12314-Feb-10 23:49 
AnswerRe: ComboBox Column Pin
Abhinav S15-Feb-10 0:52
Abhinav S15-Feb-10 0:52 
GeneralRe: ComboBox Column Pin
spankyleo12315-Feb-10 1:33
spankyleo12315-Feb-10 1:33 
GeneralRe: ComboBox Column Pin
Abhinav S15-Feb-10 2:36
Abhinav S15-Feb-10 2:36 
GeneralRe: ComboBox Column Pin
spankyleo12315-Feb-10 3:26
spankyleo12315-Feb-10 3:26 
GeneralRe: ComboBox Column Pin
Abhinav S15-Feb-10 6:53
Abhinav S15-Feb-10 6:53 
QuestionWhich is the best printing in ASP.NET Pin
sharad Pyakurel14-Feb-10 23:41
sharad Pyakurel14-Feb-10 23:41 
AnswerRe: Which is the best printing in ASP.NET Pin
DaveAuld15-Feb-10 4:44
professionalDaveAuld15-Feb-10 4:44 
QuestionProcess Exit problem ! Pin
Nematjon Rahmanov14-Feb-10 23:01
Nematjon Rahmanov14-Feb-10 23:01 
AnswerRe: Process Exit problem ! Pin
Luc Pattyn14-Feb-10 23:10
sitebuilderLuc Pattyn14-Feb-10 23:10 
QuestionRe: Process Exit problem ! Pin
Nematjon Rahmanov14-Feb-10 23:32
Nematjon Rahmanov14-Feb-10 23:32 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.