Thread-safe flag for methods #7826
-
It could be useful if methods would contain a "flag" saying they are thread-safe or not. |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 2 replies
-
What would that flag mean? What would it do? This sounds suspiciously like |
Beta Was this translation helpful? Give feedback.
-
Thread safety is not a yes-or-no flag. Can different methods be invoked at the same time? Are they grouped? |
Beta Was this translation helpful? Give feedback.
-
That's what custom attributes are for... using System;
public class C {
[ThreadSafe(true)]
public void M() {
}
}
[AttributeUsage(AttributeTargets.Method)]
public class ThreadSafeAttribute : Attribute
{
public bool IsThreadSafe { get; }
public ThreadSafeAttribute(bool value)
{
this.IsThreadSafe = value;
}
} And done. ;-) However, I agree with all the people arguing against such a flag. |
Beta Was this translation helpful? Give feedback.
You should recommend that to EF. They can write analyzers for this sort of scenario.