源代码改用vs默认格式化

This commit is contained in:
28810
2019-06-27 09:40:35 +08:00
parent 873364c7ee
commit f8c3608fda
309 changed files with 73814 additions and 67594 deletions

View File

@ -4,71 +4,77 @@ using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Linq.Expressions;
namespace FreeSql.Internal.Model {
public class ColumnInfo {
public TableInfo Table { get; set; }
public string CsName { get; set; }
public Type CsType { get; set; }
public ColumnAttribute Attribute { get; set; }
public string Comment { get; internal set; }
namespace FreeSql.Internal.Model
{
public class ColumnInfo
{
public TableInfo Table { get; set; }
public string CsName { get; set; }
public Type CsType { get; set; }
public ColumnAttribute Attribute { get; set; }
public string Comment { get; internal set; }
static ConcurrentDictionary<ColumnInfo, Func<object, object>> _dicGetMapValue = new ConcurrentDictionary<ColumnInfo, Func<object, object>>();
public object GetMapValue(object obj) {
var func = _dicGetMapValue.GetOrAdd(this, col => {
var paramExp = Expression.Parameter(typeof(object));
var returnTarget = Expression.Label(typeof(object));
static ConcurrentDictionary<ColumnInfo, Func<object, object>> _dicGetMapValue = new ConcurrentDictionary<ColumnInfo, Func<object, object>>();
public object GetMapValue(object obj)
{
var func = _dicGetMapValue.GetOrAdd(this, col =>
{
var paramExp = Expression.Parameter(typeof(object));
var returnTarget = Expression.Label(typeof(object));
if (Attribute.MapType == CsType)
return Expression.Lambda<Func<object, object>>(
Expression.Block(
Expression.Return(returnTarget, Expression.Convert(
Expression.MakeMemberAccess(
Expression.TypeAs(paramExp, col.Table.Type),
Table.Properties[col.CsName]
), typeof(object))),
Expression.Label(returnTarget, Expression.Default(typeof(object)))
), new[] { paramExp }).Compile();
if (Attribute.MapType == CsType)
return Expression.Lambda<Func<object, object>>(
Expression.Block(
Expression.Return(returnTarget, Expression.Convert(
Expression.MakeMemberAccess(
Expression.TypeAs(paramExp, col.Table.Type),
Table.Properties[col.CsName]
), typeof(object))),
Expression.Label(returnTarget, Expression.Default(typeof(object)))
), new[] { paramExp }).Compile();
var retExp = Expression.Variable(typeof(object), "ret");
var blockExp = new List<Expression>();
blockExp.AddRange(new Expression[] {
Expression.Assign(retExp, Utils.GetDataReaderValueBlockExpression(Attribute.MapType,
Expression.MakeMemberAccess(
Expression.TypeAs(paramExp, col.Table.Type),
Table.Properties[col.CsName]
)
)),
Expression.Return(returnTarget, retExp),
Expression.Label(returnTarget, Expression.Default(typeof(object)))
});
return Expression.Lambda<Func<object, object>>(Expression.Block(new[] { retExp }, blockExp), new[] { paramExp }).Compile();
});
return func(obj);
}
static ConcurrentDictionary<ColumnInfo, Action<object, object>> _dicSetMapValue = new ConcurrentDictionary<ColumnInfo, Action<object, object>>();
public void SetMapValue(object obj, object val) {
var func = _dicSetMapValue.GetOrAdd(this, col => {
var objExp = Expression.Parameter(typeof(object), "obj");
var valExp = Expression.Parameter(typeof(object), "val");
var retExp = Expression.Variable(typeof(object), "ret");
var blockExp = new List<Expression>();
blockExp.AddRange(new Expression[] {
Expression.Assign(retExp, Utils.GetDataReaderValueBlockExpression(Attribute.MapType,
Expression.MakeMemberAccess(
Expression.TypeAs(paramExp, col.Table.Type),
Table.Properties[col.CsName]
)
)),
Expression.Return(returnTarget, retExp),
Expression.Label(returnTarget, Expression.Default(typeof(object)))
});
return Expression.Lambda<Func<object, object>>(Expression.Block(new[] { retExp }, blockExp), new[] { paramExp }).Compile();
});
return func(obj);
}
static ConcurrentDictionary<ColumnInfo, Action<object, object>> _dicSetMapValue = new ConcurrentDictionary<ColumnInfo, Action<object, object>>();
public void SetMapValue(object obj, object val)
{
var func = _dicSetMapValue.GetOrAdd(this, col =>
{
var objExp = Expression.Parameter(typeof(object), "obj");
var valExp = Expression.Parameter(typeof(object), "val");
if (Attribute.MapType == CsType)
return Expression.Lambda<Action<object, object>>(
Expression.Assign(Expression.MakeMemberAccess(
Expression.TypeAs(objExp, col.Table.Type),
Table.Properties[col.CsName]
), Expression.Convert(
valExp,
Attribute.MapType)), objExp, valExp).Compile();
if (Attribute.MapType == CsType)
return Expression.Lambda<Action<object, object>>(
Expression.Assign(Expression.MakeMemberAccess(
Expression.TypeAs(objExp, col.Table.Type),
Table.Properties[col.CsName]
), Expression.Convert(
valExp,
Attribute.MapType)), objExp, valExp).Compile();
return Expression.Lambda<Action<object, object>>(
Expression.Assign(Expression.MakeMemberAccess(
Expression.TypeAs(objExp, col.Table.Type),
Table.Properties[col.CsName]
), Expression.Convert(
Utils.GetDataReaderValueBlockExpression(Attribute.MapType, valExp),
Attribute.MapType)), objExp, valExp).Compile();
});
func(obj, val);
}
}
return Expression.Lambda<Action<object, object>>(
Expression.Assign(Expression.MakeMemberAccess(
Expression.TypeAs(objExp, col.Table.Type),
Table.Properties[col.CsName]
), Expression.Convert(
Utils.GetDataReaderValueBlockExpression(Attribute.MapType, valExp),
Attribute.MapType)), objExp, valExp).Compile();
});
func(obj, val);
}
}
}

View File

@ -3,17 +3,19 @@ using System.Collections.Generic;
using System.Reflection;
using System.Text;
namespace FreeSql.Internal.Model {
public class ReadAnonymousTypeInfo {
public PropertyInfo Property { get; set; }
public string CsName { get; set; }
public Type CsType { get; set; }
public Type MapType { get; set; }
public string DbField { get; set; }
public ConstructorInfo Consturctor { get; set; }
public ReadAnonymousTypeInfoConsturctorType ConsturctorType { get; set; }
public List<ReadAnonymousTypeInfo> Childs = new List<ReadAnonymousTypeInfo>();
public TableInfo Table { get; set; }
}
public enum ReadAnonymousTypeInfoConsturctorType { Arguments, Properties }
namespace FreeSql.Internal.Model
{
public class ReadAnonymousTypeInfo
{
public PropertyInfo Property { get; set; }
public string CsName { get; set; }
public Type CsType { get; set; }
public Type MapType { get; set; }
public string DbField { get; set; }
public ConstructorInfo Consturctor { get; set; }
public ReadAnonymousTypeInfoConsturctorType ConsturctorType { get; set; }
public List<ReadAnonymousTypeInfo> Childs = new List<ReadAnonymousTypeInfo>();
public TableInfo Table { get; set; }
}
public enum ReadAnonymousTypeInfoConsturctorType { Arguments, Properties }
}

View File

@ -2,9 +2,11 @@
using System.Collections.Generic;
using System.Text;
namespace FreeSql.Internal.Model {
public class SelectColumnInfo {
public ColumnInfo Column { get; set; }
public SelectTableInfo Table { get; set; }
}
namespace FreeSql.Internal.Model
{
public class SelectColumnInfo
{
public ColumnInfo Column { get; set; }
public SelectTableInfo Table { get; set; }
}
}

View File

@ -1,22 +1,26 @@
using System.Linq.Expressions;
namespace FreeSql.Internal.Model {
public class SelectTableInfo {
public TableInfo Table { get; set; }
namespace FreeSql.Internal.Model
{
public class SelectTableInfo
{
public TableInfo Table { get; set; }
private string _alias;
public string Alias {
get => _alias;
set {
_alias = value;
if (string.IsNullOrEmpty(AliasInit)) AliasInit = value;
}
}
public string AliasInit { get; set; }
public string On { get; set; }
public string NavigateCondition { get; set; }
public ParameterExpression Parameter { get; set; }
public SelectTableInfoType Type { get; set; }
}
public enum SelectTableInfoType { From, LeftJoin, InnerJoin, RightJoin, Parent }
private string _alias;
public string Alias
{
get => _alias;
set
{
_alias = value;
if (string.IsNullOrEmpty(AliasInit)) AliasInit = value;
}
}
public string AliasInit { get; set; }
public string On { get; set; }
public string NavigateCondition { get; set; }
public ParameterExpression Parameter { get; set; }
public SelectTableInfoType Type { get; set; }
}
public enum SelectTableInfoType { From, LeftJoin, InnerJoin, RightJoin, Parent }
}

View File

@ -3,58 +3,65 @@ using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Reflection;
namespace FreeSql.Internal.Model {
public class TableInfo {
public Type Type { get; set; }
public Type TypeLazy { get; set; }
public MethodInfo TypeLazySetOrm { get; set; }
public Dictionary<string, PropertyInfo> Properties { get; set; } = new Dictionary<string, PropertyInfo>(StringComparer.CurrentCultureIgnoreCase);
public Dictionary<string, ColumnInfo> Columns { get; set; } = new Dictionary<string, ColumnInfo>(StringComparer.CurrentCultureIgnoreCase);
public Dictionary<string, ColumnInfo> ColumnsByCs { get; set; } = new Dictionary<string, ColumnInfo>(StringComparer.CurrentCultureIgnoreCase);
public Dictionary<string, ColumnInfo> ColumnsByCsIgnore { get; set; } = new Dictionary<string, ColumnInfo>(StringComparer.CurrentCultureIgnoreCase);
public ColumnInfo[] Primarys { get; set; }
public Dictionary<string, List<ColumnInfo>> Uniques { get; set; }
public string CsName { get; set; }
public string DbName { get; set; }
public string DbOldName { get; set; }
public string SelectFilter { get; set; }
public bool DisableSyncStructure { get; set; }
namespace FreeSql.Internal.Model
{
public class TableInfo
{
public Type Type { get; set; }
public Type TypeLazy { get; set; }
public MethodInfo TypeLazySetOrm { get; set; }
public Dictionary<string, PropertyInfo> Properties { get; set; } = new Dictionary<string, PropertyInfo>(StringComparer.CurrentCultureIgnoreCase);
public Dictionary<string, ColumnInfo> Columns { get; set; } = new Dictionary<string, ColumnInfo>(StringComparer.CurrentCultureIgnoreCase);
public Dictionary<string, ColumnInfo> ColumnsByCs { get; set; } = new Dictionary<string, ColumnInfo>(StringComparer.CurrentCultureIgnoreCase);
public Dictionary<string, ColumnInfo> ColumnsByCsIgnore { get; set; } = new Dictionary<string, ColumnInfo>(StringComparer.CurrentCultureIgnoreCase);
public ColumnInfo[] Primarys { get; set; }
public Dictionary<string, List<ColumnInfo>> Uniques { get; set; }
public string CsName { get; set; }
public string DbName { get; set; }
public string DbOldName { get; set; }
public string SelectFilter { get; set; }
public bool DisableSyncStructure { get; set; }
public ColumnInfo VersionColumn { get; set; }
public ColumnInfo VersionColumn { get; set; }
ConcurrentDictionary<string, TableRef> _refs { get; } = new ConcurrentDictionary<string, TableRef>(StringComparer.CurrentCultureIgnoreCase);
ConcurrentDictionary<string, TableRef> _refs { get; } = new ConcurrentDictionary<string, TableRef>(StringComparer.CurrentCultureIgnoreCase);
internal void AddOrUpdateTableRef(string propertyName, TableRef tbref) {
_refs.AddOrUpdate(propertyName, tbref, (ok, ov) => tbref);
}
public TableRef GetTableRef(string propertyName, bool isThrowException) {
if (_refs.TryGetValue(propertyName, out var tryref) == false) return null;
if (tryref.Exception != null) {
if (isThrowException) throw tryref.Exception;
return null;
}
return tryref;
}
}
internal void AddOrUpdateTableRef(string propertyName, TableRef tbref)
{
_refs.AddOrUpdate(propertyName, tbref, (ok, ov) => tbref);
}
public TableRef GetTableRef(string propertyName, bool isThrowException)
{
if (_refs.TryGetValue(propertyName, out var tryref) == false) return null;
if (tryref.Exception != null)
{
if (isThrowException) throw tryref.Exception;
return null;
}
return tryref;
}
}
public class TableRef {
public PropertyInfo Property { get; set; }
public class TableRef
{
public PropertyInfo Property { get; set; }
public TableRefType RefType { get; set; }
public TableRefType RefType { get; set; }
public Type RefEntityType { get; set; }
/// <summary>
/// 中间表,多对多
/// </summary>
public Type RefMiddleEntityType { get; set; }
public Type RefEntityType { get; set; }
/// <summary>
/// 中间表,多对多
/// </summary>
public Type RefMiddleEntityType { get; set; }
public List<ColumnInfo> Columns { get; set; } = new List<ColumnInfo>();
public List<ColumnInfo> MiddleColumns { get; set; } = new List<ColumnInfo>();
public List<ColumnInfo> RefColumns { get; set; } = new List<ColumnInfo>();
public List<ColumnInfo> Columns { get; set; } = new List<ColumnInfo>();
public List<ColumnInfo> MiddleColumns { get; set; } = new List<ColumnInfo>();
public List<ColumnInfo> RefColumns { get; set; } = new List<ColumnInfo>();
public Exception Exception { get; set; }
}
public enum TableRefType {
OneToOne, ManyToOne, OneToMany, ManyToMany
}
public Exception Exception { get; set; }
}
public enum TableRefType
{
OneToOne, ManyToOne, OneToMany, ManyToMany
}
}