mirror of
https://github.com/claunia/plist-cil.git
synced 2025-12-16 19:14:26 +00:00
Enable syntax highlighting for code snippets
This commit is contained in:
committed by
GitHub
parent
7f98f27448
commit
e16fd79e30
120
README.md
120
README.md
@@ -71,78 +71,82 @@ For converting a file into another format there exist convenience methods in the
|
|||||||
|
|
||||||
### Reading
|
### Reading
|
||||||
|
|
||||||
try
|
```csharp
|
||||||
|
try
|
||||||
|
{
|
||||||
|
FileInfo file = new FileInfo("Info.plist");
|
||||||
|
NSDictionary rootDict = (NSDictionary)PropertyListParser.Parse(file);
|
||||||
|
string name = rootDict.ObjectForKey("Name").ToString();
|
||||||
|
NSObject[] parameters = ((NSArray)rootDict.ObjectForKey("Parameters")).GetArray();
|
||||||
|
foreach(NSObject param in parameters)
|
||||||
{
|
{
|
||||||
FileInfo file = new FileInfo("Info.plist");
|
if(param.GetType().Equals(typeof(NSNumber)))
|
||||||
NSDictionary rootDict = (NSDictionary)PropertyListParser.Parse(file);
|
|
||||||
string name = rootDict.ObjectForKey("Name").ToString();
|
|
||||||
NSObject[] parameters = ((NSArray)rootDict.ObjectForKey("Parameters")).GetArray();
|
|
||||||
foreach(NSObject param in parameters)
|
|
||||||
{
|
{
|
||||||
if(param.GetType().Equals(typeof(NSNumber)))
|
NSNumber num = (NSNumber)param;
|
||||||
|
switch(num.GetNSNumberType())
|
||||||
{
|
{
|
||||||
NSNumber num = (NSNumber)param;
|
case NSNumber.BOOLEAN:
|
||||||
switch(num.GetNSNumberType())
|
|
||||||
{
|
{
|
||||||
case NSNumber.BOOLEAN:
|
boolean bool = num.ToBool();
|
||||||
{
|
// ...
|
||||||
boolean bool = num.ToBool();
|
break;
|
||||||
// ...
|
}
|
||||||
break;
|
case NSNumber.INTEGER:
|
||||||
}
|
{
|
||||||
case NSNumber.INTEGER:
|
long l = num.ToLong();
|
||||||
{
|
// or int i = num.ToInt();
|
||||||
long l = num.ToLong();
|
// ...
|
||||||
// or int i = num.ToInt();
|
break;
|
||||||
// ...
|
}
|
||||||
break;
|
case NSNumber.REAL:
|
||||||
}
|
{
|
||||||
case NSNumber.REAL:
|
double d = num.ToDouble();
|
||||||
{
|
// ...
|
||||||
double d = num.ToDouble();
|
break;
|
||||||
// ...
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// else...
|
|
||||||
}
|
}
|
||||||
|
// else...
|
||||||
}
|
}
|
||||||
catch(Exception ex)
|
}
|
||||||
{
|
catch(Exception ex)
|
||||||
Console.WriteLine(ex.StackTrace);
|
{
|
||||||
}
|
Console.WriteLine(ex.StackTrace);
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
### Writing
|
### Writing
|
||||||
|
|
||||||
// Creating the root object
|
```csharp
|
||||||
NSDictionary root = new NSDictionary();
|
// Creating the root object
|
||||||
|
NSDictionary root = new NSDictionary();
|
||||||
|
|
||||||
// Creation of an array of length 2
|
// Creation of an array of length 2
|
||||||
NSArray people = new NSArray(2);
|
NSArray people = new NSArray(2);
|
||||||
|
|
||||||
// Creation of the first object to be stored in the array
|
// Creation of the first object to be stored in the array
|
||||||
NSDictionary person1 = new NSDictionary();
|
NSDictionary person1 = new NSDictionary();
|
||||||
// The NSDictionary will automatically wrap strings, numbers and dates in the respective NSObject subclasses
|
// The NSDictionary will automatically wrap strings, numbers and dates in the respective NSObject subclasses
|
||||||
person1.Add("Name", "Peter"); // This will become a NSString
|
person1.Add("Name", "Peter"); // This will become a NSString
|
||||||
// Use the DateTime class
|
// Use the DateTime class
|
||||||
person1.Add("RegistrationDate", new DateTime(2011, 1, 13, 9, 28, 0)); // This will become a NSDate
|
person1.Add("RegistrationDate", new DateTime(2011, 1, 13, 9, 28, 0)); // This will become a NSDate
|
||||||
person1.Add("Age", 23); // This will become a NSNumber
|
person1.Add("Age", 23); // This will become a NSNumber
|
||||||
person1.Add("Photo", new NSData(new FileInfo("peter.jpg")));
|
person1.Add("Photo", new NSData(new FileInfo("peter.jpg")));
|
||||||
|
|
||||||
// Creation of the second object to be stored in the array
|
// Creation of the second object to be stored in the array
|
||||||
NSDictionary person2 = new NSDictionary();
|
NSDictionary person2 = new NSDictionary();
|
||||||
person2.Add("Name", "Lisa");
|
person2.Add("Name", "Lisa");
|
||||||
person2.Add("Age", 42);
|
person2.Add("Age", 42);
|
||||||
person2.Add("RegistrationDate", new NSDate("2010-09-23T12:32:42Z"));
|
person2.Add("RegistrationDate", new NSDate("2010-09-23T12:32:42Z"));
|
||||||
person2.Add("Photo", new NSData(new FileInfo("lisa.jpg")));
|
person2.Add("Photo", new NSData(new FileInfo("lisa.jpg")));
|
||||||
|
|
||||||
// Put the objects into the array
|
// Put the objects into the array
|
||||||
people.SetValue(0, person1);
|
people.SetValue(0, person1);
|
||||||
people.SetValue(1, person2);
|
people.SetValue(1, person2);
|
||||||
|
|
||||||
// Put the array into the property list
|
// Put the array into the property list
|
||||||
root.Add("People", people);
|
root.Add("People", people);
|
||||||
|
|
||||||
// Save the property list
|
// Save the property list
|
||||||
PropertyListParser.SaveAsXml(root, new FileInfo("people.plist"));
|
PropertyListParser.SaveAsXml(root, new FileInfo("people.plist"));
|
||||||
|
```
|
||||||
|
|||||||
Reference in New Issue
Block a user