本文整理汇总了C#中NSDictionary.Add方法的典型用法代码示例。如果您正苦于以下问题:C# NSDictionary.Add方法的具体用法?C# NSDictionary.Add怎么用?C# NSDictionary.Add使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类NSDictionary
的用法示例。
在下文中一共展示了NSDictionary.Add方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ParseObject
/// <summary>
/// Parses a node in the XML structure and returns the corresponding NSObject
/// </summary>
/// <returns>The corresponding NSObject.</returns>
/// <param name="n">The XML node.</param>
static NSObject ParseObject(XmlNode n)
{
if (n.Name.Equals("dict"))
{
NSDictionary dict = new NSDictionary();
List<XmlNode> children = FilterElementNodes(n.ChildNodes);
for (int i = 0; i < children.Count; i += 2)
{
XmlNode key = children[i];
XmlNode val = children[i + 1];
string keyString = GetNodeTextContents(key);
dict.Add(keyString, ParseObject(val));
}
return dict;
}
if (n.Name.Equals("array"))
{
List<XmlNode> children = FilterElementNodes(n.ChildNodes);
NSArray array = new NSArray(children.Count);
for (int i = 0; i < children.Count; i++)
{
array.Add(ParseObject(children[i]));
}
return array;
}
if (n.Name.Equals("true"))
return new NSNumber(true);
if (n.Name.Equals("false"))
return new NSNumber(false);
if (n.Name.Equals("integer"))
return new NSNumber(GetNodeTextContents(n), NSNumber.INTEGER);
if (n.Name.Equals("real"))
return new NSNumber(GetNodeTextContents(n), NSNumber.REAL);
if (n.Name.Equals("string"))
return new NSString(GetNodeTextContents(n));
if (n.Name.Equals("data"))
return new NSData(GetNodeTextContents(n));
return n.Name.Equals("date") ? new NSDate(GetNodeTextContents(n)) : null;
}
示例2: GenerateAndSavePlist
public virtual void GenerateAndSavePlist(string PlistFileName, string IPAName, string IconName, string BundleIdentifier, string BundleVersion, string BundleDisplayName)
{
string HTTPRoot = GetParamOrConfigString(OTAHTTPRootFlag, "iOS OTA HTTP root path is not set. Can't generate the OTA manifest.");
if(!HTTPRoot.EndsWith("/"))
{
HTTPRoot += "/";
}
if(HTTPRoot.StartsWith("http:"))
{
HTTPRoot = HTTPRoot.Replace("http:", "https:");
}
if(!HTTPRoot.StartsWith("https://"))
{
HTTPRoot = "https://" + HTTPRoot;
}
NSDictionary SoftwarePackageDict = new NSDictionary();
SoftwarePackageDict.Add("kind", new NSString("software-package"));
SoftwarePackageDict.Add("url", new NSString(HTTPRoot + IPAName));
NSDictionary DisplayImageDict = new NSDictionary();
DisplayImageDict.Add("kind", new NSString("display-image"));
DisplayImageDict.Add("needs-shine", new NSNumber(false));
DisplayImageDict.Add("url", new NSString(HTTPRoot + IconName));
NSArray AssetsArray = new NSArray(new NSObject[] { SoftwarePackageDict, DisplayImageDict });
NSDictionary MetadataDict = new NSDictionary();
MetadataDict.Add("bundle-identifier", new NSString(BundleIdentifier));
MetadataDict.Add("bundle-version", new NSString(BundleVersion));
MetadataDict.Add("kind", new NSString("software"));
MetadataDict.Add("title", new NSString(BundleDisplayName));
NSDictionary Item0Dict = new NSDictionary();
Item0Dict.Add("assets", AssetsArray);
Item0Dict.Add("metadata", MetadataDict);
NSArray ItemsArray = new NSArray(new NSObject[] { Item0Dict });
NSDictionary RootDictionary = new NSDictionary();
RootDictionary.Add("items", ItemsArray);
FileInfo NewPlist = new FileInfo(PlistFileName);
PropertyListParser.SaveAsXml(RootDictionary, NewPlist);
}
示例3: Wrap
//.........这里部分代码省略.........
}
if (typeof(short).Equals(c))
{
return Wrap((int)(short)o);
}
if (typeof(int).Equals(c))
{
return Wrap((int)(int)o);
}
if (typeof(long).IsAssignableFrom(c))
{
return Wrap((long)o);
}
if (typeof(float).Equals(c))
{
return Wrap((double)(float)o);
}
if (typeof(double).IsAssignableFrom(c))
{
return Wrap((double)o);
}
if (typeof(string).Equals(c))
{
return new NSString((string)o);
}
if (typeof(DateTime).Equals(c))
{
return new NSDate((DateTime)o);
}
if (c.IsArray)
{
Type cc = c.GetElementType();
if (cc.Equals(typeof(byte)))
{
return Wrap((byte[])o);
}
if (cc.Equals(typeof(bool)))
{
bool[] array = (bool[])o;
NSArray nsa = new NSArray(array.Length);
for (int i = 0; i < array.Length; i++)
nsa.SetValue(i, Wrap(array[i]));
return nsa;
}
if (cc.Equals(typeof(float)))
{
float[] array = (float[])o;
NSArray nsa = new NSArray(array.Length);
for (int i = 0; i < array.Length; i++)
nsa.SetValue(i, Wrap(array[i]));
return nsa;
}
if (cc.Equals(typeof(double)))
{
double[] array = (double[])o;
NSArray nsa = new NSArray(array.Length);
for (int i = 0; i < array.Length; i++)
nsa.SetValue(i, Wrap(array[i]));
return nsa;
}
if (cc.Equals(typeof(short)))
{
short[] array = (short[])o;
NSArray nsa = new NSArray(array.Length);
for (int i = 0; i < array.Length; i++)
nsa.SetValue(i, Wrap(array[i]));
return nsa;
}
if (cc.Equals(typeof(int)))
{
int[] array = (int[])o;
NSArray nsa = new NSArray(array.Length);
for (int i = 0; i < array.Length; i++)
nsa.SetValue(i, Wrap(array[i]));
return nsa;
}
if (cc.Equals(typeof(long)))
{
long[] array = (long[])o;
NSArray nsa = new NSArray(array.Length);
for (int i = 0; i < array.Length; i++)
nsa.SetValue(i, Wrap(array[i]));
return nsa;
}
return Wrap((Object[])o);
}
if (typeof(Dictionary<string,Object>).IsAssignableFrom(c))
{
Dictionary<string,Object> netDict = (Dictionary<string,Object>)o;
NSDictionary dict = new NSDictionary();
foreach (KeyValuePair<string, Object> kvp in netDict)
{
dict.Add(kvp.Key, Wrap(kvp.Value));
}
return dict;
}
if (typeof(List<Object>).IsAssignableFrom(c))
return Wrap(((List<Object>)o).ToArray());
return WrapSerialized(o);
}
示例4: ParseDictionary
/// <summary>
/// Parses a dictionary from the current parsing position.
/// The prerequisite for calling this method is, that a dictionary begin token has been read.
/// </summary>
/// <returns>The dictionary found at the parsing position.</returns>
NSDictionary ParseDictionary()
{
//Skip begin token
Skip();
SkipWhitespacesAndComments();
NSDictionary dict = new NSDictionary();
while (!Accept(DICTIONARY_END_TOKEN))
{
//Parse key
string keyString;
if (Accept(QUOTEDSTRING_BEGIN_TOKEN))
keyString = ParseQuotedString();
else
keyString = ParseString();
SkipWhitespacesAndComments();
//Parse assign token
Read(DICTIONARY_ASSIGN_TOKEN);
SkipWhitespacesAndComments();
NSObject nso = ParseObject();
dict.Add(keyString, nso);
SkipWhitespacesAndComments();
Read(DICTIONARY_ITEM_DELIMITER_TOKEN);
SkipWhitespacesAndComments();
}
//skip end token
Skip();
return dict;
}
示例5: ParseObject
//.........这里部分代码省略.........
length *= 2;
return new NSString(CopyOfRange(bytes, offset + stroffset, offset + stroffset + length), "UTF-16BE");
}
case 0x7:
{
//UTF-8 string (v1.0 and later)
int[] lengthAndOffset = ReadLengthAndOffset(objInfo, offset);
int strOffset = lengthAndOffset[1];
int characters = lengthAndOffset[0];
//UTF-8 characters can have variable length, so we need to calculate the byte length dynamically
//by reading the UTF-8 characters one by one
int length = CalculateUtf8StringLength(bytes, offset + strOffset, characters);
return new NSString(CopyOfRange(bytes, offset + strOffset, offset + strOffset + length), "UTF-8");
}
case 0x8:
{
//UID (v1.0 and later)
int length = objInfo + 1;
return new UID(obj.ToString(), CopyOfRange(bytes, offset + 1, offset + 1 + length));
}
case 0xA:
{
//Array
int[] lengthAndOffset = ReadLengthAndOffset(objInfo, offset);
int length = lengthAndOffset[0];
int arrayOffset = lengthAndOffset[1];
NSArray array = new NSArray(length);
for (int i = 0; i < length; i++)
{
int objRef = (int)ParseUnsignedInt(CopyOfRange(bytes,
offset + arrayOffset + i * objectRefSize,
offset + arrayOffset + (i + 1) * objectRefSize));
array.Add(ParseObject(objRef));
}
return array;
}
case 0xB:
{
//Ordered set (v1.0 and later)
int[] lengthAndOffset = ReadLengthAndOffset(objInfo, offset);
int length = lengthAndOffset[0];
int contentOffset = lengthAndOffset[1];
NSSet set = new NSSet(true);
for (int i = 0; i < length; i++)
{
int objRef = (int)ParseUnsignedInt(CopyOfRange(bytes,
offset + contentOffset + i * objectRefSize,
offset + contentOffset + (i + 1) * objectRefSize));
set.AddObject(ParseObject(objRef));
}
return set;
}
case 0xC:
{
//Set (v1.0 and later)
int[] lengthAndOffset = ReadLengthAndOffset(objInfo, offset);
int length = lengthAndOffset[0];
int contentOffset = lengthAndOffset[1];
NSSet set = new NSSet();
for (int i = 0; i < length; i++)
{
int objRef = (int)ParseUnsignedInt(CopyOfRange(bytes,
示例6: AddBundleURLType
public static void AddBundleURLType(IIgorModule ModuleInst, string PlistPath, string NewURLScheme)
{
if(IgorAssert.EnsureTrue(ModuleInst, File.Exists(PlistPath), "Plist " + PlistPath + " doesn't exist!"))
{
FileInfo PlistFileInfo = new FileInfo(PlistPath);
NSObject PlistRoot = PropertyListParser.Parse(PlistFileInfo);
if(IgorAssert.EnsureTrue(ModuleInst, PlistRoot != null, "Plist " + PlistPath + " could not be parsed!"))
{
if(IgorAssert.EnsureTrue(ModuleInst, typeof(NSDictionary).IsAssignableFrom(PlistRoot.GetType()), "Plist " + PlistPath + " root object is not a dictionary."))
{
NSDictionary RootDictionary = (NSDictionary)PlistRoot;
if(IgorAssert.EnsureTrue(ModuleInst, RootDictionary != null, "Plist root is not a dictionary."))
{
NSSet BundleURLTypes = null;
if(RootDictionary.ContainsKey("CFBundleURLTypes"))
{
NSObject BundleURLTypesObj = RootDictionary.Get("CFBundleURLTypes");
if(IgorAssert.EnsureTrue(ModuleInst, BundleURLTypesObj != null, "CFBundleURLTypes wasn't found in the root dictionary even though the key exists."))
{
if(IgorAssert.EnsureTrue(ModuleInst, typeof(NSArray).IsAssignableFrom(BundleURLTypesObj.GetType()), "CFBundleURLTypes isn't an NSArray."))
{
BundleURLTypes = new NSSet(((NSArray)BundleURLTypesObj).GetArray());
}
}
}
if(BundleURLTypes == null)
{
BundleURLTypes = new NSSet();
}
bool bAlreadyExists = false;
foreach(NSObject CurrentURLType in BundleURLTypes)
{
if(bAlreadyExists)
{
break;
}
if(IgorAssert.EnsureTrue(ModuleInst, typeof(NSDictionary).IsAssignableFrom(CurrentURLType.GetType()), "One of the CFBundleURLTypes isn't an NSDictionary."))
{
NSDictionary CurrentURLTypeDict = (NSDictionary)CurrentURLType;
if(IgorAssert.EnsureTrue(ModuleInst, CurrentURLTypeDict != null, "One of the CFBundleURLTypes didn't cast to NSDictionary correctly."))
{
if(CurrentURLTypeDict.ContainsKey("CFBundleURLSchemes"))
{
NSObject CurrentURLSchemesArrayObj = CurrentURLTypeDict.Get("CFBundleURLSchemes");
if(IgorAssert.EnsureTrue(ModuleInst, typeof(NSArray).IsAssignableFrom(CurrentURLSchemesArrayObj.GetType()), "A CFBundleURLSchemes key exists for a given CFBundleURLType, but it's not an NSArray type."))
{
NSArray CurrentURLSchemesArray = (NSArray)CurrentURLSchemesArrayObj;
if(IgorAssert.EnsureTrue(ModuleInst, CurrentURLSchemesArray != null, "The CFBundleURLSchemes object didn't cast to NSDictionary correctly."))
{
NSSet CurrentURLSchemesSet = new NSSet(CurrentURLSchemesArray.GetArray());
foreach(NSObject CurrentURLSchemeObj in CurrentURLSchemesSet)
{
if(IgorAssert.EnsureTrue(ModuleInst, typeof(NSString).IsAssignableFrom(CurrentURLSchemeObj.GetType()), "One of the CFBundleURLSchemes is not an NSString."))
{
NSString CurrentURLScheme = (NSString)CurrentURLSchemeObj;
if(IgorAssert.EnsureTrue(ModuleInst, CurrentURLScheme != null, "A CFBundleURLScheme entry didn't cast to NSString correctly."))
{
if(CurrentURLScheme.GetContent() == NewURLScheme)
{
bAlreadyExists = true;
IgorDebug.Log(ModuleInst, "URL scheme " + NewURLScheme + " is already in " + PlistPath);
break;
}
}
}
}
}
}
}
}
}
}
if(!bAlreadyExists)
{
NSString NewSchemeString = new NSString(NewURLScheme);
NSArray NewSchemeArray = new NSArray(1);
NewSchemeArray.SetValue(0, NewSchemeString);
NSDictionary NewTypeDictionary = new NSDictionary();
NewTypeDictionary.Add("CFBundleURLSchemes", NewSchemeArray);
//.........这里部分代码省略.........
示例7: GetConditionals
private NSArray GetConditionals()
{
var uniqueConditions = GetAllUniqueConditions();
NSArray conditionalItems = new NSArray(uniqueConditions.Count);
var uniqueConditionsCounter = 0;
foreach (var uniqueCondition in uniqueConditions)
{
NSDictionary condition = new NSDictionary();
condition.Add("condition", uniqueCondition);
conditionalItems.SetValue(uniqueConditionsCounter, condition);
uniqueConditionsCounter++;
NSArray plIncludedManifests = GetIncludedManifests(uniqueCondition);
NSArray plManagedInstalls = GetManagedInstalls(uniqueCondition);
NSArray plManagedUninstalls = GetManagedUninstalls(uniqueCondition);
NSArray plManagedUpdates = GetManagedUpdates(uniqueCondition);
NSArray plOptionalInstalls = GetOptionlInstalls(uniqueCondition);
if (plIncludedManifests.Count > 0)
condition.Add("included_manifests", plIncludedManifests);
if (plManagedInstalls.Count > 0)
condition.Add("managed_installs", plManagedInstalls);
if (plManagedUninstalls.Count > 0)
condition.Add("managed_uninstalls", plManagedUninstalls);
if (plManagedUpdates.Count > 0)
condition.Add("managed_updates", plManagedUpdates);
if (plOptionalInstalls.Count > 0)
condition.Add("optional_installs", plOptionalInstalls);
}
return conditionalItems;
}
示例8: GeneratePlist
private MemoryStream GeneratePlist()
{
NSDictionary root = new NSDictionary();
NSArray plCatalogs = GetCatalogs();
NSArray plConditionals = GetConditionals();
NSArray plIncludedManifests = GetIncludedManifests();
NSArray plManagedInstalls = GetManagedInstalls();
NSArray plManagedUninstalls = GetManagedUninstalls();
NSArray plManagedUpdates = GetManagedUpdates();
NSArray plOptionalInstalls = GetOptionlInstalls();
if (plCatalogs.Count > 0) root.Add("catalogs", plCatalogs);
if (plConditionals.Count > 0) root.Add("conditional_items", plConditionals);
if (plIncludedManifests.Count > 0) root.Add("included_manifests", plIncludedManifests);
if (plManagedInstalls.Count > 0) root.Add("managed_installs", plManagedInstalls);
if (plManagedUninstalls.Count > 0) root.Add("managed_uninstalls", plManagedUninstalls);
if (plManagedUpdates.Count > 0) root.Add("managed_updates", plManagedUpdates);
if (plOptionalInstalls.Count > 0) root.Add("optional_installs", plOptionalInstalls);
var rdr = new MemoryStream();
try
{
PropertyListParser.SaveAsXml(root, rdr);
}
catch (Exception ex)
{
Logger.Log(ex.Message);
}
return rdr;
}