ObjectCreationHandlingAttribute Class
Definition
- Namespace
- Bodu.Text.Serialization
- Assembly
- Bodu.Text.Serialization.dll
- Package
- Bodu.Text.Serialization 1.0.0
Specifies, for the annotated type or member, whether the serializer replaces the value with a freshly created instance or populates the value already held during deserialization, overriding the serializer-wide preferred object-creation handling.
[AttributeUsage(AttributeTargets.Class|AttributeTargets.Struct|AttributeTargets.Property|AttributeTargets.Field|AttributeTargets.Interface, AllowMultiple = false)]
public sealed class ObjectCreationHandlingAttribute : SerializationAttribute
- Inheritance
-
ObjectCreationHandlingAttribute
- Attributes
-
System.AttributeUsageAttribute
- Inherited Members
- Extension Methods
Examples
public sealed class Pipeline
{
[ObjectCreationHandling(ObjectCreationHandling.Populate)]
public List<string> Steps { get; } = new() { "restore" };
}
// Deserialized entries are appended to the existing list instead of replacing it.
Remarks
When applied to a member the attribute governs that member alone; when applied to a type it governs every member of the type that does not carry its own attribute. A member-level attribute takes precedence over a type-level one, and both take precedence over the options-level default.
Constructors
ObjectCreationHandlingAttribute(ObjectCreationHandling)
Initializes a new instance of the ObjectCreationHandlingAttribute class.
public ObjectCreationHandlingAttribute(ObjectCreationHandling handling)
Parameters
handlingObjectCreationHandlingThe object-creation handling applied to the annotated type or member.
Exceptions
- ArgumentOutOfRangeException
Thrown when
handlingis not a defined ObjectCreationHandling value.
Properties
Handling
Gets the object-creation handling applied to the annotated type or member.
public ObjectCreationHandling Handling { get; }
Property Value
- ObjectCreationHandling
The object-creation handling.
Applies to
| Product | Versions |
|---|---|
| .NET | 8, 10 |