A cross-platform UI framework for .NET
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

46 lines
1.5 KiB

using System;
using System.Collections.Generic;
using Avalonia.Rendering.Composition.Transport;
// Special license applies <see href="https://raw.githubusercontent.com/AvaloniaUI/Avalonia/master/src/Avalonia.Base/Rendering/Composition/License.md">License.md</see>
namespace Avalonia.Rendering.Composition.Server
{
/// <summary>
/// A server-side list container capable of receiving changes from the UI thread
/// Right now it's quite dumb since it always receives the full list
/// </summary>
class ServerList<T> : ServerObject where T : ServerObject
{
public List<T> List { get; } = new List<T>();
protected override void DeserializeChangesCore(BatchStreamReader reader, TimeSpan committedAt)
{
if (reader.Read<byte>() == 1)
{
List.Clear();
var count = reader.Read<int>();
for (var c = 0; c < count; c++)
List.Add(reader.ReadObject<T>());
}
base.DeserializeChangesCore(reader, committedAt);
}
public override long LastChangedBy
{
get
{
var seq = base.LastChangedBy;
foreach (var i in List)
seq = Math.Max(i.LastChangedBy, seq);
return seq;
}
}
public List<T>.Enumerator GetEnumerator() => List.GetEnumerator();
public ServerList(ServerCompositor compositor) : base(compositor)
{
}
}
}