public BalanceObject(Type type, IBalancable obj) { intDic = new Dictionary<string, int>(); floatDic = new Dictionary<string, float>(); stringDic = new Dictionary<string, string>(); }
/// <summary> /// Adds balancing with custom name. /// </summary> /// <param name="obj">Object to add</param> /// <param name="name">Custom Name</param> /// <returns>Success of operation</returns> public bool GetBalancing(IBalancable obj, Type objecttype) { (obj as IBalancable).Changed += UpdateData; Type type = obj.GetType(); if(!m_BalanceObjects.ContainsKey(obj)){ m_BalanceObjects.Add(obj, new BalanceObject(objecttype, obj)); } //get all public members of the object foreach (var f in type.GetProperties()) { //check whether or not the type of the object is int bool result = f.GetValue(obj, null) is int; if (result) { //add to dictionary the field name and the value of this specific object converted to int if (m_BalanceObjects[obj].intDic.ContainsKey(f.Name)) { m_BalanceObjects[obj].intDic.Add(f.Name, Convert.ToInt32(f.GetValue(obj, null))); } else { m_BalanceObjects[obj].intDic[f.Name] = Convert.ToInt32(f.GetValue(obj, null)); } } else { //check whether or not the type of the object is float result = f.GetValue(obj, null) is float; if (result) { //add to dictionary the field name and the value of this specific object converted to float if (m_BalanceObjects[obj].floatDic.ContainsKey(f.Name)) { m_BalanceObjects[obj].floatDic.Add(f.Name, Convert.ToSingle(f.GetValue(obj, null))); } else { m_BalanceObjects[obj].floatDic[f.Name] = Convert.ToSingle(f.GetValue(obj, null)); } } else { //check whether or not the type of the object is string result = f.GetValue(obj, null) is string; if (result) { //add to dictionary the field name and the value of this specific object converted to string if (m_BalanceObjects[obj].stringDic.ContainsKey(f.Name)) { m_BalanceObjects[obj].stringDic.Add(f.Name, Convert.ToString(f.GetValue(obj, null))); } else { m_BalanceObjects[obj].stringDic[f.Name] = Convert.ToString(f.GetValue(obj, null)); } } } } } return true; }
/// <summary> /// Adds balancing with custom name. /// </summary> /// <param name="obj">Object to add</param> /// <param name="name">Custom Name</param> /// <returns>Success of operation</returns> public bool GetBalancing(IBalancable obj, Type objecttype) { (obj as IBalancable).Changed += UpdateData; Type type = obj.GetType(); if (!m_BalanceObjects.ContainsKey(obj)) { m_BalanceObjects.Add(obj, new BalanceObject(objecttype, obj)); } //get all public members of the object foreach (var f in type.GetProperties()) { //check whether or not the type of the object is int bool result = f.GetValue(obj, null) is int; if (result) { //add to dictionary the field name and the value of this specific object converted to int if (m_BalanceObjects[obj].intDic.ContainsKey(f.Name)) { m_BalanceObjects[obj].intDic.Add(f.Name, Convert.ToInt32(f.GetValue(obj, null))); } else { m_BalanceObjects[obj].intDic[f.Name] = Convert.ToInt32(f.GetValue(obj, null)); } } else { //check whether or not the type of the object is float result = f.GetValue(obj, null) is float; if (result) { //add to dictionary the field name and the value of this specific object converted to float if (m_BalanceObjects[obj].floatDic.ContainsKey(f.Name)) { m_BalanceObjects[obj].floatDic.Add(f.Name, Convert.ToSingle(f.GetValue(obj, null))); } else { m_BalanceObjects[obj].floatDic[f.Name] = Convert.ToSingle(f.GetValue(obj, null)); } } else { //check whether or not the type of the object is string result = f.GetValue(obj, null) is string; if (result) { //add to dictionary the field name and the value of this specific object converted to string if (m_BalanceObjects[obj].stringDic.ContainsKey(f.Name)) { m_BalanceObjects[obj].stringDic.Add(f.Name, Convert.ToString(f.GetValue(obj, null))); } else { m_BalanceObjects[obj].stringDic[f.Name] = Convert.ToString(f.GetValue(obj, null)); } } } } } return(true); }
public BalanceObject(Type type, IBalancable obj) { intDic = new Dictionary <string, int>(); floatDic = new Dictionary <string, float>(); stringDic = new Dictionary <string, string>(); }