Enhanced C#
Loyc library documentation
 All Classes Namespaces Functions Variables Enumerations Enumerator Properties Events Pages
Public Member Functions | List of all members
Loyc.SyncLib.ISyncObject< SyncManager, T > Interface Template Reference

This interface is equivalent to SyncObjectFunc{SyncManager,T}, reformulated as an interface. It only exists because the CLR (C# runtime) supports optimizations on generic parameters that are structs, but similar optimizations don't exist for delegates. For this reason it is possible to achieve higher performance by providing a synchronizer in the form of a struct rather than a delegate (see Remarks) More...


Source file:
Inheritance diagram for Loyc.SyncLib.ISyncObject< SyncManager, T >:
Loyc.SyncLib.Impl.AsISyncObject< SyncManager, T >

Remarks

This interface is equivalent to SyncObjectFunc{SyncManager,T}, reformulated as an interface. It only exists because the CLR (C# runtime) supports optimizations on generic parameters that are structs, but similar optimizations don't exist for delegates. For this reason it is possible to achieve higher performance by providing a synchronizer in the form of a struct rather than a delegate (see Remarks)

Example usage:

public class PersonSync<SM> : ISyncObject<SM, Person> where SM : ISyncManager
{
public Person Sync(SM sync, Person? obj)
{
sync.CurrentObject = obj ??= new Person();
obj.Name = sync.Sync("Name", obj.Name);
obj.Siblings = sync.SyncList("Siblings", obj.Siblings, this);
return obj;
}
}
// Later...
var json = SyncJson.Write(new Person { Name = "Jon" }, new PersonSync<SyncJson.Writer>());
]]>

Public Member Functions

Sync (SyncManager sync, T?value)