public static Type GetFieldType(AApiVersionedFields owner, string field) { try { Type type = AApiVersionedFields.GetContentFieldTypes(0, owner.GetType())[GetFieldName(field)]; if (field.IndexOf(' ') == -1) { return(type); } else { if (type.HasElementType && !type.GetElementType().IsAbstract) { return(type.GetElementType()); } Type baseType = GetGenericType(type); if (baseType != null && !baseType.IsAbstract) { return(baseType); } return(GetFieldValue(owner, field).Type); } } catch (Exception ex) { throw ex; } }
void setFlags(AApiVersionedFields owner, string field, ulong mask, bool value) { ulong old = getFlags(owner, field); ulong res = old & ~mask; if (value) { res |= mask; } Type t = AApiVersionedFields.GetContentFieldTypes(0, owner.GetType())[field]; TypedValue tv = new TypedValue(t, Enum.ToObject(t, res)); owner[field] = tv; }
void SetFields() { Dictionary <string, Type> cft = AApiVersionedFields.GetContentFieldTypes(0, typeof(AResourceIndexEntry)); values = new Dictionary <string, FilterField>(); tlpResourceInfo.ColumnCount = fields.Count + 1; tlpResourceInfo.RowCount = 1; tlpResourceInfo.RowStyles.Clear(); tlpResourceInfo.RowStyles.Add(new RowStyle(SizeType.AutoSize)); tlpResourceInfo.RowStyles.Add(new RowStyle(SizeType.Percent, 100)); tlpResourceInfo.ColumnStyles.Clear(); tlpResourceInfo.ColumnStyles.Add(new ColumnStyle(SizeType.AutoSize)); tlpResourceInfo.Controls.Add(tlpControls, 0, 0); for (int i = 0; i < fields.Count; i++) { if (fields[i] == "Name") { tlpResourceInfo.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 133)); } else if (fields[i] == "Instance") { tlpResourceInfo.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 150)); } else if (i > 4 || fields[i] == "Tag") { tlpResourceInfo.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 75)); } else { tlpResourceInfo.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 100)); } FilterField ff = new FilterField(!nonRIEFields.Contains(fields[i])); ff.Name = fields[i]; ff.Dock = DockStyle.Fill; ff.Checked = false; ff.Filter = new Regex(""); ff.Title = fields[i]; ff.Value = new Regex(""); ff.TabIndex = i + 2; tlpResourceInfo.Controls.Add(ff, i + 1, 0); values.Add(fields[i], ff); } tlpResourceInfo.PerformLayout(); }
public override PropertyDescriptorCollection GetProperties(ITypeDescriptorContext context, object value, Attribute[] attributes) { EnumFlagsCTD ctd = (EnumFlagsCTD)value; string name = ctd.field.Split(' ').Length == 1 ? ctd.field : ctd.field.Split(new char[] { ' ' }, 2)[1].Trim(); Type enumType = AApiVersionedFields.GetContentFieldTypes(0, ctd.owner.GetType())[name]; int bits = underlyingTypeToBits(Enum.GetUnderlyingType(enumType)); EnumFlagPropertyDescriptor[] enumFlags = new EnumFlagPropertyDescriptor[bits]; string fmt = "[{0:X" + bits.ToString("X").Length + "}] "; for (int i = 0; i < bits; i++) { ulong u = (ulong)1 << i; string s = (Enum)Enum.ToObject(enumType, u) + ""; if (s == u.ToString()) { s = "-"; } s = String.Format(fmt, i) + s; enumFlags[i] = new EnumFlagPropertyDescriptor(ctd.owner, ctd.field, u, s); } return(new PropertyDescriptorCollection(enumFlags)); }
public void SetField(AApiVersionedFields owner, string field) { type = AApiVersionedFields.GetContentFieldTypes(0, owner.GetType())[field]; if (!(typeof(TextReader).IsAssignableFrom(type) || typeof(BinaryReader).IsAssignableFrom(type))) { throw new InvalidCastException(); } this.owner = owner; this.field = field; btnImport.Enabled = owner.GetType().GetProperty(field).CanWrite; btnExport.Enabled = owner.GetType().GetProperty(field).CanRead; //TextReader does not have BaseStream, which is needed for ViewHex btnViewHex.Enabled = typeof(BinaryReader).IsAssignableFrom(type); btnEdit.Enabled = false; if (btnExport.Enabled && btnImport.Enabled) { bool hasText = S4PIDemoFE.Properties.Settings.Default.TextEditorCmd != null && S4PIDemoFE.Properties.Settings.Default.TextEditorCmd.Length > 0; bool hasHex = S4PIDemoFE.Properties.Settings.Default.HexEditorCmd != null && S4PIDemoFE.Properties.Settings.Default.HexEditorCmd.Length > 0; btnEdit.Enabled = (typeof(TextReader).IsAssignableFrom(type) && hasText) || (typeof(BinaryReader).IsAssignableFrom(type) && hasHex); } }