From 42b039cf89a7074f81ab8130c10ddb63d46a19bd Mon Sep 17 00:00:00 2001 From: Date: Sun, 6 May 2018 19:11:24 -0700 Subject: [PATCH] Added in functionality to read/write to List --- .../Extentions/BinaryReadWriteExtentions.cs | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/GeneralMods/ModdedUtilitiesNetworking/Framework/Extentions/BinaryReadWriteExtentions.cs b/GeneralMods/ModdedUtilitiesNetworking/Framework/Extentions/BinaryReadWriteExtentions.cs index fb76d085..0079116d 100644 --- a/GeneralMods/ModdedUtilitiesNetworking/Framework/Extentions/BinaryReadWriteExtentions.cs +++ b/GeneralMods/ModdedUtilitiesNetworking/Framework/Extentions/BinaryReadWriteExtentions.cs @@ -6,6 +6,8 @@ using System.Linq; using System.Text; using System.Threading.Tasks; using Netcode; + + namespace ModdedUtilitiesNetworking.Framework.Extentions { public static class BinaryReadWriteExtentions @@ -27,6 +29,39 @@ namespace ModdedUtilitiesNetworking.Framework.Extentions public static void WriteString(this BinaryWriter writer, object str) { writer.WriteString((string)str); + + } + + /// + /// Writes a string list to a binary stream. + /// + /// + /// The list to write. + public static void WriteStringList(this BinaryWriter writer, object strList) + { + List list =(List)strList; + writer.Write(list.Count); + for(int i=0; i + /// Reads a string list from the binary data. + /// + /// + /// + public static List ReadStringList(this BinaryReader reader) + { + int count = reader.ReadInt32(); + List strList = new List(); + for(int i = 0; i < count; i++) + { + string s=reader.ReadString(); + strList.Add(s); + } + return strList; } ///