Вы можете инкапсулировать список тривиально:
using System;
using System.Collections.Generic;
using System.Xml.Serialization;
[XmlRoot("user_list")]
public class UserList
{
public UserList() {Items = new List<User>();}
[XmlElement("user")]
public List<User> Items {get;set;}
}
public class User
{
[XmlElement("id")]
public Int32 Id { get; set; }
[XmlElement("name")]
public String Name { get; set; }
}
static class Program
{
static void Main()
{
XmlSerializer ser= new XmlSerializer(typeof(UserList));
UserList list = new UserList();
list.Items.Add(new User { Id = 1, Name = "abc"});
list.Items.Add(new User { Id = 2, Name = "def"});
list.Items.Add(new User { Id = 3, Name = "ghi"});
ser.Serialize(Console.Out, list);
}
}
I know you can register for the NSWorkspaceWillPowerOffNotification notification from NSWorkspace, which is not a C function but does work.
#import <AppKit/AppKit.h>
#import "WorkspaceResponder.h"
int main (int argc, const char * argv[]) {
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
NSNotificationCenter *nc = [[NSWorkspace sharedWorkspace] notificationCenter];
WorkspaceResponder *mainController = [[WorkspaceResponder alloc] init];
//register for shutdown notications
[nc addObserver:mainController
selector:@selector(computerWillShutDownNotification:)
name:NSWorkspaceWillPowerOffNotification object:nil];
[[NSRunLoop currentRunLoop] run];
[pool release];
return 0;
}
Then in WorkspaceResponder.m:
- (void) computerWillShutDownNotification:(NSNotification *)notification {
NSLog(@"Received Shutdown Notification");
}