The question is a bit complicated so I will try and explain. I have a custom .plist (XML Property List) file I created with Xcode. Within it is many different types of data: NSDictionary, NSArray, NSString, BOOL, etc.
Here's an example:
In my code I can quickly obtain an NSDictionary
of this entire file without knowing an data types using the following code (this is ARC code by the way). The only data types that I DO know of is that all of the keys are strings, but the values can be anything I've shown above:
+ (NSDictionary *)configDictionary
{
collectorstemplateAppDelegate *appDelegate = (collectorstemplateAppDelegate*)
[[UIApplication sharedApplication] delegate];
NSString *path = [[NSBundle mainBundle]
pathForResource:appDelegate.currentPlist ofType:@"plist"];
NSDictionary *dict = [[NSDictionary alloc] initWithContentsOfFile:path];
return dict;
}
What I am trying to do is to accomplish the same thing on C#. I'd like to take these plists and move them to my Windows Phone phone apps, keeping the same structure. I realize that I will need to write some additional code to handle the XML behind the file, but you get the idea.... I want a Dictionary
or HashTable
or Collection
of something similar to what I've done above, without knowing the types of the values.
Obviously in my case something like Dictionary<string, string>
isn't going to work for me.
Any help would be great.
Answering my own question here but looking for validation....
Would Dictionary<string, object>
work? Because I know the key is a string, I would just need to cast the value to the appropriate type, correct?
int appleID = (int) plistDict["appleid"];
If this is correct or incorrect, someone please let me know.
Hashtable is a non-generic version of Dictionary. In other words it doesn't require you to specify the types it deals with, and you can cash like you would in Objective-C.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.