Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Index: Circa.Core/SettingsNode.cs
- ===================================================================
- --- Circa.Core/SettingsNode.cs (revision 107)
- +++ Circa.Core/SettingsNode.cs (working copy)
- @@ -3,8 +3,10 @@
- using System.Collections.Generic;
- using System.IO;
- using System.Linq;
- +using System.Reflection;
- using System.Text;
- using Newtonsoft.Json;
- +using System.Linq.Expressions;
- namespace Circa.Core {
- [JsonObject( MemberSerialization.OptIn )]
- @@ -38,7 +40,7 @@
- new JsonSerializerSettings {
- PreserveReferencesHandling = PreserveReferencesHandling.Objects,
- ReferenceLoopHandling = ReferenceLoopHandling.Serialize,
- - TypeNameHandling = TypeNameHandling.All
- + TypeNameHandling = TypeNameHandling.Objects
- }
- );
- using ( var writer = new StreamWriter ( confFile, false, Encoding.UTF8 ) ) {
- @@ -52,6 +54,19 @@
- return _dictionary.Keys;
- }
- }
- +
- + public void Add<T> (T obj) {
- + if (typeof (T).IsPrimitive)
- + throw new InvalidOperationException ( string.Format ("Cannot register type '{0}', it is a primitive type.") );
- + else {
- + var properties = obj.GetType ().GetProperties (BindingFlags.Public);
- + foreach (var propInfo in properties) {
- + var propKey = propInfo.Name.ToLower ()[0] + propInfo.Name.Substring (1);
- + var propValue = propInfo.GetValue (obj, null);
- + Add (propKey, () => propValue);
- + }
- + }
- + }
- public void Add<T>( string key ) {
- if ( _dictionary.ContainsKey( key ) ) {
- Index: Circa/Program.cs
- ===================================================================
- --- Circa/Program.cs (revision 107)
- +++ Circa/Program.cs (working copy)
- @@ -59,27 +59,13 @@
- SettingsNode snServers = new SettingsNode( );
- foreach ( IrcServer server in network.Servers ) {
- SettingsNode snServer = new SettingsNode( );
- -
- - snServer.Add( "name", () => server.Name );
- - snServer.Add( "hostName", () => server.HostName );
- - snServer.Add( "port", () => server.Port );
- - snServer.Add( "network", () => server.Network.Name ); // have to do this one by reference
- + snServer.Add ( server );
- snServers.Add<SettingsNode>( server.Name, () => snServer );
- }
- +
- + snNetwork.Add ( network );
- - snNetwork.Add( "name", () => network.Name );
- - snNetwork.Add( "realName", () => network.RealName );
- - snNetwork.Add( "userName", () => network.UserName );
- - snNetwork.Add( "nickNames", () => network.NickNames );
- - snNetwork.Add( "useHttpProxy", () => network.UseHttpProxy );
- - snNetwork.Add( "useHttpsProxy", () => network.UseHttpsProxy );
- - snNetwork.Add( "httpProxyHostName", () => network.HttpProxyHostName );
- - snNetwork.Add( "httpsProxyHostName", () => network.HttpsProxyHostName );
- - snNetwork.Add( "httpProxyPort", () => network.HttpProxyPort );
- - snNetwork.Add( "httpsProxyPort", () => network.HttpsProxyPort );
- - snNetwork.Add( "servers", () => snServers );
- -
- snNetworks.Add( network.Name, () => snNetwork );
- }
- #endif
- Index: Circa.Core/ChangeLog
- ===================================================================
- --- Circa.Core/ChangeLog (revision 107)
- +++ Circa.Core/ChangeLog (working copy)
- @@ -1,5 +1,9 @@
- 2010-05-11 Bojan Rajkovic <severecross@gmail.com>
- + * SettingsNode.cs:
- +
- +2010-05-11 Bojan Rajkovic <severecross@gmail.com>
- +
- * SettingsNode.cs: Re-added SettingsNode's private constructor
- and made Parent a read-only auto-property with an internal
- setter, since consumers of the API should never be
- Index: Circa/ChangeLog
- ===================================================================
- --- Circa/ChangeLog (revision 0)
- +++ Circa/ChangeLog (revision 0)
- @@ -0,0 +1,4 @@
- +2010-05-11 Bojan Rajkovic <severecross@gmail.com>
- +
- + * Program.cs:
- +
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement