From 32ee0665decb235ca68d026f0026124f4e8d4730 Mon Sep 17 00:00:00 2001 From: modamoda Date: Wed, 21 May 2014 01:07:42 +0900 Subject: [PATCH 1/3] Generic versions of readPlist(...) methods are implemented - readPlist(blah) - their test codes --- PlistCS/PlistCS/PlistTests.cs | 2 ++ PlistCS/Src/Plist.cs | 4 ++++ 2 files changed, 6 insertions(+) diff --git a/PlistCS/PlistCS/PlistTests.cs b/PlistCS/PlistCS/PlistTests.cs index 1c44ead..043dcc9 100644 --- a/PlistCS/PlistCS/PlistTests.cs +++ b/PlistCS/PlistCS/PlistTests.cs @@ -69,12 +69,14 @@ private void CheckDictionary(Dictionary dict) public void ReadBinary() { CheckDictionary((Dictionary)Plist.readPlist(sourceBinPath)); + CheckDictionary(Plist.readPlist>(sourceBinPath)); } [TestMethod] public void ReadXml() { CheckDictionary((Dictionary)Plist.readPlist(sourceXmlPath)); + CheckDictionary(Plist.readPlist>(sourceXmlPath)); } [TestMethod] diff --git a/PlistCS/Src/Plist.cs b/PlistCS/Src/Plist.cs index f4c56a3..1d1bce2 100644 --- a/PlistCS/Src/Plist.cs +++ b/PlistCS/Src/Plist.cs @@ -44,6 +44,7 @@ public static class Plist #region Public Functions + public static T readPlist(string path) { return (T)readPlist(path); } public static object readPlist(string path) { using (FileStream f = new FileStream(path, FileMode.Open, FileAccess.Read)) @@ -52,11 +53,13 @@ public static object readPlist(string path) } } + public static T readPlistSource(string source) { return (T)readPlistSource(source); } public static object readPlistSource(string source) { return readPlist(System.Text.Encoding.UTF8.GetBytes(source)); } + public static T readPlist(byte[] data) { return (T)readPlist(data); } public static object readPlist(byte[] data) { return readPlist(new MemoryStream(data), plistType.Auto); @@ -77,6 +80,7 @@ public static plistType getPlistType(Stream stream) } } + public static T readPlist(Stream stream, plistType type) { return (T)readPlist(stream, type); } public static object readPlist(Stream stream, plistType type) { if (type == plistType.Auto) From dad8b73260cfc511c9facd4c36e8f3351c6ccba8 Mon Sep 17 00:00:00 2001 From: modamoda Date: Sat, 24 May 2014 00:46:25 +0900 Subject: [PATCH 2/3] Following .NET naming convention. (public methods) - http://msdn.microsoft.com/en-us/library/ms229045(v=vs.110).aspx - Old methods still remain with "obsolete" attribute --- PlistCS/PlistCS/PlistTests.cs | 18 +++---- PlistCS/Src/Plist.cs | 98 +++++++++++++++++++++++++---------- 2 files changed, 79 insertions(+), 37 deletions(-) diff --git a/PlistCS/PlistCS/PlistTests.cs b/PlistCS/PlistCS/PlistTests.cs index 043dcc9..2db5d8e 100644 --- a/PlistCS/PlistCS/PlistTests.cs +++ b/PlistCS/PlistCS/PlistTests.cs @@ -68,35 +68,35 @@ private void CheckDictionary(Dictionary dict) [TestMethod] public void ReadBinary() { - CheckDictionary((Dictionary)Plist.readPlist(sourceBinPath)); - CheckDictionary(Plist.readPlist>(sourceBinPath)); + CheckDictionary((Dictionary)Plist.ReadPlist(sourceBinPath)); + CheckDictionary(Plist.ReadPlist>(sourceBinPath)); } [TestMethod] public void ReadXml() { - CheckDictionary((Dictionary)Plist.readPlist(sourceXmlPath)); - CheckDictionary(Plist.readPlist>(sourceXmlPath)); + CheckDictionary((Dictionary)Plist.ReadPlist(sourceXmlPath)); + CheckDictionary(Plist.ReadPlist>(sourceXmlPath)); } [TestMethod] public void WriteBinary() { - Plist.writeBinary(CreateDictionary(), targetBinPath); - CheckDictionary((Dictionary)Plist.readPlist(targetBinPath)); + Plist.WriteBinary(CreateDictionary(), targetBinPath); + CheckDictionary((Dictionary)Plist.ReadPlist(targetBinPath)); } [TestMethod] public void WriteXml() { - Plist.writeXml(CreateDictionary(), targetXmlPath); - CheckDictionary((Dictionary)Plist.readPlist(targetXmlPath)); + Plist.WriteXml(CreateDictionary(), targetXmlPath); + CheckDictionary((Dictionary)Plist.ReadPlist(targetXmlPath)); } [TestMethod] public void ReadWriteBinaryByteArray() { - CheckDictionary((Dictionary)Plist.readPlist(Plist.writeBinary(CreateDictionary()))); + CheckDictionary((Dictionary)Plist.ReadPlist(Plist.WriteBinary(CreateDictionary()))); } } } \ No newline at end of file diff --git a/PlistCS/Src/Plist.cs b/PlistCS/Src/Plist.cs index 1d1bce2..7ea4644 100644 --- a/PlistCS/Src/Plist.cs +++ b/PlistCS/Src/Plist.cs @@ -42,54 +42,91 @@ public static class Plist private static int offsetByteSize; private static long offsetTableOffset; + #region Deprecated(obsoleted) public methods + + [Obsolete("Use ReadPlist(string path) instead")] + public static object readPlist(string path) { return ReadPlist(path); } + + [Obsolete("Use ReadPlistSource(source) instead")] + public static object readPlistSource(string source) { return ReadPlistSource(source); } + + [Obsolete("Use ReadPlist(data) instead")] + public static object readPlist(byte[] data) { return ReadPlist(data); } + + [Obsolete("Use GetPlistType(stream) instead")] + public static PlistType getPlistType(Stream stream) { return GetPlistType(stream); } + + [Obsolete("Use ReadPlist(stream, type) instead")] + public static object readPlist(Stream stream, PlistType type) { return ReadPlist(stream, type); } + + [Obsolete("Use WriteXml(value, path) instead")] + public static void writeXml(object value, string path) { WriteXml(value, path); } + + [Obsolete("Use WriteXml(value, stream) instead")] + public static void writeXml(object value, Stream stream) { WriteXml(value, stream); } + + [Obsolete("Use WriteXml(value) instead")] + public static string writeXml(object value) { return WriteXml(value); } + + [Obsolete("Use WriteBinary(value, path) instead")] + public static void writeBinary(object value, string path) { WriteBinary(value, path); } + + [Obsolete("Use WriteBinary(value, stream) instead")] + public static void writeBinary(object value, Stream stream) { WriteBinary(value, stream); } + + [Obsolete("Use WriteBinary(value) instead")] + public static byte[] writeBinary(object value) { return WriteBinary(value); } + + #endregion + #region Public Functions - public static T readPlist(string path) { return (T)readPlist(path); } - public static object readPlist(string path) + public static T ReadPlist(string path) { return (T)ReadPlist(path); } + public static object ReadPlist(string path) { using (FileStream f = new FileStream(path, FileMode.Open, FileAccess.Read)) { - return readPlist(f, plistType.Auto); + return ReadPlist(f, PlistType.Auto); } } - public static T readPlistSource(string source) { return (T)readPlistSource(source); } - public static object readPlistSource(string source) + public static T ReadPlistSource(string source) { return (T)ReadPlistSource(source); } + public static object ReadPlistSource(string source) { - return readPlist(System.Text.Encoding.UTF8.GetBytes(source)); + return ReadPlist(System.Text.Encoding.UTF8.GetBytes(source)); } - public static T readPlist(byte[] data) { return (T)readPlist(data); } - public static object readPlist(byte[] data) + public static T ReadPlist(byte[] data) { return (T)ReadPlist(data); } + public static object ReadPlist(byte[] data) { - return readPlist(new MemoryStream(data), plistType.Auto); + return ReadPlist(new MemoryStream(data), PlistType.Auto); } - public static plistType getPlistType(Stream stream) + public static PlistType GetPlistType(Stream stream) { byte[] magicHeader = new byte[8]; stream.Read(magicHeader, 0, 8); if (BitConverter.ToInt64(magicHeader, 0) == 3472403351741427810) { - return plistType.Binary; + return PlistType.Binary; } else { - return plistType.Xml; + return PlistType.Xml; } } - public static T readPlist(Stream stream, plistType type) { return (T)readPlist(stream, type); } - public static object readPlist(Stream stream, plistType type) + public static T ReadPlist(Stream stream, PlistType type) { return (T)ReadPlist(stream, type); } + public static object ReadPlist(Stream stream, PlistType type) { - if (type == plistType.Auto) + if (type == PlistType.Auto) { - type = getPlistType(stream); + type = GetPlistType(stream); stream.Seek(0, SeekOrigin.Begin); } - if (type == plistType.Binary) + if (type == PlistType.Binary) { using (BinaryReader reader = new BinaryReader(stream)) { @@ -106,23 +143,23 @@ public static object readPlist(Stream stream, plistType type) } } - public static void writeXml(object value, string path) + public static void WriteXml(object value, string path) { using (StreamWriter writer = new StreamWriter(path)) { - writer.Write(writeXml(value)); + writer.Write(WriteXml(value)); } } - public static void writeXml(object value, Stream stream) + public static void WriteXml(object value, Stream stream) { using (StreamWriter writer = new StreamWriter(stream)) { - writer.Write(writeXml(value)); + writer.Write(WriteXml(value)); } } - public static string writeXml(object value) + public static string WriteXml(object value) { using (MemoryStream ms = new MemoryStream()) { @@ -148,23 +185,23 @@ public static string writeXml(object value) } } - public static void writeBinary(object value, string path) + public static void WriteBinary(object value, string path) { using (BinaryWriter writer = new BinaryWriter(new FileStream(path, FileMode.Create))) { - writer.Write(writeBinary(value)); + writer.Write(WriteBinary(value)); } } - public static void writeBinary(object value, Stream stream) + public static void WriteBinary(object value, Stream stream) { using (BinaryWriter writer = new BinaryWriter(stream)) { - writer.Write(writeBinary(value)); + writer.Write(WriteBinary(value)); } } - public static byte[] writeBinary(object value) + public static byte[] WriteBinary(object value) { offsetTable.Clear(); objectTable.Clear(); @@ -929,11 +966,16 @@ private static object parseBinaryByteArray(int headerPosition) #endregion } - + + [Obsolete("use PlistType(uppercase) instead")] public enum plistType { Auto, Binary, Xml } + public enum PlistType + { + Auto, Binary, Xml + } public static class PlistDateConverter { From 99fbb163bad317c8dd720ff003d99a84a0fabb3e Mon Sep 17 00:00:00 2001 From: modamoda Date: Sat, 24 May 2014 00:50:21 +0900 Subject: [PATCH 3/3] .gitignore added --- .gitignore | 185 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 185 insertions(+) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..7414ecf --- /dev/null +++ b/.gitignore @@ -0,0 +1,185 @@ +## Ignore Visual Studio temporary files, build results, and +## files generated by popular Visual Studio add-ons. + +# User-specific files +*.suo +*.user +*.sln.docstates + +# Build results +[Dd]ebug/ +[Dd]ebugPublic/ +[Rr]elease/ +[Rr]eleases/ +x64/ +build/ +bld/ +[Bb]in/ +[Oo]bj/ + +# Roslyn cache directories +*.ide/ + +# MSTest test Results +[Tt]est[Rr]esult*/ +[Bb]uild[Ll]og.* + +#NUNIT +*.VisualState.xml +TestResult.xml + +# Build Results of an ATL Project +[Dd]ebugPS/ +[Rr]eleasePS/ +dlldata.c + +*_i.c +*_p.c +*_i.h +*.ilk +*.meta +*.obj +*.pch +*.pdb +*.pgc +*.pgd +*.rsp +*.sbr +*.tlb +*.tli +*.tlh +*.tmp +*.tmp_proj +*.log +*.vspscc +*.vssscc +.builds +*.pidb +*.svclog +*.scc + +# Chutzpah Test files +_Chutzpah* + +# Visual C++ cache files +ipch/ +*.aps +*.ncb +*.opensdf +*.sdf +*.cachefile + +# Visual Studio profiler +*.psess +*.vsp +*.vspx + +# TFS 2012 Local Workspace +$tf/ + +# Guidance Automation Toolkit +*.gpState + +# ReSharper is a .NET coding add-in +_ReSharper*/ +*.[Rr]e[Ss]harper +*.DotSettings.user + +# JustCode is a .NET coding addin-in +.JustCode + +# TeamCity is a build add-in +_TeamCity* + +# DotCover is a Code Coverage Tool +*.dotCover + +# NCrunch +_NCrunch_* +.*crunch*.local.xml + +# MightyMoose +*.mm.* +AutoTest.Net/ + +# Web workbench (sass) +.sass-cache/ + +# Installshield output folder +[Ee]xpress/ + +# DocProject is a documentation generator add-in +DocProject/buildhelp/ +DocProject/Help/*.HxT +DocProject/Help/*.HxC +DocProject/Help/*.hhc +DocProject/Help/*.hhk +DocProject/Help/*.hhp +DocProject/Help/Html2 +DocProject/Help/html + +# Click-Once directory +publish/ + +# Publish Web Output +*.[Pp]ublish.xml +*.azurePubxml +## TODO: Comment the next line if you want to checkin your +## web deploy settings but do note that will include unencrypted +## passwords +*.pubxml + +# NuGet Packages Directory +packages/* +## TODO: If the tool you use requires repositories.config +## uncomment the next line +#!packages/repositories.config + +# Enable "build/" folder in the NuGet Packages folder since +# NuGet packages use it for MSBuild targets. +# This line needs to be after the ignore of the build folder +# (and the packages folder if the line above has been uncommented) +!packages/build/ + +# Windows Azure Build Output +csx/ +*.build.csdef + +# Windows Store app package directory +AppPackages/ + +# Others +sql/ +*.Cache +ClientBin/ +[Ss]tyle[Cc]op.* +~$* +*~ +*.dbmdl +*.dbproj.schemaview +*.pfx +*.publishsettings +node_modules/ + +# RIA/Silverlight projects +Generated_Code/ + +# Backup & report files from converting an old project file +# to a newer Visual Studio version. Backup files are not needed, +# because we have git ;-) +_UpgradeReport_Files/ +Backup*/ +UpgradeLog*.XML +UpgradeLog*.htm + +# SQL Server files +*.mdf +*.ldf + +# Business Intelligence projects +*.rdl.data +*.bim.layout +*.bim_*.settings + +# Microsoft Fakes +FakesAssemblies/