Class PropertyContract
- Namespace
- ShapeShift.Schema
- Assembly
- ShapeShift.dll
Describes one named member of an ObjectContract.
public sealed class PropertyContract
- Inheritance
-
PropertyContract
- Inherited Members
Constructors
PropertyContract(string, DataContract)
Describes one named member of an ObjectContract.
public PropertyContract(string name, DataContract type)
Parameters
namestringThe name of the property as it appears in the serialized payload, after any naming policy has been applied.
typeDataContractThe contract for the property's value.
Properties
DeclaredName
Gets the name declared by the type shape, before the serializer's naming policy was applied.
public string? DeclaredName { get; init; }
Property Value
Remarks
This reflects any PropertyShapeAttribute.Name override, but not
ShapeShiftNamingPolicy.
DefaultValue
Gets the default value that the deserializer assumes when this property is absent from the payload, when that value can be expressed in the data model.
public ShapeShiftValue? DefaultValue { get; init; }
Property Value
IsAlwaysWritten
Gets a value indicating whether this property is always written when serializing.
public bool IsAlwaysWritten { get; init; }
Property Value
Remarks
When false, SerializeDefaultValuesPolicy allows the serializer to omit this property when its value matches DefaultValue.
IsNullable
Gets a value indicating whether null is an acceptable value for this property.
public bool IsNullable { get; init; }
Property Value
IsReadable
Gets a value indicating whether this property is included when serializing.
public bool IsReadable { get; init; }
Property Value
Remarks
This is false for members that can only be assigned during deserialization (e.g. write-only members).
IsRequired
Gets a value indicating whether the deserializer requires this property to be present in the payload.
public bool IsRequired { get; init; }
Property Value
IsWritable
Gets a value indicating whether this property is accepted when deserializing.
public bool IsWritable { get; init; }
Property Value
Remarks
When false, the property appears in serialized payloads but the deserializer ignores it.
MemberName
Gets the name of the CLR property or field that this entry was derived from.
public string? MemberName { get; init; }
Property Value
- string
The CLR member name, or null when this entry does not come from a member that a caller could name in C# (for example a constructor parameter that has no matching property).
Remarks
This is the only name on this type that is never influenced by a PropertyShapeAttribute.Name
alias or by ShapeShiftNamingPolicy. It exists so that a CLR member reached through an
expression such as person => person.Address.City can be matched to the entry that describes
it, whose Name then supplies the name that actually appears in the payload.
Use DeclaredName instead when you want the name the shape declares, alias included.
Name
Gets the name of the property as it appears in the serialized payload.
public string Name { get; }
Property Value
Position
Gets the 0-based position this property occupies when its declaring type uses Positional.
public int? Position { get; init; }
Property Value
Remarks
A position is a permanent part of the contract: it may be retired but never reused for a different member, and members may only be appended after the highest position already in use.
Type
Gets the contract for the property's value.
public DataContract Type { get; }
Property Value
Methods
GetMemberName(IPropertyShape)
Gets the name of the CLR property or field that a property shape represents, ignoring any
PropertyShapeAttribute.Name alias.
public static string? GetMemberName(IPropertyShape property)
Parameters
propertyIPropertyShapeThe property shape to inspect.
Returns
- string
The CLR member name, or null when the shape does not expose the underlying member (as is the case for tuple elements synthesized by some shape providers).
Remarks
Format packages that build their own ObjectContract should populate MemberName from this method so that expression-based paths work with their contracts. The underlying member is only consulted when an alias is present, because without one the shape's own name is already the CLR member name.
ToString()
Returns a string that represents the current object.
public override string ToString()
Returns
- string
A string that represents the current object.