private static bool IsDisplay(PropertyData property) { switch (property.Name) { case "AcceptPause": case "AcceptStop": case "CheckPoint": return false; } return true; }
/// <summary> /// Gets the .Net type equivalent for the WMI (CIM) type. /// </summary> public static Type Convert(PropertyData property) { //Added: Support for arrays if (!property.IsArray) { return typemap[property.Type]; } else { return Type.GetType(String.Format("{0}[]", typemap[property.Type])); } }
/// <summary> /// This function will generate enums corresponding to the Values/Valuemap pair /// and for the BitValues/Bitmap pair. /// </summary> /// <returns> /// returns if the property is an enum. This is checked by if enum is added or not /// </returns> bool GeneratePropertyHelperEnums(PropertyData prop, string strPropertyName, bool bNullable) { bool isEnumAdded = false; bool bZeroFieldInEnum = false; //Only if the property is of type int and there is atleast values qualifier on it //then we will generate an enum for the values/valuemap(if available) //Here we don't have to check explicitly for type of the property as the size of //values array will be zero if the type is not int. string strEnum = ResolveCollision(strPropertyName + "Values", true); // if there is a mismatch in the number of values and ValueMaps then // there is an error in the value maps and so don't add enum if (Values.Count > 0 && (ValueMap.Count == 0 || ValueMap.Count == Values.Count)) { if (ValueMap.Count == 0) { bZeroFieldInEnum = true; } //Now we will have to create an enum. EnumObj = new CodeTypeDeclaration(strEnum); //Now convert the type to the generated enum type if (prop.IsArray) { cmp.Type = new CodeTypeReference(strEnum, 1); } else { cmp.Type = new CodeTypeReference(strEnum); } EnumObj.IsEnum = true; EnumObj.TypeAttributes = TypeAttributes.Public; Int64 maxValue = 0; for (int i = 0; i < Values.Count; i++) { cmf = new CodeMemberField(); cmf.Name = Values[i].ToString(); if (ValueMap.Count > 0) { cmf.InitExpression = new CodePrimitiveExpression(ValueMap[i]); Int64 test = System.Convert.ToInt64(ValueMap[i],(IFormatProvider)CultureInfo.InvariantCulture.GetFormat(typeof(System.UInt64))); if (test > maxValue) maxValue=test; if (bZeroFieldInEnum == false) { if (System.Convert.ToInt64( ValueMap[i], (IFormatProvider)CultureInfo.InvariantCulture.GetFormat( typeof(System.UInt64))) == 0) { bZeroFieldInEnum = true; } } } else { cmf.InitExpression = new CodePrimitiveExpression(i); if (i > maxValue) maxValue=i; } EnumObj.Members.Add(cmf); } // If there is no 0 valued field in enum, just add a invalid for enum // This is just to show in property browser if ((bNullable == true) && (bZeroFieldInEnum == false)) { // use the 0 enum position for NULL cmf = new CodeMemberField(); cmf.Name = "NULL_ENUM_VALUE"; cmf.InitExpression = new CodePrimitiveExpression(0); EnumObj.Members.Add(cmf); prop.NullEnumValue = 0; } else if ((bNullable == true) && (bZeroFieldInEnum == true)) { // must create an entry for NULL that is not zero and is not used // use the another unused enum position for NULL cmf = new CodeMemberField (); cmf.Name = "NULL_ENUM_VALUE"; cmf.InitExpression = new CodePrimitiveExpression((int)(maxValue+1)); EnumObj.Members.Add(cmf); prop.NullEnumValue = (int)(maxValue+1); } else if ((bNullable == false) && (bZeroFieldInEnum == false)) { // add an entry for 0 valued enum cmf = new CodeMemberField (); cmf.Name = "INVALID_ENUM_VALUE"; cmf.InitExpression = new CodePrimitiveExpression(0); EnumObj.Members.Add(cmf); prop.NullEnumValue = 0; } cc.Members.Add(EnumObj); isEnumAdded = true; } //Now clear the Values & ValueMap Array Values.Clear(); ValueMap.Clear(); bZeroFieldInEnum = false; //Only if the property is of type int and there is atleast values qualifier on it //then we will generate an enum for the values/valuemap(if available) //Here we don't have to check explicitly for type of the property as the size of //values array will be zero if the type is not int. if (BitValues.Count > 0 && (BitMap.Count == 0 || BitMap.Count == BitValues.Count)) { if(BitMap.Count == 0) { bZeroFieldInEnum = true; } //Now we will create the enum EnumObj = new CodeTypeDeclaration(strEnum); //Now convert the type to the generated enum type if (prop.IsArray) { cmp.Type = new CodeTypeReference(strEnum, 1); } else { cmp.Type = new CodeTypeReference(strEnum); } EnumObj.IsEnum = true; EnumObj.TypeAttributes = TypeAttributes.Public; Int32 bitValue = 1; Int64 maxBitValue = 0; for (int i = 0; i < BitValues.Count; i++) { cmf = new CodeMemberField(); cmf.Name = BitValues[i].ToString(); if (BitMap.Count > 0) { cmf.InitExpression = new CodePrimitiveExpression(BitMap[i]); Int64 test = System.Convert.ToInt64(BitMap[i],(IFormatProvider)CultureInfo.InvariantCulture.GetFormat(typeof(System.UInt64))); if (test > maxBitValue) maxBitValue=test; } else { cmf.InitExpression = new CodePrimitiveExpression(bitValue); if (bitValue > maxBitValue) maxBitValue=bitValue; // Now shift 1 more bit so that we can put it for the // next element in the enum bitValue = bitValue << 1; } if(bZeroFieldInEnum == false) { if( (System.Convert.ToInt64(BitMap[i],(IFormatProvider)CultureInfo.InvariantCulture.GetFormat(typeof(System.UInt64))) == 0) ) // Bug No: 121987 { bZeroFieldInEnum = true; } } EnumObj.Members.Add(cmf); } // If there is no 0 valued field in enum, just add a invalid for enum // This is just to show in property browser if ((bNullable == true) && (bZeroFieldInEnum == false)) { // use the 0 enum position for NULL cmf = new CodeMemberField (); cmf.Name = "NULL_ENUM_VALUE"; cmf.InitExpression = new CodePrimitiveExpression(0); EnumObj.Members.Add(cmf); prop.NullEnumValue = 0; } else if ((bNullable == true) && (bZeroFieldInEnum == true)) { // must create an entry for NULL that is not zero and is not used // use the another unused enum position for NULL cmf = new CodeMemberField (); cmf.Name = "NULL_ENUM_VALUE"; if (BitValues.Count > 30) { maxBitValue = maxBitValue + 1; } else { maxBitValue = maxBitValue << 1; } cmf.InitExpression = new CodePrimitiveExpression((int)(maxBitValue)); EnumObj.Members.Add(cmf); // just add one - we won't preserve the bit shifting but this won't be used in CIM anyway. prop.NullEnumValue = (int)(maxBitValue); } else if ((bNullable == false) && (bZeroFieldInEnum == false)) { // add an entry for 0 valued enum cmf = new CodeMemberField (); cmf.Name = "INVALID_ENUM_VALUE"; cmf.InitExpression = new CodePrimitiveExpression(0); EnumObj.Members.Add(cmf); prop.NullEnumValue = 0; } cc.Members.Add(EnumObj); isEnumAdded = true; } //Now clear the Bitmap and BitValues Array BitValues.Clear(); BitMap.Clear(); return isEnumAdded; }
private string ProcessPropertyQualifiers(PropertyData prop, ref bool bRead, ref bool bWrite, ref bool bStatic, bool bDynamicClass, out bool nullable) { bool flag = false; bool flag2 = false; bool flag3 = false; nullable = true; bRead = true; bWrite = false; this.arrConvFuncName = "ToInt32"; this.enumType = "System.Int32"; string str = string.Empty; foreach (QualifierData data in prop.Qualifiers) { if (string.Compare(data.Name, "description", StringComparison.OrdinalIgnoreCase) == 0) { str = data.Value.ToString(); } else if (string.Compare(data.Name, "Not_Null", StringComparison.OrdinalIgnoreCase) == 0) { nullable = false; } else { if (string.Compare(data.Name, "key", StringComparison.OrdinalIgnoreCase) == 0) { this.arrKeyType.Add(this.cmp.Type); this.arrKeys.Add(prop.Name); nullable = false; break; } if (string.Compare(data.Name, "static", StringComparison.OrdinalIgnoreCase) == 0) { bStatic = true; this.cmp.Attributes |= MemberAttributes.Static; } else if (string.Compare(data.Name, "read", StringComparison.OrdinalIgnoreCase) == 0) { if (!((bool) data.Value)) { bRead = false; } else { bRead = true; } } else if (string.Compare(data.Name, "write", StringComparison.OrdinalIgnoreCase) == 0) { flag = true; if ((bool) data.Value) { flag2 = true; } else { flag2 = false; } } else if ((string.Compare(data.Name, "ValueMap", StringComparison.OrdinalIgnoreCase) == 0) && !flag3) { try { this.ValueMap.Clear(); if (isTypeInt(prop.Type) && (data.Value != null)) { string[] strArray = (string[]) data.Value; for (int i = 0; i < strArray.Length; i++) { try { this.arrConvFuncName = ConvertToNumericValueAndAddToArray(prop.Type, strArray[i], this.ValueMap, out this.enumType); } catch (OverflowException) { } } } } catch (FormatException) { flag3 = true; this.ValueMap.Clear(); } catch (InvalidCastException) { this.ValueMap.Clear(); } } else if ((string.Compare(data.Name, "Values", StringComparison.OrdinalIgnoreCase) == 0) && !flag3) { try { this.Values.Clear(); if (isTypeInt(prop.Type) && (data.Value != null)) { ArrayList arrIn = new ArrayList(5); string[] strArray2 = (string[]) data.Value; for (int j = 0; j < strArray2.Length; j++) { if (strArray2[j].Length == 0) { this.Values.Clear(); flag3 = true; break; } string str2 = ConvertValuesToName(strArray2[j]); arrIn.Add(str2); } this.ResolveEnumNameValues(arrIn, ref this.Values); } } catch (InvalidCastException) { this.Values.Clear(); } } else if ((string.Compare(data.Name, "BitMap", StringComparison.OrdinalIgnoreCase) == 0) && !flag3) { try { this.BitMap.Clear(); if (isTypeInt(prop.Type) && (data.Value != null)) { string[] strArray3 = (string[]) data.Value; for (int k = 0; k < strArray3.Length; k++) { this.BitMap.Add(ConvertBitMapValueToInt32(strArray3[k])); } } } catch (FormatException) { this.BitMap.Clear(); flag3 = true; } catch (InvalidCastException) { this.BitMap.Clear(); } } else if ((string.Compare(data.Name, "BitValues", StringComparison.OrdinalIgnoreCase) == 0) && !flag3) { try { this.BitValues.Clear(); if (isTypeInt(prop.Type) && (data.Value != null)) { ArrayList list2 = new ArrayList(5); string[] strArray4 = (string[]) data.Value; for (int m = 0; m < strArray4.Length; m++) { if (strArray4[m].Length == 0) { this.BitValues.Clear(); flag3 = true; break; } string str3 = ConvertValuesToName(strArray4[m]); list2.Add(str3); } this.ResolveEnumNameValues(list2, ref this.BitValues); } } catch (InvalidCastException) { this.BitValues.Clear(); } } } } if (((!bDynamicClass && !flag) || ((!bDynamicClass && flag) && flag2)) || ((bDynamicClass && flag) && flag2)) { bWrite = true; } return str; }
private bool GeneratePropertyHelperEnums(PropertyData prop, string strPropertyName, bool bNullable) { bool flag = false; bool flag2 = false; string name = this.ResolveCollision(strPropertyName + "Values", true); if ((this.Values.Count > 0) && ((this.ValueMap.Count == 0) || (this.ValueMap.Count == this.Values.Count))) { if (this.ValueMap.Count == 0) { flag2 = true; } this.EnumObj = new CodeTypeDeclaration(name); if (prop.IsArray) { this.cmp.Type = new CodeTypeReference(name, 1); } else { this.cmp.Type = new CodeTypeReference(name); } this.EnumObj.IsEnum = true; this.EnumObj.TypeAttributes = TypeAttributes.Public; long num = 0L; for (int i = 0; i < this.Values.Count; i++) { this.cmf = new CodeMemberField(); this.cmf.Name = this.Values[i].ToString(); if (this.ValueMap.Count > 0) { this.cmf.InitExpression = new CodePrimitiveExpression(this.ValueMap[i]); long num3 = System.Convert.ToInt64(this.ValueMap[i], (IFormatProvider) CultureInfo.InvariantCulture.GetFormat(typeof(ulong))); if (num3 > num) { num = num3; } if (!flag2 && (System.Convert.ToInt64(this.ValueMap[i], (IFormatProvider) CultureInfo.InvariantCulture.GetFormat(typeof(ulong))) == 0L)) { flag2 = true; } } else { this.cmf.InitExpression = new CodePrimitiveExpression(i); if (i > num) { num = i; } } this.EnumObj.Members.Add(this.cmf); } if (bNullable && !flag2) { this.cmf = new CodeMemberField(); this.cmf.Name = "NULL_ENUM_VALUE"; this.cmf.InitExpression = new CodePrimitiveExpression(0); this.EnumObj.Members.Add(this.cmf); prop.NullEnumValue = 0L; } else if (bNullable && flag2) { this.cmf = new CodeMemberField(); this.cmf.Name = "NULL_ENUM_VALUE"; this.cmf.InitExpression = new CodePrimitiveExpression((int) (num + 1L)); this.EnumObj.Members.Add(this.cmf); prop.NullEnumValue = (int) (num + 1L); } else if (!bNullable && !flag2) { this.cmf = new CodeMemberField(); this.cmf.Name = "INVALID_ENUM_VALUE"; this.cmf.InitExpression = new CodePrimitiveExpression(0); this.EnumObj.Members.Add(this.cmf); prop.NullEnumValue = 0L; } this.cc.Members.Add(this.EnumObj); flag = true; } this.Values.Clear(); this.ValueMap.Clear(); flag2 = false; if ((this.BitValues.Count > 0) && ((this.BitMap.Count == 0) || (this.BitMap.Count == this.BitValues.Count))) { if (this.BitMap.Count == 0) { flag2 = true; } this.EnumObj = new CodeTypeDeclaration(name); if (prop.IsArray) { this.cmp.Type = new CodeTypeReference(name, 1); } else { this.cmp.Type = new CodeTypeReference(name); } this.EnumObj.IsEnum = true; this.EnumObj.TypeAttributes = TypeAttributes.Public; int num4 = 1; long num5 = 0L; for (int j = 0; j < this.BitValues.Count; j++) { this.cmf = new CodeMemberField(); this.cmf.Name = this.BitValues[j].ToString(); if (this.BitMap.Count > 0) { this.cmf.InitExpression = new CodePrimitiveExpression(this.BitMap[j]); long num7 = System.Convert.ToInt64(this.BitMap[j], (IFormatProvider) CultureInfo.InvariantCulture.GetFormat(typeof(ulong))); if (num7 > num5) { num5 = num7; } } else { this.cmf.InitExpression = new CodePrimitiveExpression(num4); if (num4 > num5) { num5 = num4; } num4 = num4 << 1; } if (!flag2 && (System.Convert.ToInt64(this.BitMap[j], (IFormatProvider) CultureInfo.InvariantCulture.GetFormat(typeof(ulong))) == 0L)) { flag2 = true; } this.EnumObj.Members.Add(this.cmf); } if (bNullable && !flag2) { this.cmf = new CodeMemberField(); this.cmf.Name = "NULL_ENUM_VALUE"; this.cmf.InitExpression = new CodePrimitiveExpression(0); this.EnumObj.Members.Add(this.cmf); prop.NullEnumValue = 0L; } else if (bNullable && flag2) { this.cmf = new CodeMemberField(); this.cmf.Name = "NULL_ENUM_VALUE"; if (this.BitValues.Count > 30) { num5 += 1L; } else { num5 = num5 << 1; } this.cmf.InitExpression = new CodePrimitiveExpression((int) num5); this.EnumObj.Members.Add(this.cmf); prop.NullEnumValue = (int) num5; } else if (!bNullable && !flag2) { this.cmf = new CodeMemberField(); this.cmf.Name = "INVALID_ENUM_VALUE"; this.cmf.InitExpression = new CodePrimitiveExpression(0); this.EnumObj.Members.Add(this.cmf); prop.NullEnumValue = 0L; } this.cc.Members.Add(this.EnumObj); flag = true; } this.BitValues.Clear(); this.BitMap.Clear(); return flag; }
public static String GetDescription(this PropertyData property) { return(property.HasQualifier("Description") ? property.Qualifiers["Description"].Value.ToString() : String.Empty); }
public static Boolean IsRealNumeric(this PropertyData property) { return(IsRealNumeric(property.Type)); }
public static Boolean IsReadable(this PropertyData property) { return(property.HasQualifier("read")); }
private static Boolean HasQualifier(this PropertyData property, String qualifier) { return(Exists(property.Qualifiers, qualifier)); }
private String GetPropertyDeclaration(PropertyData property) { var sb = new StringBuilder(); if(this.ShowQualifiers && property.Qualifiers.Count > 0) sb.AppendFormat("{0}\r\n", GetQualiferDeclaration(property.Qualifiers)); sb.AppendFormat("{0} {1};", property.Type.ToString().ToLowerInvariant(), property.Name); return sb.ToString(); }
//================================================================================================= private bool WmiColumnMatchesOutputColumn( PropertyData wmiCol, IDTSOutputColumn100 column ) { DataType dt; int length; int scale; int precision; int codePage; GetWmiColumnProperties( wmiCol, out dt, out length, out scale, out precision, out codePage); if (dt == column.DataType && length == column.Length && scale == column.Scale && codePage == column.CodePage) { return true; } return false; }
//================================================================================================= private void GetWmiColumnProperties(PropertyData column, out DataType dtstype, out int length, out int scale, out int precision, out int codePage) { dtstype = CimToDts(column.Type); length = (int)GetQualifiers(column, "MaxLen", 0); precision = 0; scale = 0; codePage = 0; // if WMI does not provide column length then set it to 256 if (dtstype == DataType.DT_WSTR && length == 0) length = 256; }
//================================================================================================= private object GetQualifiers(PropertyData prop, string qualifierName, object defaultValue) { try { QualifierData qualifier = prop.Qualifiers[qualifierName]; return (qualifier != null ? qualifier.Value : defaultValue); } catch { return defaultValue; } }
private void SetBufferColumn( PipelineBuffer buffer, ManagementObject row, PropertyData wmiColumn, int col_index, object col_value ) { if (col_value == null) { buffer.SetNull(col_index); return; } // col_value should not be an array type // since all arrays must be unwinded at this point System.Diagnostics.Trace.Assert( !col_value.GetType().IsArray, "WMI array type was not unwinded for some reason"); switch (CimToDts(wmiColumn.Type)) { case DataType.DT_WSTR: case DataType.DT_NTEXT: buffer.SetString( col_index, ObjToString(col_value, buffer.GetColumnInfo(col_index).MaxLength) ); break; case DataType.DT_DBDATE: case DataType.DT_DBTIMESTAMP: case DataType.DT_DBTIMESTAMP2: // CIM DateTime is represented as a wierd string in DMTF date/time format buffer.SetDateTime( col_index, ManagementDateTimeConverter.ToDateTime((string)col_value) ); break; case DataType.DT_NUMERIC: buffer.SetDecimal(col_index, (decimal)col_value); break; case DataType.DT_GUID: buffer.SetGuid(col_index, (Guid)col_value); break; case DataType.DT_I1: buffer.SetSByte(col_index, (SByte)col_value); break; case DataType.DT_I2: buffer.SetInt16(col_index, (short)col_value); break; case DataType.DT_I4: buffer.SetInt32(col_index, (int)col_value); break; case DataType.DT_I8: { long longValue; object value = col_value; if (value is TimeSpan) { TimeSpan ts = (TimeSpan)value; longValue = ts.Ticks; } else { longValue = (long)value; } buffer.SetInt64(col_index, longValue); break; } case DataType.DT_BOOL: buffer.SetBoolean(col_index, (bool)col_value); break; case DataType.DT_R4: buffer.SetSingle(col_index, (float)col_value); break; case DataType.DT_R8: buffer.SetDouble(col_index, (double)col_value); break; case DataType.DT_UI1: buffer.SetByte(col_index, (byte)col_value); break; //case DataType.DT_BYTES: // DataType.DT_UI1: // buffer.SetBytes(col_index, (byte[])col_value); // break; case DataType.DT_UI2: buffer.SetUInt16(col_index, (ushort)col_value); break; case DataType.DT_UI4: buffer.SetUInt32(col_index, (uint)col_value); break; case DataType.DT_UI8: buffer.SetUInt64(col_index, (ulong)col_value); break; default: // We shouldn't be here if we have all our supported data types covered in the switch. System.Diagnostics.Trace.Assert(false, "Unsupported data type : " + wmiColumn.Type.ToString()); break; } }
public void CopyTo (PropertyData [] propertyArray, int index) { throw new NotImplementedException (); }
public void CopyTo(PropertyData[] propertyArray, int index) { this.CopyTo((Array) propertyArray, index); }
private string ProcessPropertyQualifiers(PropertyData prop, ref bool bRead, ref bool bWrite, ref bool bStatic, bool bDynamicClass, out bool nullable) { bool flag = false; bool flag1 = false; bool flag2 = false; nullable = true; bRead = true; bWrite = false; this.arrConvFuncName = "ToInt32"; this.enumType = "System.Int32"; string empty = string.Empty; foreach (QualifierData qualifier in prop.Qualifiers) { if (string.Compare(qualifier.Name, "description", StringComparison.OrdinalIgnoreCase) != 0) { if (string.Compare(qualifier.Name, "Not_Null", StringComparison.OrdinalIgnoreCase) != 0) { if (string.Compare(qualifier.Name, "key", StringComparison.OrdinalIgnoreCase) != 0) { if (string.Compare(qualifier.Name, "static", StringComparison.OrdinalIgnoreCase) != 0) { if (string.Compare(qualifier.Name, "read", StringComparison.OrdinalIgnoreCase) != 0) { if (string.Compare(qualifier.Name, "write", StringComparison.OrdinalIgnoreCase) != 0) { if (string.Compare(qualifier.Name, "ValueMap", StringComparison.OrdinalIgnoreCase) != 0 || flag2) { if (string.Compare(qualifier.Name, "Values", StringComparison.OrdinalIgnoreCase) != 0 || flag2) { if (string.Compare(qualifier.Name, "BitMap", StringComparison.OrdinalIgnoreCase) != 0 || flag2) { if (string.Compare(qualifier.Name, "BitValues", StringComparison.OrdinalIgnoreCase) != 0 || flag2) { continue; } try { this.BitValues.Clear(); if (ManagementClassGenerator.isTypeInt(prop.Type) && qualifier.Value != null) { ArrayList arrayLists = new ArrayList(5); string[] value = (string[])qualifier.Value; int num = 0; while (num < (int)value.Length) { if (value[num].Length != 0) { string name = ManagementClassGenerator.ConvertValuesToName(value[num]); arrayLists.Add(name); num++; } else { this.BitValues.Clear(); flag2 = true; break; } } this.ResolveEnumNameValues(arrayLists, ref this.BitValues); } } catch (InvalidCastException invalidCastException) { this.BitValues.Clear(); } } else { try { this.BitMap.Clear(); if (ManagementClassGenerator.isTypeInt(prop.Type) && qualifier.Value != null) { string[] strArrays = (string[])qualifier.Value; for (int i = 0; i < (int)strArrays.Length; i++) { this.BitMap.Add(ManagementClassGenerator.ConvertBitMapValueToInt32(strArrays[i])); } } } catch (FormatException formatException) { this.BitMap.Clear(); flag2 = true; } catch (InvalidCastException invalidCastException1) { this.BitMap.Clear(); } } } else { try { this.Values.Clear(); if (ManagementClassGenerator.isTypeInt(prop.Type) && qualifier.Value != null) { ArrayList arrayLists1 = new ArrayList(5); string[] value1 = (string[])qualifier.Value; int num1 = 0; while (num1 < (int)value1.Length) { if (value1[num1].Length != 0) { string str = ManagementClassGenerator.ConvertValuesToName(value1[num1]); arrayLists1.Add(str); num1++; } else { this.Values.Clear(); flag2 = true; break; } } this.ResolveEnumNameValues(arrayLists1, ref this.Values); } } catch (InvalidCastException invalidCastException2) { this.Values.Clear(); } } } else { try { this.ValueMap.Clear(); if (ManagementClassGenerator.isTypeInt(prop.Type) && qualifier.Value != null) { string[] strArrays1 = (string[])qualifier.Value; for (int j = 0; j < (int)strArrays1.Length; j++) { try { this.arrConvFuncName = ManagementClassGenerator.ConvertToNumericValueAndAddToArray(prop.Type, strArrays1[j], this.ValueMap, out this.enumType); } catch (OverflowException overflowException) { } } } } catch (FormatException formatException1) { flag2 = true; this.ValueMap.Clear(); } catch (InvalidCastException invalidCastException3) { this.ValueMap.Clear(); } } } else { flag = true; if (!(bool)qualifier.Value) { flag1 = false; } else { flag1 = true; } } } else { if ((bool)qualifier.Value) { bRead = true; } else { bRead = false; } } } else { bStatic = true; CodeMemberProperty attributes = this.cmp; attributes.Attributes = attributes.Attributes | MemberAttributes.Static; } } else { this.arrKeyType.Add(this.cmp.Type); this.arrKeys.Add(prop.Name); nullable = false; break; } } else { nullable = false; } } else { empty = qualifier.Value.ToString(); } } if (!bDynamicClass && !flag || !bDynamicClass && flag && flag1 || bDynamicClass && flag && flag1) { bWrite = true; } return empty; }
public static String GetValueAsString(this PropertyData p, PropertyDataValueMap valueMap) { return(String.Join(", ", GetValueAsStringArray(p, valueMap))); }
public static Boolean IsKey(this PropertyData property) { return(property.HasQualifier("key")); }
public static String GetValueAsString(this PropertyData p) { return(GetValueAsString(p, PropertyDataValueMap.Empty)); }
public static Boolean IsWritable(this PropertyData property) { return(property.HasQualifier("write")); }
private static string ResolvePropertyValue(PropertyData property) { if (property.Value != null) return property.Value.ToString(); return string.Empty; }
public static Boolean IsInteger(this PropertyData property) { return(IsInteger(property.Type)); }
private TreeGridNode AddNode(ManagementBaseObject o, PropertyData p, TreeGridNodeCollection nodes) { TreeGridNode node = nodes.Add(p.Name, p.GetValueAsString(this.valueMaps)); string guid = GetGUID(); node.Tag = guid; this.objectMap.Add(guid, o); this.propertyMap.Add(guid, p); // Get property description var description = String.Empty; if (this.ManagementClass != null && this.managementClass.HasProperty(p.Name)) { description = this.ManagementClass.Properties[p.Name].GetDescription(); if (!String.IsNullOrEmpty(description)) description = "\r\n" + description; } // Set tooltip node.Cells[0].ToolTipText = String.Format( "{0} {1}.{2}{3}", p.Type.ToString() + (p.IsArray ? "[]" : String.Empty), this.ManagementObject.ClassPath.ClassName, p.Name, description ); // Highlight key columns if (p.IsKey()) { // Apply styles Font f = node._grid.DefaultCellStyle.Font; node.Cells[0].Style.Font = new Font(f.FontFamily, f.Size, FontStyle.Bold); } // Expand arrays if (p.Value != null && p.IsArray) { var values = p.GetValueAsStringArray(this.ShowMappedValues ? this.valueMaps : null); int i = 0; bool addValues = true; foreach (object value in values) { if (i >= MAX_ARRAY_MEMBERS) { addValues = false; } else { // Keep add values or just count them? if (addValues) { TreeGridNode child = node.Nodes.Add(String.Format("[{0}]", i), value.ToString()); child.Cells[0].Style.Alignment = DataGridViewContentAlignment.MiddleRight; child.Cells[0].Style.ForeColor = SystemColors.GrayText; } i++; } } // Add note if results were truncated if (!addValues) { TreeGridNode truncNode = node.Nodes.Add(String.Format("[...{0}]", i), "Results were truncated."); truncNode.Cells[0].Style.Alignment = DataGridViewContentAlignment.MiddleRight; truncNode.Cells[0].Style.ForeColor = SystemColors.GrayText; } node.Cells[1].Value = String.Format("{0} [{1}]", p.Type, i); } // Expand Objects if (p.Type == CimType.Reference || p.Type == CimType.Object) { if (p.Value != null) { // TODO: What about object arrays? ManagementBaseObject refObject; if (p.Type == CimType.Reference && null != this.Scope) { refObject = new ManagementObject(this.Scope, new ManagementPath((String)p.Value), new ObjectGetOptions()); } else { refObject = (ManagementBaseObject) p.Value; } node.Cells[1].Value = refObject.GetRelativePath(); foreach (PropertyData subProperty in refObject.Properties) { TreeGridNode subNode = this.AddNode(refObject, subProperty, node.Nodes); string subGuid = GetGUID(); subNode.Tag = subGuid; this.objectMap.Add(subGuid, refObject); this.propertyMap.Add(subGuid, subProperty); } } else { node.Cells[1].Value = "NULL"; } } return node; }
/// <summary> /// <para>Copies the <see cref='System.Management.PropertyDataCollection'/> to a specialized <see cref='System.Management.PropertyData'/> object /// array.</para> /// </summary> /// <param name='propertyArray'>The destination array to contain the copied <see cref='System.Management.PropertyDataCollection'/>.</param> /// <param name=' index'>The index in the destination array from which to start copying.</param> public void CopyTo(PropertyData[] propertyArray, Int32 index) { CopyTo((Array)propertyArray, index); }
/// <summary> /// Updates the current object pointers based on the selected cells. /// </summary> private void dataGridView1_SelectionChanged(object sender, EventArgs e) { if (this.dataGridView1.CurrentNode == null || this.dataGridView1.CurrentNode.Tag == null) { this.selectedObject = null; this.selectedProperty = null; return; } else { // Update selected property and object string guid = this.dataGridView1.CurrentNode.Tag.ToString(); this.selectedObject = this.objectMap.ContainsKey(guid) ? this.objectMap[guid] : null; this.selectedProperty = this.propertyMap.ContainsKey(guid) ? this.propertyMap[guid] : null; // Move to column index 1 (the editable field) if (this.dataGridView1.CurrentCell.ColumnIndex != 1) { this.dataGridView1.CurrentCell = this.dataGridView1.Rows[this.dataGridView1.CurrentCell.RowIndex].Cells[1]; } // Edit contents if (this.dataGridView1.CurrentNode.Nodes.Count == 0) this.dataGridView1.BeginEdit(true); } this.OnSelectedPropertyChanged(); }
private bool GetDateTimeType(PropertyData prop, ref CodeTypeReference codeType) { bool flag = false; codeType = null; if (prop.IsArray) { codeType = new CodeTypeReference("System.DateTime", 1); } else { codeType = new CodeTypeReference("System.DateTime"); } try { if (string.Compare(prop.Qualifiers["SubType"].Value.ToString(), "interval", StringComparison.OrdinalIgnoreCase) == 0) { flag = true; if (prop.IsArray) { codeType = new CodeTypeReference("System.TimeSpan", 1); } else { codeType = new CodeTypeReference("System.TimeSpan"); } } } catch (ManagementException) { } if (flag) { if (!this.bTimeSpanConversionFunctionsAdded) { this.cc.Comments.Add(new CodeCommentStatement(GetString("COMMENT_TIMESPANCONVFUNC"))); this.bTimeSpanConversionFunctionsAdded = true; this.GenerateTimeSpanConversionFunction(); } return flag; } if (!this.bDateConversionFunctionsAdded) { this.cc.Comments.Add(new CodeCommentStatement(GetString("COMMENT_DATECONVFUNC"))); this.bDateConversionFunctionsAdded = true; this.GenerateDateTimeConversionFunction(); } return flag; }
private static String GetObjectAsString(Object obj, PropertyData p, PropertyDataValueMap map) { if (obj == null) { return String.Empty; } // Is a reference to another management class? else if (obj.GetType().IsAssignableFrom(typeof(ManagementBaseObject))) { // Expand object return ((ManagementBaseObject)obj).GetRelativePath(); } else if (p.Type == CimType.DateTime) { DateTime datetime = ManagementDateTimeConverter.ToDateTime(p.Value.ToString()); return datetime.ToString(); } else if (p.Type == CimType.UInt64 && p.Name == "TIME_CREATED") { Double ms = ((UInt64)obj) / 10000; var datetime = epoch.AddMilliseconds(ms); return datetime.ToLocalTime().ToString(); } else if (map != null && obj != null && map.ContainsKey(obj.ToString())) { return String.Format("{0} ({1})", map[obj.ToString()], obj.ToString()); } else { // Plain old string! return obj.ToString(); } }
/// <summary> /// This function will process the qualifiers for a given WMI property and set the /// attributes of the generated property accordingly. /// </summary> string ProcessPropertyQualifiers(PropertyData prop,ref bool bRead, ref bool bWrite, ref bool bStatic,bool bDynamicClass,out bool nullable) { bool hasWrite = false; bool writeValue = false; bool bMapsFailed = false; nullable = true; // property is always readable bRead = true; bWrite = false; arrConvFuncName = "ToInt32"; enumType = "System.Int32"; string description = String.Empty; foreach (QualifierData q in prop.Qualifiers) { if (String.Compare(q.Name,"description",StringComparison.OrdinalIgnoreCase) == 0) { description = q.Value.ToString(); } else if (String.Compare(q.Name,"Not_Null",StringComparison.OrdinalIgnoreCase) == 0) { nullable = false; } else if (String.Compare(q.Name,"key",StringComparison.OrdinalIgnoreCase) == 0) { //This is a key. So push it in to the key array arrKeyType.Add(cmp.Type); arrKeys.Add(prop.Name); nullable = false; break; } else if (string.Compare(q.Name,"static",StringComparison.OrdinalIgnoreCase) == 0) { //This property is static. So add static to the Type of the object bStatic = true; cmp.Attributes |= MemberAttributes.Static; } else if (string.Compare(q.Name,"read",StringComparison.OrdinalIgnoreCase) == 0) { if ((bool)q.Value == false) { bRead = false; } else { bRead = true; } } else if (string.Compare(q.Name,"write",StringComparison.OrdinalIgnoreCase) == 0) { hasWrite = true; if ((bool)q.Value == true) { writeValue = true; } else { writeValue = false; } } // check for ValueMap/Values and BitMap/BitValues pair and create // Enum Accordingly else if (string.Compare(q.Name,"ValueMap",StringComparison.OrdinalIgnoreCase) == 0 && bMapsFailed == false) { try { ValueMap.Clear(); //Now check whether the type of the property is int if (isTypeInt(prop.Type) == true) { if (q.Value != null) { string [] strArray = (string [])q.Value; for(int i=0;i < strArray.Length ;i++) { try { arrConvFuncName = ConvertToNumericValueAndAddToArray(prop.Type,strArray[i],ValueMap,out enumType); } catch(OverflowException) { // ValueMap.Add(Convert.ToInt64(strArray[i])); // bValueMapInt64 = true; } } } } } // if the value is not a numerical, then we cannot construct a enum catch(System.FormatException) { bMapsFailed = true; ValueMap.Clear(); } catch(System.InvalidCastException ) { // This exception may occur if the qualifier value is not an array as expected ValueMap.Clear(); } } else if (string.Compare(q.Name,"Values",StringComparison.OrdinalIgnoreCase) == 0 && bMapsFailed == false) { try { Values.Clear(); if (isTypeInt(prop.Type) == true) { if (q.Value != null) { ArrayList arTemp = new ArrayList(5); string [] strArray = (string[])q.Value; for(int i=0;i < strArray.Length;i++) { if(strArray[i].Length == 0) { Values.Clear(); bMapsFailed = true; break; } string strName = ConvertValuesToName(strArray[i]); arTemp.Add(strName); } ResolveEnumNameValues(arTemp,ref Values); } } } catch(System.InvalidCastException ) { // This exception may occur if the qualifier value is not an array as expected Values.Clear(); } } else if (string.Compare(q.Name,"BitMap",StringComparison.OrdinalIgnoreCase) == 0 && bMapsFailed == false) { try { BitMap.Clear(); if (isTypeInt(prop.Type) == true) { if (q.Value != null) { string [] strArray = (string [])q.Value; for(int i=0;i < strArray.Length;i++) { BitMap.Add(ConvertBitMapValueToInt32(strArray[i])); } } } } // if the value is not a numerical, then we cannot construct a enum catch(System.FormatException) { BitMap.Clear(); bMapsFailed = true; } catch(System.InvalidCastException ) { // This exception may occur if the qualifier value is not an array as expected BitMap.Clear(); } } else if (string.Compare(q.Name,"BitValues",StringComparison.OrdinalIgnoreCase) == 0 && bMapsFailed == false) { try { BitValues.Clear(); if (isTypeInt(prop.Type) == true) { if (q.Value != null) { ArrayList arTemp = new ArrayList(5); string [] strArray = (string [])q.Value; for(int i=0;i < strArray.Length;i++) { if(strArray[i].Length == 0) { BitValues.Clear(); bMapsFailed = true; break; } string strName = ConvertValuesToName(strArray[i]); arTemp.Add(strName); } ResolveEnumNameValues(arTemp,ref BitValues); } } } catch(System.InvalidCastException ) { // This exception may occur if the qualifier value is not an array as expected BitValues.Clear(); } } } // Property is not writeable only if "read" qualifier is present and its value is "true" // Also, for dynamic classes, absence of "write" qualifier means that the property is read-only. if ((!bDynamicClass && !hasWrite )|| (!bDynamicClass && hasWrite && writeValue)|| (bDynamicClass && hasWrite && writeValue) ) { bWrite = true; } return description; }
private static string getPropertyNameValue(PropertyData innerProperty) { string propertyName = null; string propertyValue = null; try { propertyName = ((PropertyData)innerProperty).Name; propertyValue = ((PropertyData)innerProperty).Value.ToString(); } catch (Exception) { propertyValue = "[Error]"; } return string.Format("[{0}]={1}", propertyName, propertyValue); }
// This function checks the "SubType" Qualifier and if the value of this qualifies // is "interval" then the returned CodeTypeReference is of type System.TimeSpan // otherwise the returned type will be System.DateTime. // This functions is called only for cimtype.DateTime type properties private bool GetDateTimeType(PropertyData prop,ref CodeTypeReference codeType ) { bool isTimeInterval = false; codeType = null; if(prop.IsArray) { codeType = new CodeTypeReference("System.DateTime",1); } else { codeType = new CodeTypeReference("System.DateTime"); } try { if(String.Compare(prop.Qualifiers["SubType"].Value.ToString() ,"interval",StringComparison.OrdinalIgnoreCase) == 0) { isTimeInterval = true; if(prop.IsArray) { codeType = new CodeTypeReference("System.TimeSpan",1); } else { codeType = new CodeTypeReference("System.TimeSpan"); } } } catch(ManagementException) { // Qualifier may not be present then ignore it } if(isTimeInterval) { if(bTimeSpanConversionFunctionsAdded == false) { cc.Comments.Add(new CodeCommentStatement(GetString("COMMENT_TIMESPANCONVFUNC"))); bTimeSpanConversionFunctionsAdded = true; // Call this function to generate conversion function GenerateTimeSpanConversionFunction(); } } else { if(bDateConversionFunctionsAdded == false) { cc.Comments.Add(new CodeCommentStatement(GetString("COMMENT_DATECONVFUNC"))); bDateConversionFunctionsAdded = true; // Call this function to generate conversion function GenerateDateTimeConversionFunction(); } } return isTimeInterval; }
public IDictionary <string, string> GetPorts() { // DeviceID PNPDeviceID // COM9 BTHENUM\{00001101-0000-1000-8000-00805F9B34FB}_LOCALMFG&0000\8&4E34AC5&0&000000000000_00000006 // COM11 BTHENUM\{00001101-0000-1000-8000-00805F9B34FB}_LOCALMFG&0000\8&4E34AC5&0&000000000000_00000011 // COM10 BTHENUM\{00001101-0000-1000-8000-00805F9B34FB}_LOCALMFG&000F\8&4E34AC5&0&0017EC34AB99_C00000000 // COM15 BTHENUM\{00001101-0000-1000-8000-00805F9B34FB}_LOCALMFG&0000\8&4E34AC5&0&000000000000_00000012 // COM16 BTHENUM\{00001101-0000-1000-8000-00805F9B34FB}_LOCALMFG&000F\8&4E34AC5&0&0017EC34A94E_C00000000 Console.WriteLine("Updating devices..."); IDictionary <string, string> results = new Dictionary <string, string>(); string queryString; //queryString = "SELECT * FROM WIN32_SerialPort"; queryString = "SELECT * FROM Win32_PnPEntity WHERE ClassGuid=\"{4d36e978-e325-11ce-bfc1-08002be10318}\""; List <object> values = new List <object>(); EnumerateInstances(queryString, (sender, obj) => // ObjectReadyEventHandler(object sender, ObjectReadyEventArgs obj) { try { ManagementObject port = (ManagementObject)obj.NewObject; // DeviceId is "BTHENUM\{00001101-0000-1000-8000-00805F9B34FB}_LOCALMFG&0002\7&4BFCAD4&0&C83E990CF8D8_C00000000" // Port number is "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Enum\" + DeviceId + "\Device Parameters\PortName" // Device Name is in HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Enum\BTHENUM\Dev_$MAC\*\FriendlyName /* * Console.WriteLine("---"); * foreach (System.Management.PropertyData Property in port.Properties) * { * Console.WriteLine(Property.Name + " " + (Property.Value == null ? null : Property.Value.ToString())); * if (Property.Value != null && Property.Value is string[]) * { * string[] strings = (string[])Property.Value; * foreach (string s in strings) * { * Console.WriteLine("..." + s); * } * } * } */ // Find Port string deviceId = port.Properties["DeviceID"].Value.ToString(); string portName = null; try { RegistryKey deviceParameters = Registry.LocalMachine.OpenSubKey(@"SYSTEM\CurrentControlSet\Enum\" + deviceId + @"\Device Parameters"); portName = deviceParameters.GetValue("PortName").ToString(); } catch (Exception) { Console.WriteLine("ERROR: Exception determining port name for " + deviceId); return; } // Find Name string label = null; if (port.Properties["Name"] != null) { System.Management.PropertyData nameProperty = port.Properties["Name"]; label = "\"" + nameProperty.Value.ToString() + "\""; } // Find Bluetooth MAC Address string mac = null; if (deviceId.StartsWith(@"BTHENUM\")) { string[] slashParts = deviceId.Split(new char[] { '\\' }); if (slashParts.Length > 2) { string[] ampersandParts = slashParts[2].Split(new char[] { '&' }); for (int i = 0; i < ampersandParts.Length; i++) { string temp = ampersandParts[i]; int underscore = temp.IndexOf('_'); if (underscore >= 0) { temp = temp.Substring(0, underscore); } //if (temp.Length > 12) { temp = temp.Substring(temp.Length - 12); } if (temp.Length == 12) { mac = temp; } } } if (mac == "000000000000") { mac = null; } } // Find Bluetooth device name string deviceName = null; if (mac != null) { // Device Name is in HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Enum\BTHENUM\Dev_$MAC\*\FriendlyName try { RegistryKey devKey = Registry.LocalMachine.OpenSubKey(@"SYSTEM\CurrentControlSet\Enum\BTHENUM\" + "Dev_" + mac); // Find first sub-key string[] subKeys = devKey.GetSubKeyNames(); if (subKeys.Length > 0) { // Device Name is in HKEY_LOCAL_MACHINE\ Dev_$MAC\*\FriendlyName RegistryKey devKey2 = devKey.OpenSubKey(subKeys[0]); deviceName = devKey2.GetValue("FriendlyName").ToString(); } } catch (Exception) { Console.WriteLine("WARNING: Exception determining Bluetooth device name for " + deviceId); } } if (deviceName != null) { label = label + " [" + deviceName + "]"; } //label = label + " Bluetooth"; if (mac != null) { string address = "" + mac[0] + mac[1] + ':' + mac[2] + mac[3] + ':' + mac[4] + mac[5] + ':' + mac[6] + mac[7] + ':' + mac[8] + mac[9] + ':' + mac[10] + mac[11]; label = label + " <" + address + ">"; } Console.WriteLine("Port: " + portName + " - " + label); results.Add(portName, label); } catch (ManagementException e) { Console.WriteLine("Error: " + e.Message); } }); Console.WriteLine("...done."); return(results); }
private static string PropData2String(PropertyData pd) { string toReturn = string.Format("Name: {0}{1}", pd.Name, Environment.NewLine); toReturn += string.Format("IsArray: {0}{1}", pd.IsArray.ToString(), Environment.NewLine); toReturn += string.Format("IsLocal: {0}{1}", pd.IsLocal.ToString(), Environment.NewLine); toReturn += string.Format("Origin: {0}{1}", pd.Origin, Environment.NewLine); toReturn += string.Format("CIMType: {0}{1}", pd.Type.ToString(), Environment.NewLine); if (pd.Value != null) toReturn += string.Format("Value: {0}{1}", pd.Value.ToString(), Environment.NewLine); else toReturn += string.Format("Value is null{0}", Environment.NewLine); int i = 0; foreach (QualifierData qd in pd.Qualifiers) { toReturn += string.Format("\tQualifier[{0}]IsAmended: {1}{2}", i.ToString(CultureInfo.InvariantCulture), qd.IsAmended.ToString(), Environment.NewLine); toReturn += string.Format("\tQualifier[{0}]IsLocal: {1}{2}", i.ToString(CultureInfo.InvariantCulture), qd.IsLocal.ToString(), Environment.NewLine); toReturn += string.Format("\tQualifier[{0}]IsOverridable: {1}{2}", i.ToString(CultureInfo.InvariantCulture), qd.IsOverridable.ToString(), Environment.NewLine); toReturn += string.Format("\tQualifier[{0}]Name: {1}{2}", i.ToString(CultureInfo.InvariantCulture), qd.Name, Environment.NewLine); toReturn += string.Format("\tQualifier[{0}]PropagatesToInstance: {1}{2}", i.ToString(CultureInfo.InvariantCulture), qd.PropagatesToInstance.ToString(), Environment.NewLine); toReturn += string.Format("\tQualifier[{0}]PropagatesToSubclass: {1}{2}", i.ToString(CultureInfo.InvariantCulture), qd.PropagatesToSubclass.ToString(), Environment.NewLine); if (qd.Value != null) toReturn += string.Format("\tQualifier[{0}]Value: {1}{2}", i.ToString(CultureInfo.InvariantCulture), qd.Value.ToString(), Environment.NewLine); else toReturn += string.Format("\tQualifier[{0}]Value is null{1}", i.ToString(CultureInfo.InvariantCulture), Environment.NewLine); i++; } return toReturn; }
private bool GeneratePropertyHelperEnums(PropertyData prop, string strPropertyName, bool bNullable) { bool flag = false; bool flag1 = false; string str = this.ResolveCollision(string.Concat(strPropertyName, "Values"), true); if (this.Values.Count > 0 && (this.ValueMap.Count == 0 || this.ValueMap.Count == this.Values.Count)) { if (this.ValueMap.Count == 0) { flag1 = true; } this.EnumObj = new CodeTypeDeclaration(str); if (!prop.IsArray) { this.cmp.Type = new CodeTypeReference(str); } else { this.cmp.Type = new CodeTypeReference(str, 1); } this.EnumObj.IsEnum = true; this.EnumObj.TypeAttributes = TypeAttributes.Public; long num = (long)0; for (int i = 0; i < this.Values.Count; i++) { this.cmf = new CodeMemberField(); this.cmf.Name = this.Values[i].ToString(); if (this.ValueMap.Count <= 0) { this.cmf.InitExpression = new CodePrimitiveExpression((object)i); if ((long)i > num) { num = (long)i; } } else { this.cmf.InitExpression = new CodePrimitiveExpression(this.ValueMap[i]); long num1 = Convert.ToInt64(this.ValueMap[i], (IFormatProvider)CultureInfo.InvariantCulture.GetFormat(typeof(ulong))); if (num1 > num) { num = num1; } if (!flag1 && Convert.ToInt64(this.ValueMap[i], (IFormatProvider)CultureInfo.InvariantCulture.GetFormat(typeof(ulong))) == (long)0) { flag1 = true; } } this.EnumObj.Members.Add(this.cmf); } if (!bNullable || flag1) { if (!bNullable || !flag1) { if (!bNullable && !flag1) { this.cmf = new CodeMemberField(); this.cmf.Name = "INVALID_ENUM_VALUE"; this.cmf.InitExpression = new CodePrimitiveExpression((object)0); this.EnumObj.Members.Add(this.cmf); prop.NullEnumValue = (long)0; } } else { this.cmf = new CodeMemberField(); this.cmf.Name = "NULL_ENUM_VALUE"; this.cmf.InitExpression = new CodePrimitiveExpression((object)((int)(num + (long)1))); this.EnumObj.Members.Add(this.cmf); prop.NullEnumValue = (long)((int)(num + (long)1)); } } else { this.cmf = new CodeMemberField(); this.cmf.Name = "NULL_ENUM_VALUE"; this.cmf.InitExpression = new CodePrimitiveExpression((object)0); this.EnumObj.Members.Add(this.cmf); prop.NullEnumValue = (long)0; } this.cc.Members.Add(this.EnumObj); flag = true; } this.Values.Clear(); this.ValueMap.Clear(); flag1 = false; if (this.BitValues.Count > 0 && (this.BitMap.Count == 0 || this.BitMap.Count == this.BitValues.Count)) { if (this.BitMap.Count == 0) { flag1 = true; } this.EnumObj = new CodeTypeDeclaration(str); if (!prop.IsArray) { this.cmp.Type = new CodeTypeReference(str); } else { this.cmp.Type = new CodeTypeReference(str, 1); } this.EnumObj.IsEnum = true; this.EnumObj.TypeAttributes = TypeAttributes.Public; int num2 = 1; long num3 = (long)0; for (int j = 0; j < this.BitValues.Count; j++) { this.cmf = new CodeMemberField(); this.cmf.Name = this.BitValues[j].ToString(); if (this.BitMap.Count <= 0) { this.cmf.InitExpression = new CodePrimitiveExpression((object)num2); if ((long)num2 > num3) { num3 = (long)num2; } num2 = num2 << 1; } else { this.cmf.InitExpression = new CodePrimitiveExpression(this.BitMap[j]); long num4 = Convert.ToInt64(this.BitMap[j], (IFormatProvider)CultureInfo.InvariantCulture.GetFormat(typeof(ulong))); if (num4 > num3) { num3 = num4; } } if (!flag1 && Convert.ToInt64(this.BitMap[j], (IFormatProvider)CultureInfo.InvariantCulture.GetFormat(typeof(ulong))) == (long)0) { flag1 = true; } this.EnumObj.Members.Add(this.cmf); } if (!bNullable || flag1) { if (!bNullable || !flag1) { if (!bNullable && !flag1) { this.cmf = new CodeMemberField(); this.cmf.Name = "INVALID_ENUM_VALUE"; this.cmf.InitExpression = new CodePrimitiveExpression((object)0); this.EnumObj.Members.Add(this.cmf); prop.NullEnumValue = (long)0; } } else { this.cmf = new CodeMemberField(); this.cmf.Name = "NULL_ENUM_VALUE"; if (this.BitValues.Count <= 30) { num3 = num3 << 1; } else { num3 = num3 + (long)1; } this.cmf.InitExpression = new CodePrimitiveExpression((object)((int)num3)); this.EnumObj.Members.Add(this.cmf); prop.NullEnumValue = (long)((int)num3); } } else { this.cmf = new CodeMemberField(); this.cmf.Name = "NULL_ENUM_VALUE"; this.cmf.InitExpression = new CodePrimitiveExpression((object)0); this.EnumObj.Members.Add(this.cmf); prop.NullEnumValue = (long)0; } this.cc.Members.Add(this.EnumObj); flag = true; } this.BitValues.Clear(); this.BitMap.Clear(); return flag; }