Last update January 17, 2008

Feature Request List /
Local Scope Operator



Describe the new page here.

Apologies for lack of any formatting here, I'm newish to this wiki business

This refers to a degree of delegate automation, suppose I have various functions that fire but I need to track which was fired first, for example in a resource locking situation (psudeocode):

 public void AddNewUser?( string Name )
 {
   Database.tblUsers.Lock();
   Database.tblUsers.Insert( Name );
   Database.tblUSers.Unlock();
 }

public void AddUsers?( string[] Names ) { foreach( string Name in Names ) AddNewUser?( Name ); }

one way of "mastering" the database lock to the AddUsers? function and have AddNewUser? perform no locking or unlocking would be to use a delegate - find the class's entrypoint function and let that handle the locking.

But there is no simple way to refer to the current function as a delegate - I'd not be able to use "this" as that would refer to the parent/hosting class instance. I suggest "scope" or some such keyword to refer to the hosting function and maybe "this.scope" to refer to the function at the top of the callstack below the class itself (though "class" and "scope" would probably be better "this" is engrained in history so we're stuck with it's ambiguity) ... consider:

 class MyClass?
 {
   void EntryPoint?()
   {
      //scope = pointer to current MyClass?.EntryPoint? instance
      //this.scope == scope
      ChildFunction?();
   }

void ChildFunction?() { //scope == pointer to current MyClass?.ChildFunction? instance //this.scope == pointer to current MyClass?.EntryPoint? instance } }

"scope" itself is probably not the best choice as it might be confused with standard brace scope. But a short word of roughly 4 chars would probably be best.

This can also be used in event registration, though the possibilities seem quite strange when you start to think about it!

 void btnCloneSelf_Click( sender , args )
 {
   Button clone = new Button();
   clone.Click = scope;  
 }

back to our first example, here's some long, drawn out psudeocode as to how this might work:

 class MyClass?
 {
   public void AddNewUser?( string Name )
   {
      if( scope == this.scope )
         Database.tblUsers.Lock();

Database.tblUsers.Insert( Name );

if( scope == this.scope ) Database.tblUSers.Unlock(); }

public void AddUsers?( string[] Names ) { if( scope == this.scope ) Database.tblUsers.Lock();

foreach( string Name in Names ) AddNewUser?( Name );

if( scope == this.scope ) Database.tblUSers.Unlock(); } }

this could even be further dissolved into a simple boolean check with yet another keyword (or a define), but we can finally start to see some clarity here:

   #define entrypoint   ( scope == this.scope )

public void AddNewUser?( string Name ) { if( entrypoint ) Database.tblUsers.Lock();

Database.tblUsers.Insert( Name );

if( entrypoint ) Database.tblUSers.Unlock(); }


FrontPage | News | TestPage | MessageBoard | Search | Contributors | Folders | Index | Help | Preferences | Edit

Edit text of this page (date of last change: January 17, 2008 12:26 (diff))