本文整理汇总了C#中Mono.CSharp.Expression类的典型用法代码示例。如果您正苦于以下问题:C# Expression类的具体用法?C# Expression怎么用?C# Expression使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Expression类属于Mono.CSharp命名空间,在下文中一共展示了Expression类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CSharpBinder
public CSharpBinder (DynamicMetaObjectBinder binder, Compiler.Expression expr, DynamicMetaObject errorSuggestion)
{
this.binder = binder;
this.expr = expr;
this.restrictions = BindingRestrictions.Empty;
this.errorSuggestion = errorSuggestion;
}
示例2: ImplicitTypeParameterConversion
public static Expression ImplicitTypeParameterConversion (Expression expr, TypeParameterSpec expr_type, TypeSpec target_type)
{
//
// From T to a type parameter U, provided T depends on U
//
if (target_type.IsGenericParameter) {
if (expr_type.TypeArguments != null && expr_type.HasDependencyOn (target_type)) {
if (expr == null)
return EmptyExpression.Null;
if (expr_type.IsReferenceType && !((TypeParameterSpec) target_type).IsReferenceType)
return new BoxedCast (expr, target_type);
return new ClassCast (expr, target_type);
}
return null;
}
//
// LAMESPEC: From T to dynamic type because it's like T to object
//
if (target_type.BuiltinType == BuiltinTypeSpec.Type.Dynamic) {
if (expr == null)
return EmptyExpression.Null;
if (expr_type.IsReferenceType)
return new ClassCast (expr, target_type);
return new BoxedCast (expr, target_type);
}
//
// From T to its effective base class C
// From T to any base class of C (it cannot contain dynamic or be of dynamic type)
// From T to any interface implemented by C
//
var base_type = expr_type.GetEffectiveBase ();
if (base_type == target_type || TypeSpec.IsBaseClass (base_type, target_type, false) || base_type.ImplementsInterface (target_type, true)) {
if (expr == null)
return EmptyExpression.Null;
if (expr_type.IsReferenceType)
return new ClassCast (expr, target_type);
return new BoxedCast (expr, target_type);
}
if (target_type.IsInterface && expr_type.IsConvertibleToInterface (target_type)) {
if (expr == null)
return EmptyExpression.Null;
if (expr_type.IsReferenceType)
return new ClassCast (expr, target_type);
return new BoxedCast (expr, target_type);
}
return null;
}
示例3: Bind
public DynamicMetaObject Bind (DynamicContext ctx, Type callingType)
{
Expression res;
try {
var rc = new Compiler.ResolveContext (new RuntimeBinderContext (ctx, callingType), ResolveOptions);
// Static typemanager and internal caches are not thread-safe
lock (resolver) {
expr = expr.Resolve (rc, Compiler.ResolveFlags.VariableOrValue);
}
if (expr == null)
throw new RuntimeBinderInternalCompilerException ("Expression resolved to null");
res = expr.MakeExpression (new Compiler.BuilderContext ());
} catch (RuntimeBinderException e) {
if (errorSuggestion != null)
return errorSuggestion;
res = CreateBinderException (e.Message);
} catch (Exception) {
if (errorSuggestion != null)
return errorSuggestion;
throw;
}
return new DynamicMetaObject (res, restrictions);
}
示例4: Argument
public Argument (Expression expr)
{
if (expr == null)
throw new ArgumentNullException ();
this.Expr = expr;
}
示例5: ExplicitConversion
/// <summary>
/// Performs an explicit conversion of the expression `expr' whose
/// type is expr.Type to `target_type'.
/// </summary>
public static Expression ExplicitConversion(ResolveContext ec, Expression expr,
TypeSpec target_type, Location loc)
{
Expression e = ExplicitConversionCore (ec, expr, target_type, loc);
if (e != null) {
//
// Don't eliminate explicit precission casts
//
if (e == expr) {
if (target_type.BuiltinType == BuiltinTypeSpec.Type.Float)
return new OpcodeCast (expr, target_type, OpCodes.Conv_R4);
if (target_type.BuiltinType == BuiltinTypeSpec.Type.Double)
return new OpcodeCast (expr, target_type, OpCodes.Conv_R8);
}
return e;
}
TypeSpec expr_type = expr.Type;
if (target_type.IsNullableType) {
TypeSpec target;
if (expr_type.IsNullableType) {
target = Nullable.NullableInfo.GetUnderlyingType (target_type);
Expression unwrap = Nullable.Unwrap.Create (expr);
e = ExplicitConversion (ec, unwrap, target, expr.Location);
if (e == null)
return null;
return new Nullable.LiftedConversion (e, unwrap, target_type).Resolve (ec);
}
if (expr_type.BuiltinType == BuiltinTypeSpec.Type.Object) {
return new UnboxCast (expr, target_type);
}
target = TypeManager.GetTypeArguments (target_type) [0];
e = ExplicitConversionCore (ec, expr, target, loc);
if (e != null)
return TypeSpec.IsReferenceType (expr.Type) ? new UnboxCast (expr, target_type) : Nullable.Wrap.Create (e, target_type);
} else if (expr_type.IsNullableType) {
e = ImplicitBoxingConversion (expr, Nullable.NullableInfo.GetUnderlyingType (expr_type), target_type);
if (e != null)
return e;
e = Nullable.Unwrap.Create (expr, false);
e = ExplicitConversionCore (ec, e, target_type, loc);
if (e != null)
return EmptyCast.Create (e, target_type);
}
e = ExplicitUserConversion (ec, expr, target_type, loc);
if (e != null)
return e;
expr.Error_ValueCannotBeConverted (ec, target_type, true);
return null;
}
示例6: Const
public Const (DeclSpace parent, FullNamedExpression type, string name,
Expression expr, int mod_flags, Attributes attrs, Location loc)
: base (parent, type, mod_flags, AllowedModifiers,
new MemberName (name, loc), attrs)
{
initializer = expr;
ModFlags |= Modifiers.STATIC;
}
示例7: EnumMember
public EnumMember (Enum parent, EnumMember prev_member, string name, Expression expr,
Attributes attrs, Location loc)
: base (parent, new EnumTypeExpr (parent), name, expr, Modifiers.PUBLIC,
attrs, loc)
{
this.ParentEnum = parent;
this.ValueExpr = expr;
this.prev_member = prev_member;
}
示例8: ExplicitConversion
/// <summary>
/// Performs an explicit conversion of the expression `expr' whose
/// type is expr.Type to `target_type'.
/// </summary>
public static Expression ExplicitConversion(ResolveContext ec, Expression expr,
TypeSpec target_type, Location loc)
{
Expression e = ExplicitConversionCore (ec, expr, target_type, loc);
if (e != null) {
//
// Don't eliminate explicit precission casts
//
if (e == expr) {
if (target_type == TypeManager.float_type)
return new OpcodeCast (expr, target_type, OpCodes.Conv_R4);
if (target_type == TypeManager.double_type)
return new OpcodeCast (expr, target_type, OpCodes.Conv_R8);
}
return e;
}
TypeSpec expr_type = expr.Type;
if (TypeManager.IsNullableType (target_type)) {
if (TypeManager.IsNullableType (expr_type)) {
TypeSpec target = Nullable.NullableInfo.GetUnderlyingType (target_type);
Expression unwrap = Nullable.Unwrap.Create (expr);
e = ExplicitConversion (ec, unwrap, target, expr.Location);
if (e == null)
return null;
return new Nullable.Lifted (e, unwrap, target_type).Resolve (ec);
} else if (expr_type == TypeManager.object_type) {
return new UnboxCast (expr, target_type);
} else {
TypeSpec target = TypeManager.GetTypeArguments (target_type) [0];
e = ExplicitConversionCore (ec, expr, target, loc);
if (e != null)
return Nullable.Wrap.Create (e, target_type);
}
} else if (TypeManager.IsNullableType (expr_type)) {
bool use_class_cast;
if (ImplicitBoxingConversionExists (Nullable.NullableInfo.GetUnderlyingType (expr_type), target_type, out use_class_cast))
return new BoxedCast (expr, target_type);
e = Nullable.Unwrap.Create (expr, false);
e = ExplicitConversionCore (ec, e, target_type, loc);
if (e != null)
return EmptyCast.Create (e, target_type);
}
e = ExplicitUserConversion (ec, expr, target_type, loc);
if (e != null)
return e;
expr.Error_ValueCannotBeConverted (ec, loc, target_type, true);
return null;
}
示例9: Const
public Const(DeclSpace parent, FullNamedExpression type, string name,
Expression expr, Modifiers mod_flags, Attributes attrs, Location loc)
: base(parent, type, mod_flags, AllowedModifiers,
new MemberName (name, loc), attrs)
{
if (expr != null)
initializer = new ConstInitializer (this, expr);
ModFlags |= Modifiers.STATIC;
}
示例10: MakeSimpleCall
static public Expression MakeSimpleCall (EmitContext ec, MethodGroupExpr mg,
Expression e, Location loc)
{
ArrayList args;
MethodBase method;
args = new ArrayList (1);
args.Add (new Argument (e, Argument.AType.Expression));
method = Invocation.OverloadResolve (ec, (MethodGroupExpr) mg, args, loc);
if (method == null)
return null;
return new StaticCallExpr ((MethodInfo) method, args, loc);
}
示例11: CreateFromExpression
CodeAction CreateFromExpression(RefactoringContext context, Expression expression)
{
var resolveResult = context.Resolve(expression);
if (resolveResult.IsError)
return null;
return new CodeAction(context.TranslateString("Extract method"), script => {
string methodName = "NewMethod";
var method = new MethodDeclaration {
ReturnType = context.CreateShortType(resolveResult.Type),
Name = methodName,
Body = new BlockStatement {
new ReturnStatement(expression.Clone())
}
};
if (!StaticVisitor.UsesNotStaticMember(context, expression))
method.Modifiers |= Modifiers.Static;
var usedVariables = VariableLookupVisitor.Analyze(context, expression);
var inExtractedRegion = new VariableUsageAnalyzation (context, usedVariables);
usedVariables.Sort ((l, r) => l.Region.Begin.CompareTo (r.Region.Begin));
var target = new IdentifierExpression(methodName);
var invocation = new InvocationExpression(target);
foreach (var variable in usedVariables) {
Expression argumentExpression = new IdentifierExpression(variable.Name);
var mod = ParameterModifier.None;
if (inExtractedRegion.GetStatus (variable) == VariableState.Changed) {
mod = ParameterModifier.Ref;
argumentExpression = new DirectionExpression(FieldDirection.Ref, argumentExpression);
}
method.Parameters.Add(new ParameterDeclaration(context.CreateShortType(variable.Type), variable.Name, mod));
invocation.Arguments.Add(argumentExpression);
}
script
.InsertWithCursor(context.TranslateString("Extract method"), Script.InsertPosition.Before, method)
.ContinueScript (delegate {
script.Replace(expression, invocation);
script.Link(target, method.NameToken);
});
}, expression);
}
示例12: OptionalAssign
public OptionalAssign (Expression t, Expression s, Location loc)
: base (t, s, loc)
{
}
示例13: OptionalAssign
public OptionalAssign (Expression s, Location loc)
: base (null, s, loc)
{
}
示例14: Visit
public override object Visit (Expression expression)
{
Console.WriteLine ("Visit unknown expression:" + expression);
return null;
}
示例15: HoistedFieldAssign
public HoistedFieldAssign (Expression target, Expression source)
: base (target, source, target.Location)
{
}