Add IMergable interface

This commit is contained in:
Jarrod Doyle 2024-09-07 09:05:45 +01:00
parent 001b6a944e
commit 6f87bc6904
Signed by: Jayrude
GPG Key ID: 38B57B16E7C0ADF7
3 changed files with 24 additions and 3 deletions

View File

@ -65,4 +65,9 @@ public class GenericChunk : IChunk
{ {
writer.Write(Data); writer.Write(Data);
} }
}
public interface IMergable
{
public abstract void Merge(IMergable other);
} }

View File

@ -34,7 +34,7 @@ public record LinkId
} }
} }
public class LinkChunk : IChunk public class LinkChunk : IChunk, IMergable
{ {
public record Link public record Link
{ {
@ -68,9 +68,15 @@ public class LinkChunk : IChunk
{ {
throw new System.NotImplementedException(); throw new System.NotImplementedException();
} }
public void Merge(IMergable other)
{
links.AddRange(((LinkChunk)other).links);
}
} }
public class LinkDataMetaProp : IChunk // TODO: This should be generic like Property
public class LinkDataMetaProp : IChunk, IMergable
{ {
public record LinkData public record LinkData
{ {
@ -102,4 +108,9 @@ public class LinkDataMetaProp : IChunk
{ {
throw new System.NotImplementedException(); throw new System.NotImplementedException();
} }
public void Merge(IMergable other)
{
linkData.AddRange(((LinkDataMetaProp)other).linkData);
}
} }

View File

@ -18,7 +18,7 @@ public class Property
} }
} }
public class PropertyChunk<T> : IChunk where T : Property, new() public class PropertyChunk<T> : IChunk, IMergable where T : Property, new()
{ {
public ChunkHeader Header { get; set; } public ChunkHeader Header { get; set; }
public List<T> properties; public List<T> properties;
@ -38,6 +38,11 @@ public class PropertyChunk<T> : IChunk where T : Property, new()
{ {
throw new System.NotImplementedException(); throw new System.NotImplementedException();
} }
public void Merge(IMergable other)
{
properties.AddRange(((PropertyChunk<T>)other).properties);
}
} }
public class PropGeneric : Property public class PropGeneric : Property