The module that registers and resolves type tags: it encapsulates (1) the bidirectional dictionary between type tags and .NET types, (2) the convention by which tags are attached to synchronizers (the TypeTagAttribute), and (3) the policy for tags in a data stream that don't match anything registered or expected. All three are customizable: the dictionary via Add, and the convention and policies by overriding the virtual methods in a derived class and swapping it in with SetDefault (the Ambient Service Pattern).
More...
The module that registers and resolves type tags: it encapsulates (1) the bidirectional dictionary between type tags and .NET types, (2) the convention by which tags are attached to synchronizers (the TypeTagAttribute), and (3) the policy for tags in a data stream that don't match anything registered or expected. All three are customizable: the dictionary via Add, and the convention and policies by overriding the virtual methods in a derived class and swapping it in with SetDefault (the Ambient Service Pattern).
This registry deliberately knows nothing about synchronizers: which synchronizer handles which type is the concern of TypeSyncRegistry, which records tags it discovers here (in the instance that is Default at the time of the Add call).
Registry behavior can be changed by writing a derived class and installing it by changing the GlobalDefault or calling SetDefault. For example, you could change the error-handling policies:
-
UnknownTagError is called when reading dynamically and the tag in the data stream is not in the dictionary. The default throws FormatException; an override can return a substitute type (which must have a registered synchronizer), or null to fall back to the statically-expected type.
-
TagMismatchError is called when reading with an explicit (statically-typed) synchronizer and the data stream contains a different tag than the synchronizer's. The default throws FormatException; an override that returns normally causes the read to proceed with the expected synchronizer anyway.
|
| void | Add (Type type, string tag, bool replaceExisting=false) |
| | Associates a type tag with a type (in both directions). Re-adding an identical association is harmless; a conflicting one throws unless replaceExisting is true. More...
|
| |
| string | TagOf (Type type) |
| | Gets the tag registered for a type, or null. More...
|
| |
| Type | TypeOf (string tag) |
| | Gets the type registered for a tag, or null. More...
|
| |
| string | AttributeTagOf (Delegate syncFunc) |
| | Gets the tag declared by a synchronizer function, or null. More...
|
| |
| virtual string | AttributeTagOf (MethodInfo synchronizerMethod) |
| | Gets the tag declared by a synchronizer method: by default, a TypeTagAttribute on the method or, failing that, on its declaring type. Override to change the convention (e.g. to derive tags from type names). More...
|
| |
| virtual string | AttributeTagOf (Type synchronizerType, Type valueType) |
| | Gets the tag declared by a synchronizer type (e.g. a struct implementing ISyncObject{SM, T}) as it applies to values of type valueType: by default, a TypeTagAttribute on a method whose return type is valueType (so one synchronizer type can serve multiple value types with different tags), then on the type itself. More...
|
| |
| virtual Type | UnknownTagError (string tag, Type expectedType, FieldId field) |
| | Called when a dynamically-typed read encounters a tag that is not in the dictionary. The default throws FormatException. An override may return a substitute type to synchronize instead (it must have a registered synchronizer), or null to fall back to the statically-expected type. More...
|
| |
| virtual void | TagMismatchError (string expectedTag, string tagInStream, Type expectedType, FieldId field) |
| | Called when a statically-typed read encounters a tag that differs from the tag of the synchronizer being used. The default throws FormatException; if an override returns normally, the read proceeds with the expected synchronizer anyway. More...
|
| |