private object DataReaderToObject(SqlCeDataReader reader, EntityType entity) { object entityObject = null; switch (entity) { case EntityType.Processor: entityObject = new EntProcessor(); break; case EntityType.OS: entityObject = new EntOS(); break; case EntityType.Bios: entityObject = new EntBios(); break; case EntityType.MotherBoard: entityObject = new EntMotherBoard(); break; case EntityType.Disk: entityObject = new EntDisk(); break; case EntityType.Memory: entityObject = new EntMemory(); break; case EntityType.LogicalDrive: entityObject = new EntLogicalDrive(); break; case EntityType.CDRom: entityObject = new EntCDRom(); break; case EntityType.Video: entityObject = new EntVideo(); break; case EntityType.Multimedia: entityObject = new EntMultimedia(); break; case EntityType.Monitor: entityObject = new EntMonitor(); break; case EntityType.Share: entityObject = new EntShare(); break; case EntityType.StartUp: entityObject = new EntStartUp(); break; case EntityType.Hotfix: entityObject = new EntHotfixes(); break; case EntityType.Processes: entityObject = new EntProcesses(); break; case EntityType.Softwares: entityObject = new EntSoftwares(); break; case EntityType.Services: entityObject = new EntServices(); break; case EntityType.IPRoutes: entityObject = new EntIPRoutes(); break; case EntityType.EnvironmentVar: entityObject = new EntEnvironmentVars(); break; case EntityType.Computer: entityObject = new EntComputer(); break; case EntityType.Printer: entityObject = new EntPrinter(); break; case EntityType.UserGroup: entityObject = new EntUserGroups(); break; case EntityType.NetworkAdapter: entityObject = new EntNetworkAdapter(); break; } Type t = entityObject.GetType(); PropertyInfo[] pi = t.GetProperties(); foreach (PropertyInfo prop in pi) { if (prop.Name == "ClassName" || prop.Name == "Icon" || prop.Name == "NodeName") continue; switch (prop.PropertyType.Name) { case "String": string strValue = reader.GetString(reader.GetOrdinal(prop.Name)); prop.SetValue(entityObject, strValue, null); break; case "Int32": int intValue = reader.GetInt32(reader.GetOrdinal(prop.Name)); prop.SetValue(entityObject, intValue, null); break; case "Double": double dValue = reader.GetDouble(reader.GetOrdinal(prop.Name)); prop.SetValue(entityObject, dValue, null); break; case "DateTime": DateTime dtValue = DateTime.MinValue; if ( reader.GetValue(reader.GetOrdinal(prop.Name))== DBNull.Value) { dtValue = DateTime.MinValue; } else { dtValue = reader.GetDateTime(reader.GetOrdinal(prop.Name)); } prop.SetValue(entityObject, dtValue, null); break; case "Boolean": bool bValue = reader.GetBoolean(reader.GetOrdinal(prop.Name)); prop.SetValue(entityObject, bValue, null); break; } } return entityObject; }
private static EntIPRoutes FillDetails(ManagementBaseObject obj) { EntIPRoutes objEntIPRoutes = new EntIPRoutes(); try { objEntIPRoutes.Age = WMIUtil.ToInteger(obj["Age"]); } catch (Exception) { objEntIPRoutes.Age = 0; } try { objEntIPRoutes.Description = WMIUtil.ToString(obj["Description"]); } catch (Exception) { objEntIPRoutes.Description = ""; } try { objEntIPRoutes.Destination = WMIUtil.ToString(obj["Destination"]); } catch (Exception) { objEntIPRoutes.Destination = ""; } try { objEntIPRoutes.Mask = WMIUtil.ToString(obj["Mask"]); } catch (Exception) { objEntIPRoutes.Mask = ""; } try { objEntIPRoutes.Metric1 = WMIUtil.ToInteger(obj["Metric1"]); } catch (Exception) { objEntIPRoutes.Metric1 = -1; } try { objEntIPRoutes.Metric2 = WMIUtil.ToInteger(obj["Metric2"]); } catch (Exception) { objEntIPRoutes.Metric2 = -1; } try { objEntIPRoutes.Metric3= WMIUtil.ToInteger(obj["Metric3"]); } catch (Exception) { objEntIPRoutes.Metric3 = -1; } try { objEntIPRoutes.Metric4= WMIUtil.ToInteger(obj["Metric4"]); } catch (Exception) { objEntIPRoutes.Metric4 = -1; } try { objEntIPRoutes.Metric5 = WMIUtil.ToInteger(obj["Metric5"]); } catch (Exception) { objEntIPRoutes.Metric5 = -1; } try { objEntIPRoutes.Name = WMIUtil.ToString(obj["Name"]); } catch (Exception) { objEntIPRoutes.Name = ""; } try { objEntIPRoutes.NextHop = WMIUtil.ToString(obj["NextHop"]); } catch (Exception) { objEntIPRoutes.NextHop = ""; } try { ProtocolValues protocol = (ProtocolValues)WMIUtil.ToInteger(obj["Protocol"]); objEntIPRoutes.Protocol = protocol.ToString(); } catch (Exception) { objEntIPRoutes.Protocol= "Other"; } try { RouteTypeValues routeType = (RouteTypeValues)WMIUtil.ToInteger(obj["Type"]); objEntIPRoutes.RouteType = routeType.ToString(); } catch (Exception) { objEntIPRoutes.RouteType = "Other"; } try { objEntIPRoutes.Status = WMIUtil.ToString(obj["Status"]); } catch (Exception) { objEntIPRoutes.Status = ""; } return objEntIPRoutes; }