コード例 #1
0
        // Token: 0x0600010E RID: 270 RVA: 0x00004220 File Offset: 0x00002420
        private static TResult Extract <TResult>(ManagementBaseObject managementObject) where TResult : class, new()
        {
            TResult tresult = Activator.CreateInstance <TResult>();

            foreach (PropertyInfo propertyInfo in typeof(TResult).GetProperties())
            {
                WmiResultAttribute wmiResultAttribute = (WmiResultAttribute)Attribute.GetCustomAttribute(propertyInfo, typeof(WmiResultAttribute));
                if (wmiResultAttribute != null)
                {
                    object value = managementObject.Properties[wmiResultAttribute.PropertyName].Value;
                    Type   type  = Nullable.GetUnderlyingType(propertyInfo.PropertyType) ?? propertyInfo.PropertyType;
                    object value2;
                    if (value == null)
                    {
                        value2 = null;
                    }
                    else if (type == typeof(DateTime))
                    {
                        value2 = ManagementDateTimeConverter.ToDateTime(value.ToString()).ToUniversalTime();
                    }
                    else if (type == typeof(Guid))
                    {
                        value2 = Guid.Parse(value.ToString());
                    }
                    else
                    {
                        value2 = Convert.ChangeType(managementObject.Properties[wmiResultAttribute.PropertyName].Value, type);
                    }
                    propertyInfo.SetValue(tresult, value2, null);
                }
            }
            return(tresult);
        }
コード例 #2
0
        private static TResult Extract <TResult>(ManagementBaseObject managementObject) where TResult : class, new()
        {
            TResult val = new TResult();

            PropertyInfo[] properties = typeof(TResult).GetProperties();
            foreach (PropertyInfo propertyInfo in properties)
            {
                WmiResultAttribute wmiResultAttribute = (WmiResultAttribute)Attribute.GetCustomAttribute(propertyInfo, typeof(WmiResultAttribute));
                if (wmiResultAttribute != null)
                {
                    object value  = managementObject.Properties[wmiResultAttribute.PropertyName].Value;
                    Type   type   = Nullable.GetUnderlyingType(propertyInfo.PropertyType) ?? propertyInfo.PropertyType;
                    object value2 = (value == null) ? null : ((type == typeof(DateTime)) ? ((object)ManagementDateTimeConverter.ToDateTime(value.ToString()).ToUniversalTime()) : ((!(type == typeof(Guid))) ? Convert.ChangeType(managementObject.Properties[wmiResultAttribute.PropertyName].Value, type) : ((object)Guid.Parse(value.ToString()))));
                    propertyInfo.SetValue(val, value2, null);
                }
            }
            return(val);
        }
コード例 #3
0
        private static TResult Extract <TResult>(ManagementBaseObject managementObject) where TResult : class, new()
        {
            TResult result = new TResult();

            foreach (PropertyInfo property in typeof(TResult).GetProperties())
            {
                WmiResultAttribute customAttribute = (WmiResultAttribute)Attribute.GetCustomAttribute((MemberInfo)property, typeof(WmiResultAttribute));
                if (customAttribute != null)
                {
                    object obj1 = managementObject.Properties[customAttribute.PropertyName].Value;
                    Type   type = Nullable.GetUnderlyingType(property.PropertyType);
                    if ((object)type == null)
                    {
                        type = property.PropertyType;
                    }
                    Type   conversionType = type;
                    object obj2           = obj1 != null ? (!(conversionType == typeof(DateTime)) ? (!(conversionType == typeof(Guid)) ? Convert.ChangeType(managementObject.Properties[customAttribute.PropertyName].Value, conversionType) : (object)Guid.Parse(obj1.ToString())) : (object)ManagementDateTimeConverter.ToDateTime(obj1.ToString()).ToUniversalTime()) : (object)null;
                    property.SetValue((object)result, obj2, (object[])null);
                }
            }
            return(result);
        }