Enable syntax highlighting for code snippets

This commit is contained in:
Ruben Schmidmeister
2020-08-12 15:20:02 +02:00
committed by GitHub
parent 7f98f27448
commit e16fd79e30

View File

@@ -71,8 +71,9 @@ For converting a file into another format there exist convenience methods in the
### Reading ### Reading
try ```csharp
{ try
{
FileInfo file = new FileInfo("Info.plist"); FileInfo file = new FileInfo("Info.plist");
NSDictionary rootDict = (NSDictionary)PropertyListParser.Parse(file); NSDictionary rootDict = (NSDictionary)PropertyListParser.Parse(file);
string name = rootDict.ObjectForKey("Name").ToString(); string name = rootDict.ObjectForKey("Name").ToString();
@@ -107,42 +108,45 @@ For converting a file into another format there exist convenience methods in the
} }
// 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"));
```