Copying and Pasting cs Code

In cs, like in almost any computer programming language, reading data from a file can be tricky. You add extra lines of code to tell the computer what to do. Sometimes you can copy and paste these lines from other peoples’ code.

For example, you can follow the pattern in this listing:

     protected internal void CacheProperties(Hashtable propertiesToCache)
     {
         if (propertiesToCache == null || propertiesToCache.Count == 0 || this.customPropertiesField.Equals(propertiesToCache))
         {
             return;
         }

         // check of this game was removed from the list. in that case, we don't
         // need to read any further properties
         // list updates will remove this game from the game listing
         if (propertiesToCache.ContainsKey(GameProperties.Removed))
         {
             this.removedFromList = (Boolean)propertiesToCache[GameProperties.Removed];
             if (this.removedFromList)
             {
                 return;
             }
         }

         // fetch the "well known" properties of the room, if available
         if (propertiesToCache.ContainsKey(GameProperties.MaxPlayers))
         {
             this.maxPlayersField = (byte)propertiesToCache[GameProperties.MaxPlayers];
         }

         if (propertiesToCache.ContainsKey(GameProperties.IsOpen))
         {
             this.openField = (bool)propertiesToCache[GameProperties.IsOpen];
         }

         if (propertiesToCache.ContainsKey(GameProperties.IsVisible))
         {
             this.visibleField = (bool)propertiesToCache[GameProperties.IsVisible];
         }

         if (propertiesToCache.ContainsKey(GameProperties.PlayerCount))
         {
             this.playerCount = (int)((byte)propertiesToCache[GameProperties.PlayerCount]);
         }

         if (propertiesToCache.ContainsKey(GameProperties.CleanupCacheOnLeave))
         {
             this.autoCleanUpField = (bool)propertiesToCache[GameProperties.CleanupCacheOnLeave];
         }

         //if (propertiesToCache.ContainsKey(GameProperties.PropsListedInLobby))
         //{
         // // could be cached but isn't useful
         //}

         // merge the custom properties (from your application) to the cache (only string-typed keys will be kept)
         this.customPropertiesField.MergeStringKeys(propertiesToCache);
     }