Advertisement
Guest User

Untitled

a guest
May 24th, 2017
551
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 4.39 KB | None | 0 0
  1. Index: Circa.Core/SettingsNode.cs
  2.  
  3. ===================================================================
  4.  
  5. --- Circa.Core/SettingsNode.cs  (revision 107)
  6. +++ Circa.Core/SettingsNode.cs  (working copy)
  7. @@ -3,8 +3,10 @@
  8.  using System.Collections.Generic;
  9.  using System.IO;
  10.  using System.Linq;
  11. +using System.Reflection;
  12.  using System.Text;
  13.  using Newtonsoft.Json;
  14. +using System.Linq.Expressions;
  15.  
  16.  namespace Circa.Core {
  17.      [JsonObject( MemberSerialization.OptIn )]
  18. @@ -38,7 +40,7 @@
  19.                  new JsonSerializerSettings {
  20.                      PreserveReferencesHandling = PreserveReferencesHandling.Objects,
  21.                      ReferenceLoopHandling = ReferenceLoopHandling.Serialize,
  22. -                    TypeNameHandling = TypeNameHandling.All
  23. +                    TypeNameHandling = TypeNameHandling.Objects
  24.                  }
  25.              );
  26.              using ( var writer = new StreamWriter ( confFile, false, Encoding.UTF8 ) ) {
  27. @@ -52,6 +54,19 @@
  28.                  return _dictionary.Keys;
  29.              }
  30.          }
  31. +        
  32. +        public void Add<T> (T obj) {
  33. +            if (typeof (T).IsPrimitive)
  34. +                throw new InvalidOperationException ( string.Format ("Cannot register type '{0}', it is a primitive type.") );
  35. +            else {
  36. +                var properties = obj.GetType ().GetProperties (BindingFlags.Public);
  37. +                foreach (var propInfo in properties) {
  38. +                    var propKey = propInfo.Name.ToLower ()[0] + propInfo.Name.Substring (1);
  39. +                    var propValue = propInfo.GetValue (obj, null);
  40. +                    Add (propKey, () => propValue);
  41. +                }
  42. +            }
  43. +        }
  44.  
  45.          public void Add<T>( string key ) {
  46.              if ( _dictionary.ContainsKey( key ) ) {
  47.  
  48.  
  49. Index: Circa/Program.cs
  50.  
  51. ===================================================================
  52.  
  53. --- Circa/Program.cs    (revision 107)
  54. +++ Circa/Program.cs    (working copy)
  55. @@ -59,27 +59,13 @@
  56.                  SettingsNode snServers = new SettingsNode( );
  57.                  foreach ( IrcServer server in network.Servers ) {
  58.                      SettingsNode snServer = new SettingsNode( );
  59. -                    
  60. -                    snServer.Add( "name", () => server.Name );
  61. -                    snServer.Add( "hostName", () => server.HostName );
  62. -                    snServer.Add( "port", () => server.Port );
  63. -                    snServer.Add( "network", () => server.Network.Name ); // have to do this one by reference
  64. +                    snServer.Add ( server );
  65.  
  66.                      snServers.Add<SettingsNode>( server.Name, () => snServer );
  67.                  }
  68. +                
  69. +                snNetwork.Add ( network );
  70.  
  71. -                snNetwork.Add( "name", () => network.Name );
  72. -                snNetwork.Add( "realName", () => network.RealName );
  73. -                snNetwork.Add( "userName", () => network.UserName );
  74. -                snNetwork.Add( "nickNames", () => network.NickNames );
  75. -                snNetwork.Add( "useHttpProxy", () => network.UseHttpProxy );
  76. -                snNetwork.Add( "useHttpsProxy", () => network.UseHttpsProxy );
  77. -                snNetwork.Add( "httpProxyHostName", () => network.HttpProxyHostName );
  78. -                snNetwork.Add( "httpsProxyHostName", () => network.HttpsProxyHostName );
  79. -                snNetwork.Add( "httpProxyPort", () => network.HttpProxyPort );
  80. -                snNetwork.Add( "httpsProxyPort", () => network.HttpsProxyPort );
  81. -                snNetwork.Add( "servers", () => snServers );
  82. -
  83.                  snNetworks.Add( network.Name, () => snNetwork );
  84.              }
  85.  #endif
  86.  
  87.  
  88. Index: Circa.Core/ChangeLog
  89.  
  90. ===================================================================
  91.  
  92. --- Circa.Core/ChangeLog    (revision 107)
  93. +++ Circa.Core/ChangeLog    (working copy)
  94. @@ -1,5 +1,9 @@
  95.  2010-05-11  Bojan Rajkovic  <severecross@gmail.com>
  96.  
  97. +   * SettingsNode.cs:
  98. +
  99. +2010-05-11  Bojan Rajkovic  <severecross@gmail.com>
  100. +
  101.     * SettingsNode.cs: Re-added SettingsNode's private constructor
  102.     and made Parent a read-only auto-property with an internal
  103.     setter, since consumers of the API should never be
  104.  
  105.  
  106. Index: Circa/ChangeLog
  107.  
  108. ===================================================================
  109.  
  110. --- Circa/ChangeLog (revision 0)
  111. +++ Circa/ChangeLog (revision 0)
  112. @@ -0,0 +1,4 @@
  113. +2010-05-11  Bojan Rajkovic  <severecross@gmail.com>
  114. +
  115. +   * Program.cs:
  116. +
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement