本文整理汇总了C#中ISqlDialect.ConvertParameterValue方法的典型用法代码示例。如果您正苦于以下问题:C# ISqlDialect.ConvertParameterValue方法的具体用法?C# ISqlDialect.ConvertParameterValue怎么用?C# ISqlDialect.ConvertParameterValue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ISqlDialect
的用法示例。
在下文中一共展示了ISqlDialect.ConvertParameterValue方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetExpressionValue
static string GetExpressionValue(ISqlDialect dialect, Expression rootExpression, Expression e, IDictionary<string, object> parameters, Func<string> getParameterName)
{
var de = (dynamic)e;
if (de.NodeType == ExpressionType.MemberAccess)
{
object val = null;
var t = (Type)de.Type;
var fieldName = de.Member.Name;
if (t == typeof(DateTime))
{
if (fieldName == "Now")
{
val = DateTime.Now;
}
else if (fieldName == "UtcNow")
{
val = DateTime.UtcNow;
}
}
if (val != null)
{
var id = getParameterName();
parameters.Add(id, dialect.ConvertParameterValue(val));
return id;
}
}
var ce = (e is ConstantExpression) ? e : de.Expression;
if (ce.NodeType == ExpressionType.Constant)
{
var val = ce.Value;
if (!(e is ConstantExpression))
{
var t = (Type)ce.Type;
var fieldName = de.Member.Name;
var fieldInfo = t.GetField(fieldName) ?? t.GetField(fieldName, BindingFlags.Instance | BindingFlags.NonPublic);
if (fieldInfo != null)
{
val = fieldInfo.GetValue(val);
}
else
{
PropertyInfo propInfo = t.GetProperty(fieldName) ?? t.GetProperty(fieldName, BindingFlags.Instance | BindingFlags.NonPublic);
if (propInfo != null)
{
val = propInfo.GetValue(val, null);
}
}
//var mt = (System.Reflection.MemberTypes)(de.Member).MemberType;
//if (mt == System.Reflection.MemberTypes.Field)
//{
// var fieldInfo = t.GetField(fieldName) ?? t.GetField(fieldName, BindingFlags.Instance | BindingFlags.NonPublic);
// val = fieldInfo.GetValue(val);
//}
//else if (mt == System.Reflection.MemberTypes.Property)
//{
// PropertyInfo propInfo = t.GetProperty(fieldName) ?? t.GetProperty(fieldName, BindingFlags.Instance | BindingFlags.NonPublic);
// val = propInfo.GetValue(val, null);
//}
}
if (val == null)
{
return _NULL;
}
else if ((val as string) == _Space)
{
return "' '";
}
else
{
var id = getParameterName();
parameters.Add(id, dialect.ConvertParameterValue(val));
return id;
}
}
else if (ce.NodeType == ExpressionType.MemberAccess)
{
var val = GetMemberAccessValue(rootExpression, e);
if (val == null)
{
return _NULL;
}
else if ((val as string) == _Space)
{
return "' '";
}
else
{
var id = getParameterName();
parameters.Add(id, dialect.ConvertParameterValue(val));
return id;
//.........这里部分代码省略.........