本文整理汇总了C#中System.Linq.Expressions.ConstantExpression类的典型用法代码示例。如果您正苦于以下问题:C# ConstantExpression类的具体用法?C# ConstantExpression怎么用?C# ConstantExpression使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ConstantExpression类属于System.Linq.Expressions命名空间,在下文中一共展示了ConstantExpression类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: VisitConstant
protected override Expression VisitConstant(ConstantExpression c)
{
// have to do something here about type matching the types of Azure services
if (c.Type == typeof(LinqToAzureOrderedQueryable<StorageAccount>) || c.Type == typeof(LinqToAzureOrderedQueryable<CloudService>))
return Expression.Constant(_accounts);
return c;
}
示例2: Replace
internal static Expression Replace(Expression expressionToAlter,
ConstantExpression subExpressionToFind, Expression replacementExpression)
{
var visitor = new SubExpressionReplacer(subExpressionToFind, replacementExpression);
return visitor.Visit(expressionToAlter);
}
示例3: VisitConstant
protected override Expression VisitConstant(ConstantExpression constantExpression)
{
return constantExpression.Type.GetTypeInfo().IsGenericType
&& constantExpression.Type.GetGenericTypeDefinition() == typeof(EntityQueryable<>)
? VisitEntityQueryable(((IQueryable)constantExpression.Value).ElementType)
: constantExpression;
}
示例4: VisitConstant
protected override Expression VisitConstant(ConstantExpression constantExpression)
{
if (constantExpression.Value == null)
{
return base.VisitConstant(constantExpression);
}
var type = constantExpression.Value.GetType();
switch (Type.GetTypeCode(type))
{
case TypeCode.Boolean:
if (Convert.ToBoolean(constantExpression.Value))
{
this.Write(this.ParameterIndicatorPrefix);
this.Write(ParamNamePrefix);
this.Write(this.parameterValues.Count);
this.parameterValues.Add(new Tuple<Type, object>(typeof(string), "true"));
return constantExpression;
}
else
{
this.Write(this.ParameterIndicatorPrefix);
this.Write(ParamNamePrefix);
this.Write(this.parameterValues.Count);
this.parameterValues.Add(new Tuple<Type, object>(typeof(string), "false"));
return constantExpression;
}
}
return base.VisitConstant(constantExpression);
}
示例5: VisitConstant
protected override Expression VisitConstant(ConstantExpression c)
{
if (c.Type == typeof(MethodInfo))
_methodInfo = c.Value as MethodInfo;
return base.VisitConstant(c);
}
示例6: ConvertEntityRef
private string ConvertEntityRef(ConstantExpression expression)
{
FieldInfo field = expression.Value.GetType().GetFields().First();
object value = field.GetValue(expression.Value);
this.Parameters.Add(value);
return "?";
}
示例7: CreateNamedValueForConstant
protected virtual NamedValueExpression CreateNamedValueForConstant(ConstantExpression expression)
{
var name = "p" + (iParam++);
var nv = new NamedValueExpression(name, expression);
map.Add(GetKeyNameForConstantExpression(expression), new List<NamedValueExpression> { nv });
return nv;
}
示例8: From
public static QueryProxyReference From(ConstantExpression cex)
{
return new QueryProxyReference
{
Type = XmlMetadataInfo.FromMetadata(cex.Type)
};
}
示例9: VisitConstant
protected override Expression VisitConstant(ConstantExpression c)
{
IQueryable q = c.Value as IQueryable;
if (q != null)
{
_query.Index = q.ElementType.Name;
}
else if (c.Value == null)
{
//sb.Append("NULL");
}
else
{
switch (Type.GetTypeCode(c.Value.GetType()))
{
case TypeCode.Boolean:
//sb.Append(((bool)c.Value) ? 1 : 0);
break;
case TypeCode.String:
// sb.Append("'");
// sb.Append(c.Value);
// sb.Append("'");
break;
case TypeCode.Object:
throw new NotSupportedException(string.Format("The constant for '{0}' is not supported", c.Value));
default:
// sb.Append(c.Value);
break;
}
}
return c;
}
示例10: AddQueryPart
public void AddQueryPart(UnaryExpression leftItem, ConstantExpression rightValue, ExpressionType nodeType)
{
if(leftItem.Operand is MethodCallExpression)
{
var unaryOperation = (MethodCallExpression)leftItem.Operand;
if(unaryOperation.Method.Name != "get_Item")
{
throw new InvalidOperationException("Queries based on " + leftItem.Method.Name + " are not yet supported.");
}
if(unaryOperation.Arguments[0] is ConstantExpression)
{
var attributeRef = ((ConstantExpression) unaryOperation.Arguments[0]).Value;
AddCriteriaToActiveSearchCondition(attributeRef.ToString(), rightValue.Value, GetSearchRelationType(nodeType));
}
else
{
throw new InvalidOperationException("Only constant expressions are currently supported.");
}
}
else
{
throw new InvalidOperationException("Queries based on " + leftItem.Method.Name + " are not yet supported.");
}
}
示例11: VisitConstant
protected override Expression VisitConstant(ConstantExpression constantExpression)
{
var type = constantExpression.Type;
if ((this.options & SqlExpressionComparerOptions.IgnoreConstants) != 0)
{
return constantExpression;
}
if (type.IsValueType)
{
if (constantExpression.Value != null)
{
this.hashCode ^= constantExpression.Value.GetHashCode();
}
}
else if (typeof(Expression).IsAssignableFrom(constantExpression.Type))
{
this.Visit((Expression)constantExpression.Value);
}
else if (type == typeof(string))
{
this.hashCode ^= constantExpression.Value?.GetHashCode() ?? 0;
}
return constantExpression;
}
示例12: ReplaceConstantsWithArrayIndexes
public static Expression ReplaceConstantsWithArrayIndexes(Expression node,
ConstantExpression[] constantExpressions, ParameterExpression constantsParameter)
{
var visitor = new ConstantArrayIndexizerVisitor(constantExpressions, constantsParameter);
return visitor.Visit(node);
}
示例13: VisitConstant
protected override Expression VisitConstant(ConstantExpression c)
{
if (c.Type == typeof(JournalItemsContext<UAutoContractJournalItem>))
return Expression.Constant(this.queryableJournalItems);
else
return c;
}
示例14: VisitConstant
protected override Expression VisitConstant(ConstantExpression node)
{
if (node.Value is IQueryable)
sourceQueryable = ((IQueryable)node.Value);
return node;
}
示例15: VisitConstant
protected override Expression VisitConstant(ConstantExpression c)
{
IQueryable q = c.Value as IQueryable;
if (q != null) {
//throw new ApplicationException("Nested expressions not supported.");
}
else if (c.Value == null) {
sb.Append("null");
}
else {
if (c.Value.GetType() == typeof(Guid)) {
sb.Append("'");
sb.Append(c.Value);
sb.Append("'");
}
else {
switch (Type.GetTypeCode(c.Value.GetType())) {
case TypeCode.DateTime:
sb.Append("'");
sb.Append(((DateTime)c.Value).ToString("o"));
sb.Append("'");
break;
case TypeCode.Object:
throw new NotSupportedException(string.Format("The constant for '{0}' is not supported SimpleDB.", c.Value));
default:
sb.Append("'");
sb.Append(c.Value);
sb.Append("'");
break;
}
}
}
return c;
}