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(); }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.public void AddUsers?( string[] Names ) { foreach( string Name in Names ) AddNewUser?( Name ); }
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?(); }"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.void ChildFunction?() { //scope == pointer to current MyClass?.ChildFunction? instance //this.scope == pointer to current MyClass?.EntryPoint? instance } }
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();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: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(); } }
#define entrypoint ( scope == this.scope )
public void AddNewUser?( string Name ) { if( entrypoint ) Database.tblUsers.Lock();
Database.tblUsers.Insert( Name );
if( entrypoint ) Database.tblUSers.Unlock(); }