How to parse a Property List (plist) using C #

Recently I been working on a project using  Xamarin and came across a need to loads of logs 013-1parse a property list (plist).  After many Google searches my coworker sent my a Github repository with a plist class that will do the plist parsing in C#.  This has 2 main methods, a paser and a method to write a plist. I went on to write a class to work with it, including a method to create a plist and store it in a folder for an application. For it to work for me I had to delete many files. I think the only file you need is the plist.cs file which has the plist class (goes without saying).

Here is the code:


using System;
using System.Collections.Generic;
using System.IO;
using PlistCS;

namespace Apple
{
	public class PListLayer
	{
		Dictionary<string, object> dict;
		String file;
		public PListLayer (String filex)
		{
			this.dict = new Dictionary<string, object>
			{
				{"name12", "password12"}, 
				{"name11x", "password12x"}, 
				{"name13x", "password12x"},
				{"name14x", "password12x"} 
			};
			foreach (var mem in dict) 
			{
				Console.WriteLine("Value: {0}  Key {1}", mem.Value, mem.Key);
			}
			this.file = filex;
			this.writeToPList (this.file, this.dict);
		}

		public PListLayer (String filex, Dictionary <string, object> dictx)
		{
			this.dict = dictx;
			foreach (var mem in dict) 
			{
				Console.WriteLine("Value: {0}  Key {1}", mem.Value, mem.Key);
			}
			this.file = filex;
			this.writeToPList (this.file, this.dict);
		}

		public Boolean passwordExist(String value){
			// See whether Dictionary contains this string.
			if (this.dict.ContainsValue (value)) {
				Console.WriteLine ("password found");
				return true;
			} else
				Console.WriteLine ("password not found");
				return false;
		}

		public Boolean nameExist(String key){
			// See whether Dictionary contains this string.
		if (this.dict.ContainsKey (key)) {
			Console.WriteLine ("name found");
			return true;
		} 
			Console.WriteLine ("name not found");
			return false;
		}

		public object findPassword(String key){
			if (nameExist (key)) {
				var temp = dict [key];
				return temp;
			} else 
				return 0;
		}

		public Boolean correctPassword(String name, String passwordAttempt){
			if (nameExist (name) && passwordExist (passwordAttempt) ) {
				if (String.Compare (passwordAttempt , findPassword(name).ToString () ) == 0) {
					Console.WriteLine ("password match");
					return true;
				}
				return false;
			} else {
				Console.WriteLine ("password does not match");
				return false;
			}
		}

		public void writeToPList (String file, Dictionary <string, object> dict ){	
			var documents = Environment.GetFolderPath (Environment.SpecialFolder.MyDocuments);
			var filename = Path.Combine (documents, file);

			Plist.writeXml(dict, filename); 

			Dictionary<string, object>  temp = (Dictionary<string, object>)Plist.readPlist(filename);
			Console.WriteLine ("Writing to file.. ");
			foreach (var mem in temp) 
			{
				Console.WriteLine("Value: {0}  Key {1}", mem.Value, mem.Key);
			}
			Console.WriteLine ("Done writing to file");

		}

		public void changeValue(String file, Dictionary <string, object> dict, String key, String value){
			dict[key] = value;
			this.writeToPList (file, dict);
		}

		public void changeValue (String key, String value){
			changeValue (this.file, this.dict, key, value);
		}

		public void appendValue(String file, Dictionary<string, object> dict, String key, String value){
			dict.Add (key, value);
			this.writeToPList (file, dict);
		}

		public void appendValue(String key, String value){
			appendValue (this.file, this.dict, key, value);
		}

		public static void printPlist(String file){
			var documents = Environment.GetFolderPath (Environment.SpecialFolder.MyDocuments);
			var filename = Path.Combine (documents, file);

			Dictionary<string, object>  temp = (Dictionary<string, object>)Plist.readPlist(filename);
			Console.WriteLine ("Reading {0} file.. ", file);
			foreach (var mem in temp) 
			{
				Console.WriteLine("Value: {0}  Key {1}", mem.Value, mem.Key);
			}
			Console.WriteLine ("Done reading {0}", file);
		}

	}
}

Graveyard Database Logo

Has everything you want to know about grave yards. Plus has many celebrites and world leaders graves. Pssst it is my other site

Google + Profile
Check out Android Photo Mapping, its a app/site I been working on

  • wholesale nfl jerseys
  • wholesale nfl jerseys china
  • wholesale sports jerseys