Skip to content

Commit

Permalink
Trim Null
Browse files Browse the repository at this point in the history
  • Loading branch information
nnhy committed Feb 4, 2024
1 parent 39cc898 commit 6a9aa76
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 15 deletions.
25 changes: 12 additions & 13 deletions XCode/Attributes/MapAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,12 @@ public class MapAttribute : Attribute
/// <summary>数据列</summary>
public String Name { get; set; }

private MapProvider _Provider;
private MapProvider? _Provider;
/// <summary>目标提供者</summary>
public MapProvider Provider { get { return _Provider ??= GetProvider(_Type, _Key); } set { _Provider = value; } }
public MapProvider? Provider { get { return _Provider ??= GetProvider(_Type, _Key); } set { _Provider = value; } }

private readonly Type? _Type;
private readonly String? _Key;
#endregion

#region 构造
Expand All @@ -29,7 +32,7 @@ public MapAttribute(String column)
/// <param name="name"></param>
/// <param name="type"></param>
/// <param name="key"></param>
public MapAttribute(String name, Type type, String key = null)
public MapAttribute(String name, Type type, String? key = null)
{
Name = name;
_Type = type;
Expand All @@ -38,10 +41,7 @@ public MapAttribute(String name, Type type, String key = null)
#endregion

#region 方法
private readonly Type _Type;
private readonly String _Key;

private MapProvider? GetProvider(Type type, String key)
private MapProvider? GetProvider(Type? type, String? key)
{
if (type == null) return null;

Expand All @@ -50,8 +50,7 @@ public MapAttribute(String name, Type type, String key = null)

if (key.IsNullOrEmpty())
{
var k = (type.AsFactory()?.Unique?.Name) ?? throw new ArgumentNullException(nameof(key));
key = k;
key = ((type.AsFactory()?.Unique?.Name) ?? throw new ArgumentNullException(nameof(key)));
}

return new MapProvider { EntityType = type, Key = key };
Expand All @@ -64,18 +63,18 @@ public class MapProvider
{
#region 属性
/// <summary>实体类型</summary>
public Type EntityType { get; set; }
public Type? EntityType { get; set; }

/// <summary>关联键</summary>
public String Key { get; set; }
public String? Key { get; set; }
#endregion

#region 方法
/// <summary>获取数据源</summary>
/// <returns></returns>
public virtual IDictionary<Object, String> GetDataSource()
{
var fact = EntityType.AsFactory();
var fact = EntityType?.AsFactory() ?? throw new ArgumentNullException(nameof(EntityType));

var key = Key;
var mst = fact.Master?.Name;
Expand All @@ -94,7 +93,7 @@ public class MapProvider
var list = fact.Session.Count < 1000 ? fact.FindAllWithCache() : fact.FindAll("", null, null, 0, 100);

//return list.Where(e => e[key] != null).ToDictionary(e => e[key], e => e[mst] + "");
return list.Where(e => e[key] != null).ToDictionary(e => e[key], e => e.ToString());//用ToString()可以显示更多信息 2023-08-11
return list.Where(e => e[key] != null).ToDictionary(e => e[key]!, e => e.ToString());//用ToString()可以显示更多信息 2023-08-11
}
#endregion
}
2 changes: 2 additions & 0 deletions XCode/DataAccessLayer/Database/Access.cs
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,8 @@ protected override List<IDataIndex> GetIndexes(IDataTable table, DataTable index
var dic = new Dictionary<String, IDataIndex>();
foreach (var item in list)
{
if (item.Name.IsNullOrEmpty()) continue;

if (!dic.TryGetValue(item.Name, out var di))
{
dic.Add(item.Name, item);
Expand Down
4 changes: 2 additions & 2 deletions XCode/Model/BatchFinder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class BatchFinder<TKey, TEntity> where TEntity : Entity<TEntity>, new()
/// <summary>实体工厂</summary>
public IEntityFactory Factory { get; set; }

private readonly List<TKey> _Keys = new();
private readonly List<TKey> _Keys = [];
/// <summary>主键集合</summary>
public IList<TKey> Keys => _Keys;

Expand Down Expand Up @@ -66,7 +66,7 @@ public void Add(IEnumerable<TKey> keys)
if (key is String str && str.IsNullOrEmpty()) return null;
if (!_Keys.Contains(key)) throw new ArgumentOutOfRangeException(nameof(key), key, "error");

var uk = Factory.Table.FindByName(Factory.Unique);
var uk = Factory.Table.FindByName(Factory.Unique) ?? throw new ArgumentNullException(nameof(Factory.Unique), "没有唯一主键");

// 向前查询
while (_index < _Keys.Count)
Expand Down

0 comments on commit 6a9aa76

Please sign in to comment.