public interface IWriteContext extends ILookup
All state data that is needed for the writing of a concrete graph instance should go here, allowing all handlers and deserializers to be implemented stateless.
Modifier and Type | Method and Description |
---|---|
<T> T |
getCurrent()
Returns the most current (the last element) within the container hierarchy as it is returned by
ObjectStack
or default(T) if the most current element is not of the desired target type. |
IGraph |
getGraph()
Returns the currently active graph object.
|
IListEnumerable<Object> |
getObjectStack()
Returns the current nesting of graphs and graph elements.
|
<T> T |
getSerializationProperty(TypedKey<T> key)
Get a property value that specifies information about how to handle specific cases.
|
IWriteEvents |
getWriteEvents()
Returns an implementation of
IWriteEvents that allows to subscribe to various events in the write process. |
IXmlWriter |
getWriter()
Returns the current
IXmlWriter implementation. |
default void |
serialize(Object item,
Type t)
Serializes the specified item using the provided type information.
|
<T> void |
serialize(Type targetType,
IWriteContext context,
T item)
Serialize
item to an XML representation. |
default <T> void |
serialize(Type targetType,
T item)
Serialize the
item . |
default void |
serializeReplacement(Type targetType,
Object originalItem,
Object replacement)
Serialize an replacement object
replacement instead of the original originalItem . |
createDictionaryLookup, createDynamic, createSingle, createSingle, createWrapped, lookup, lookup, lookup, safeLookup
<T> T getCurrent()
ObjectStack
or default(T)
if the most current element is not of the desired target type.T
- The desired target type.default(T)
.IGraph getGraph()
IListEnumerable<Object> getObjectStack()
The list contains the user objects which correspond to the GraphML elements.
<T> T getSerializationProperty(TypedKey<T> key)
key
- The identifier for the propertynull
if no such property existsIWriteEvents getWriteEvents()
IWriteEvents
that allows to subscribe to various events in the write process.IXmlWriter getWriter()
IXmlWriter
implementation.default void serialize(Object item, Type t) throws SerializationNotSupportedException
item
should be assignable to type t
. This method simply delegates to
serialize(Type, IWriteContext, Object)
, using the correct type parameter.
SerializationNotSupportedException
item
- The item to serialize.t
- The type the item is known to be of at deserialization time.<T> void serialize(Type targetType, IWriteContext context, T item) throws SerializationNotSupportedException
item
to an XML representation.
Client code should usually use the extension method serialize(Type, Object)
instead to ensure the the correct
context
instance is used.
SerializationNotSupportedException
T
- The type of the object that is serialized.targetType
- The type of the object that is serialized.context
- The current write context.item
- The object that should be serialized.serialize(Type, Object)
default <T> void serialize(Type targetType, T item) throws SerializationNotSupportedException
item
.
This method calls serialize(Type, IWriteContext, Object)
with context
as first argument and should be
used in virtually all cases.
SerializationNotSupportedException
T
- The type of the object that is serialized.targetType
- The type of the object that is serialized.item
- The object that should be serialized.serialize(Type, IWriteContext, Object)
default void serializeReplacement(Type targetType, Object originalItem, Object replacement) throws SerializationNotSupportedException
replacement
instead of the original originalItem
.
Calling this method allows to remember the original object instance, even if the object is really written through a MarkupExtension
or similar replacement mechanisms.
SerializationNotSupportedException
originalItem
- The original object that should be serialized.replacement
- The replacement object that will actually be serialized instead.serialize(Type, IWriteContext, Object)