Exemple #1
0
        public Dictionary <string, string> GetObjectInfo(object i_Obj)
        {
            Dictionary <string, string> objInfo = new Dictionary <string, string>();

            try
            {
                PropertyInfo[] objectProperties = i_Obj.GetType().GetProperties();
                string         propertyName     = string.Empty;

                foreach (PropertyInfo vehicleProperty in objectProperties)
                {
                    if (vehicleProperty.GetValue(i_Obj).GetType().IsConstructedGenericType == true)
                    {
                        IList tmpArray = (IList)vehicleProperty.GetValue(i_Obj);

                        propertyName = StringManager.AddSpaceBetweenWordsWithCapLetters(vehicleProperty.Name);
                        objInfo.Add(propertyName, tmpArray.Count.ToString());
                        Dictionary <string, string> tmpObjInfo = GetObjectInfo(tmpArray[0]);
                        mergeDictionaries(ref objInfo, ref tmpObjInfo);
                    }
                    else if (vehicleProperty.GetValue(i_Obj).GetType().IsClass == true &&
                             vehicleProperty.GetValue(i_Obj).GetType() != typeof(string))
                    {
                        propertyName = StringManager.AddSpaceBetweenWordsWithCapLetters(vehicleProperty.Name);
                        objInfo.Add(propertyName, vehicleProperty.GetValue(i_Obj).ToString());
                        Dictionary <string, string> tmpObjInfo = GetObjectInfo(vehicleProperty.GetValue(i_Obj));
                        mergeDictionaries(ref objInfo, ref tmpObjInfo);
                    }
                    else
                    {
                        propertyName = StringManager.AddSpaceBetweenWordsWithCapLetters(vehicleProperty.Name);
                        objInfo.Add(propertyName, vehicleProperty.GetValue(i_Obj).ToString());
                    }
                }
            }
            catch (AccessViolationException i_AccessViolationException)
            {
                throw new Exception("System Error: IList is not allocated in the given index.", i_AccessViolationException);
            }

            return(objInfo);
        }