I created a class for thread synchronization, that I want to apply to methods, classes, properties etc without going through and inserting my code into every function, class etc. This is an example of the current implementation I have to do:
public class NotWhatIWantExample
{
LockingClass locker;
public int function()
{
locker.EnterWriteBlock();
if (condition)
{
locker.LeaveWriteBlock();
return 0;
}
locker.LeaveWriteBlock();
return 1;
}
}
Next is two examples of what I want to do if possible
Example 2:
// [LockingClassAttribute(LockingClassAttribute.WriteBlock)]
// Not Declared But Added Since Attribute Is Applied On A Method
public class WhatIWantExample
{
//LockingClass locker; Included In The Attribute
[LockingClassAttribute(LockingClassAttribute.WriteBlock)]public int function()
{
if (condition)
return 0;
}
}
Example 3:
[LockingClassAttribute(LockingClassAttribute.ReadWriteBlock)]
public class WhatIWantExample
{
//LockingClass locker; Included In The Attribute
//Function Would Override LockingClassAttribute.ReadWriteBlock
[LockingClassAttribute(LockingClassAttribute.WriteBlock)]public int function()
{
if (condition)
return 0;
return 1;
}
//Would Inherit [LockingClassAttribute(LockingClassAttribute.ReadWriteBlock)]
public int function2()
{
if (condition)
return 0;
return 1;
}
}
Is this possible to do?