Custom attribute that, when applied to a class, applies the FreezableThreadingModel to this class. The aspect introduces the IFreezable interface into the target class. After the Freeze() method has been invoked, the object can no longer be modified, and can therefore be safely shared between several threads.
Inheritance
Implements
Namespace: PostSharp.Patterns.Threading
Assembly: PostSharp.Patterns.Threading.dll
Syntax
[IntroduceInterface(typeof(IFreezable), OverrideAction = InterfaceOverrideAction.Ignore, LinesOfCodeAvoided = 5)]
[Metric("UsedFeatures", "PostSharp.Patterns.Threading.Freezable")]
[Serializer(typeof(FreezableAttribute.Serializer))]
public sealed class FreezableAttribute : ReadOnlyThreadAwareAttribute, ITypeLevelAspect, ITypeLevelAspectBuildSemantics, IAspectBuildSemantics, IValidableAnnotation, ICloneAwareAspect, IInstanceScopedAspect, IAspectProvider, IService, IAdviceProvider, IAspect, IQueryInterface, IConcurrencyController, IFreezable, IThreadAwareRemarks
Accessing a freezable object from a different thread than the one that created it, before the Freeze() method has been invoked, will result in a ThreadMismatchException.
Attempts to modify a freezable object after the Freeze() method has been invoked will result in an ObjectReadOnlyException.
The IFreezable interface is introduced after compilation, so tools that are not aware of PostSharp do not see it. To call Freeze(), cast the object to IFreezable or use the Cast<TSource, TTarget>(TSource) method, which is verified at build time.
Use this aspect instead of ImmutableAttribute when the object must be modified after its constructor has completed, for instance during deserialization. The aspect implicitly adds the AggregatableAttribute aspect, so you can build freezable object trees. Freezing an object also freezes its children. Children must be freezable or immutable.
Constructors
| Name | Description |
|---|---|
| FreezableAttribute() | |
| FreezableAttribute(PortableFormatterConstructorContext) |
Methods
| Name | Description |
|---|---|
| Advise(object) | Injects the advice into the child object. |
| OnCloned(ICloneAwareAspect) | Method called after an object enhanced by the current aspect has been
cloned using MemberwiseClone(). The |
| ToString() |