public void CreateDictionary() { string[] keys = { "WOOOTSDLKFJSDLKFDS:", "alsudhflka", "lknadlnladnf" }; NSObject[] objects = { new NSObject(), new NSObject(), new NSObject() }; var dictionary = NSDictionary.FromObjectsAndKeys(objects, keys); var newDictionary = NSDictionary.FromDictionary(dictionary); Assert.AreEqual(3, newDictionary.Values.Length); Assert.AreEqual(3, newDictionary.Keys.Length); }
public override void AddTriggers(Dictionary<string, object> triggers) { var triggersDictionary = new NSMutableDictionary<NSString, NSObject>(); foreach (var element in triggers) { triggersDictionary.Add( NSString.FromData(element.Key, NSStringEncoding.UTF8), NSObject.FromObject(element.Value)); } iOS.OneSignal.AddTriggers(NSDictionary.FromDictionary(triggersDictionary)); }
private NSDictionary NSDictionaryFromDictionary(Dictionary <string, object> dictionary) { NSMutableDictionary newDictionary = new NSMutableDictionary(); foreach (var key in dictionary.Keys) { object value = dictionary[key]; if (value is string) { newDictionary.Add(new NSString(key), new NSString((string)value)); } else if (value is int) { newDictionary.Add(new NSString(key), NSNumber.FromInt32((int)value)); } else if (value is bool) { newDictionary.Add(new NSString(key), NSNumber.FromBoolean((bool)value)); } /*else if (value is DateTime) * newDictionary.Add (new NSString (key), MacLib.MacHelpers.DateTimeToNSDate((DateTime)value));*/ else if (value is List <string> ) { List <string> list = value as List <string>; if (list == null) { list = new List <string>(); } StringWriter sw = new StringWriter(); XmlSerializer s = new XmlSerializer(list.GetType()); s.Serialize(sw, list); newDictionary.Add(new NSString(key), new NSString((string)list.ToString())); } else if (value is ServersFilterConfig) { newDictionary.Add(new NSString(key), new NSString(((ServersFilterConfig)value).Serialize())); } else if (value is NetworkActionsConfig) { newDictionary.Add(new NSString(key), new NSString(((NetworkActionsConfig)value).Serialize())); } else { throw new InvalidOperationException("Unsupported property type in Settings Defaults"); } } return(NSDictionary.FromDictionary(newDictionary)); }
partial void ibssOKButtonPressed(NSObject sender) { ibssSpinner.Hidden = false; ibssSpinner.StartAnimation(this); string networkName = ibssNetworkNameField.StringValue; NSNumber channel = new NSNumber(Convert.ToInt32(ibssChannelPopupButton.SelectedItem.Title)); string passPhrase = ibssPassphraseField.StringValue; NSMutableDictionary ibssParams = new NSMutableDictionary(); if (!(String.IsNullOrEmpty(networkName))) { ibssParams.SetValueForKey(ibssNetworkNameField.ObjectValue, CWConstants.CWIBSSKeySSID); } if (channel.IntValue > 0) { ibssParams.SetValueForKey(channel, CWConstants.CWIBSSKeyChannel); } if (!(String.IsNullOrEmpty(passPhrase))) { ibssParams.SetValueForKey(ibssPassphraseField.ObjectValue, CWConstants.CWIBSSKeyPassphrase); } NSError error = null; bool created = CurrentInterface.EnableIBSSWithParameters(NSDictionary.FromDictionary(ibssParams), out error); ibssSpinner.StopAnimation(this); ibssSpinner.Hidden = true; if (!created) { NSAlert.WithError(error).RunModal(); } else { ibssCancelButtonPressed(this); } }
public static User UserWithDictionary(NSDictionary dictionary) { string name = (NSString)dictionary.ObjectForKey(new NSString("name")); var conversationDictionaries = (NSArray)dictionary.ObjectForKey(new NSString("conversations")); var conversations = new NSMutableArray(conversationDictionaries.Count); for (nuint i = 0; i < conversationDictionaries.Count; i++) { var conversation = Conversation.ConversationWithDictionary(conversationDictionaries.GetItem <NSDictionary> (i)); conversations.Add(conversation); } var lastPhotoDictionary = NSDictionary.FromDictionary((NSDictionary)dictionary.ObjectForKey(new NSString("lastPhoto"))); return(new User { Name = name, Conversations = conversations, LastPhoto = Photo.PhotoWithDictionary(lastPhotoDictionary) }); }
partial void joinOKButtonPressed(NSObject sender) { CW8021XProfile profile = null; joinSpinner.Hidden = false; joinSpinner.StartAnimation(Window); if (joinUser8021XProfilePopupButton.Enabled) { if (String.Equals(joinUser8021XProfilePopupButton, "Default")) { profile = CW8021XProfile.Profile; profile.Ssid = joinNetworkNameField.StringValue; profile.UserDefinedName = joinNetworkNameField.StringValue; profile.Username = !String.IsNullOrEmpty(joinUsernameField.StringValue) ? joinUsernameField.StringValue : null; profile.Password = !String.IsNullOrEmpty(joinPassphraseField.StringValue) ? joinPassphraseField.StringValue : null; } else { var index = joinUser8021XProfilePopupButton.IndexOfSelectedItem; if (index >= 0) { profile = CW8021XProfile.AllUser8021XProfiles[index]; } } } if (JoinDialogContext) { NSMutableDictionary param = new NSMutableDictionary(); if (profile != null) { param.SetValueForKey(profile, CWConstants.CWAssocKey8021XProfile); } else { param.SetValueForKey(!String.IsNullOrEmpty(joinPassphraseField.StringValue) ? joinPassphraseField.ObjectValue: null, CWConstants.CWAssocKeyPassPhrase); } NSError error = null; bool result = CurrentInterface.AssociateToNetwork(SelectedNetwork, NSDictionary.FromDictionary(param), out error); joinSpinner.StopAnimation(Window); joinSpinner.Hidden = true; if (!result) { NSAlert.WithError(error).RunModal(); } else { joinCancelButtonPressed(this); } } }
NSDictionary Options() { var keys = new NSString[] { Constants.kCRToastNotificationTypeKey, Constants.kCRToastNotificationPresentationTypeKey, Constants.kCRToastUnderStatusBarKey, Constants.kCRToastTextKey, Constants.kCRToastTextAlignmentKey, Constants.kCRToastTimeIntervalKey, Constants.kCRToastAnimationInTypeKey, Constants.kCRToastAnimationOutTypeKey, Constants.kCRToastAnimationInDirectionKey, Constants.kCRToastAnimationOutDirectionKey, Constants.kCRToastNotificationPreferredPaddingKey }; var objects = new NSObject[] { NSNumber.FromInt64((long)(coverNavBarSwitch.On ? CRToastType.NavigationBar : CRToastType.StatusBar)), NSNumber.FromInt64((long)(SlideOverSwitch.On ? CRToastPresentationType.Cover : CRToastPresentationType.Push)), NSNumber.FromBoolean(SlideUnderSwitch.On), (NSString)TxtNotificationMessage.Text, NSNumber.FromInt64((long)_TextAlignment), NSNumber.FromDouble(SliderDuration.Value), NSNumber.FromInt64(InAnimationTypeSegmentedControl.SelectedSegment), NSNumber.FromInt64(OutAnimationTypeSegmentedControl.SelectedSegment), NSNumber.FromInt64(SegFromDirection.SelectedSegment), NSNumber.FromInt64(SegToDirection.SelectedSegment), NSNumber.FromDouble(SliderPadding.Value) }; var options = NSMutableDictionary.FromObjectsAndKeys(objects, keys); if (ShowImageSwitch.On) { options.Add(Constants.kCRToastImageKey, UIImage.FromFile("alert_icon.png")); options.Add(Constants.kCRToastImageAlignmentKey, NSNumber.FromInt64(ImageAlignmentSegmentedControl.SelectedSegment)); } if (ImageTintEnabledSwitch.On) { options.Add(Constants.kCRToastImageTintKey, UIColor.FromHSB(ImageTintSlider.Value, 1.0f, 1.0f)); } if (ShowActivityIndicatorSwitch.On) { options.Add(Constants.kCRToastShowActivityIndicatorKey, NSNumber.FromBoolean(true)); options.Add(Constants.kCRToastActivityIndicatorAlignmentKey, NSNumber.FromInt64(ActivityIndicatorAlignmentSegementControl.SelectedSegment)); } if (ForceUserInteractionSwitch.On) { options.Add(Constants.kCRToastForceUserInteractionKey, NSNumber.FromBoolean(true)); } if (!string.IsNullOrEmpty(TxtNotificationMessage.Text)) { options.Add(Constants.kCRToastIdentifierKey, (NSString)TxtNotificationMessage.Text); } if (!string.IsNullOrEmpty(TxtSubtitleMessage.Text)) { options.Add(Constants.kCRToastSubtitleTextKey, (NSString)TxtSubtitleMessage.Text); options.Add(Constants.kCRToastSubtitleTextAlignmentKey, NSNumber.FromInt64(SegSubtitleAlignment.SelectedSegment)); } if (DismissibleWithTapSwitch.On) { options.Add(Constants.kCRToastInteractionRespondersKey, CRToastInteractionResponder.InteractionResponderWithInteractionType(CRToastInteractionType.Tap, true, (interactionType) => { System.Diagnostics.Debug.WriteLine($"Dismissed with {interactionType} interaction"); }) ); } return(NSDictionary.FromDictionary(options)); }