StripKeysWithNullValues









How do I use Strip Keys With Null Values
Below are practical examples compiled from projects for learning and reference purposes

Featured Snippets


File name: Extensions.cs Copy
139     public static void StripKeysWithNullValues(this IDictionary original)
140     {
141         object[] keys = new object[original.Count];
142         //original.Keys.CopyTo(keys, 0);
143         int i = 0;
144         foreach (object k in original.Keys)
145         {
146             keys[i++] = k;
147         }
148
149         for (int index = 0; index < keys.Length; index++)
150         {
151             var key = keys[index];
152             if (original[key] == null)
153             {
154                 original.Remove(key);
155             }
156         }
157     }
File name: PhotonPlayer.cs Copy
152     internal void InternalCacheProperties(Hashtable properties)
153     {
154         if (properties == null || properties.Count == 0 || this.customProperties.Equals(properties))
155         {
156             return;
157         }
158
159         if (properties.ContainsKey(ActorProperties.PlayerName))
160         {
161             this.nameField = (string)properties[ActorProperties.PlayerName];
162         }
163
164         this.customProperties.MergeStringKeys(properties);
165         this.customProperties.StripKeysWithNullValues();
166     }
File name: PhotonPlayer.cs Copy
184     public void SetCustomProperties(Hashtable propertiesToSet)
185     {
186         if (propertiesToSet == null)
187         {
188             return;
189         }
190
191         // merge (delete null-values)
192         this.customProperties.MergeStringKeys(propertiesToSet); // includes a Equals check (simplifying things)
193         this.customProperties.StripKeysWithNullValues();
194
195         // send (sync) these new values
196         Hashtable customProps = propertiesToSet.StripToStringKeys() as Hashtable;
197         if (this.actorID > 0 && !PhotonNetwork.offlineMode)
198         {
199             PhotonNetwork.networkingPeer.OpSetCustomPropertiesOfActor(this.actorID, customProps, true, 0);
200         }
201         NetworkingPeer.SendMonoMessage(PhotonNetworkingMessage.OnPhotonPlayerPropertiesChanged, this, propertiesToSet);
202     }
File name: Room.cs Copy
196     public void SetCustomProperties(Hashtable propertiesToSet)
197     {
198         if (propertiesToSet == null)
199         {
200             return;
201         }
202
203         // merge (delete null-values)
204         this.customProperties.MergeStringKeys(propertiesToSet); // includes a Equals check (simplifying things)
205         this.customProperties.StripKeysWithNullValues();
206
207
208         // send (sync) these new values
209         Hashtable customProps = propertiesToSet.StripToStringKeys() as Hashtable;
210         if (!PhotonNetwork.offlineMode)
211         {
212             PhotonNetwork.networkingPeer.OpSetCustomPropertiesOfRoom(customProps, true, 0);
213         }
214         NetworkingPeer.SendMonoMessage(PhotonNetworkingMessage.OnPhotonCustomRoomPropertiesChanged, propertiesToSet);
215     }

StripKeysWithNullValues 118 lượt xem

Gõ tìm kiếm nhanh...