public ResourceDescription(ITableType tableType) { var type = tableType.TypeName; this.ResourceName = type.Name; //遍历所有自定义属性 foreach (var one in type.GetProperties()) { ObsoleteAttribute obsolete = Attribute.GetCustomAttribute(one, typeof(ObsoleteAttribute)) as ObsoleteAttribute; ColumnAttribute att = Attribute.GetCustomAttribute(one, typeof(ColumnAttribute)) as ColumnAttribute; if (att == null) { continue; } FieldDefine rf = GetPropertyInfo(one, att, obsolete); if (rf == null) { continue; } Fields.Add(rf); } }
public static ResourceDescription GetReferenceHelper(ITableType tableType) { if (!_tables.TryGetValue(tableType.FileName, out var rh)) { rh = new ResourceDescription(tableType); _tables.Add(tableType.FileName, rh); } return(rh); }
public CursorType(ITableType tableType) : base() { _tableType = tableType; }
private async void LoadTable(object obj) { if (string.IsNullOrEmpty(Global.GetInstance().ResPath)) { await((MetroWindow)Application.Current.MainWindow).ShowMessageAsync("Error", $"资源路径不对:{Global.GetInstance().ResPath}"); return; } ITableType typeObj = obj as ITableType; if (typeObj == null) { return; } var resDes = ResourceHelper.GetReferenceHelper(typeObj); foreach (var field in resDes.Fields) { if (field.Type.IsEnum) { var column = new DataGridComboBoxColumn { Header = field.ColumnName, Width = field.Width, SelectedValueBinding = new Binding(field.FieldName), }; var enumDesc = EnumHelper.GetEnumDescription(field.Type); column.ItemsSource = enumDesc.Enums; column.SelectedValuePath = "Value"; column.DisplayMemberPath = "Display"; Grid.Columns.Add(column); } else if (field.Type == typeof(bool)) { var column = new DataGridCheckBoxColumn() { Header = field.ColumnName, Width = field.Width, Binding = new Binding(field.FieldName), }; if (Styles.TryGetValue(typeof(DataGridCheckBoxColumn).Name, out var style)) { column.ElementStyle = style; column.EditingElementStyle = style; } Grid.Columns.Add(column); } else { var column = new DataGridTextColumn { Header = field.ColumnName, Width = field.Width, Binding = new Binding(field.FieldName), }; if (Styles.TryGetValue(typeof(DataGridTextColumn).Name, out var style)) { column.EditingElementStyle = style; } Grid.Columns.Add(column); } } if (!ResourceAll.IsInstance()) { ResourceAll.GetInstance().Init(); } IReferenceMgr resMgr = null; if (typeObj.TypeName == typeof(ResourceWorld)) { resMgr = ResourceAll.GetInstance().MapMgr; } if (resMgr == null) { return; } _gridData = resMgr.GetAll(); Grid.ItemsSource = _gridData; Grid.Visibility = Visibility.Visible; }