本文整理汇总了C#中Mono.CSharp.Expression类的典型用法代码示例。如果您正苦于以下问题:C# Expression类的具体用法?C# Expression怎么用?C# Expression使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Expression类属于Mono.CSharp命名空间,在下文中一共展示了Expression类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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;
}
开发者ID:bbqchickenrobot,项目名称:playscript-mono,代码行数:7,代码来源:CSharpBinder.cs
示例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;
}
开发者ID:nberardi,项目名称:mono,代码行数:60,代码来源:convert.cs
示例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);
}
开发者ID:bbqchickenrobot,项目名称:playscript-mono,代码行数:29,代码来源:CSharpBinder.cs
示例4: Argument
public Argument (Expression expr)
{
if (expr == null)
throw new ArgumentNullException ();
this.Expr = expr;
}
开发者ID:pgoron,项目名称:monodevelop,代码行数:7,代码来源:argument.cs
示例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;
}
开发者ID:exodrifter,项目名称:mcs-ICodeCompiler,代码行数:63,代码来源:convert.cs
示例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;
}
开发者ID:lewurm,项目名称:benchmarker,代码行数:8,代码来源:const.cs
示例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;
}
开发者ID:calumjiao,项目名称:Mono-Class-Libraries,代码行数:9,代码来源:enum.cs
示例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;
}
开发者ID:speier,项目名称:shake,代码行数:60,代码来源:convert.cs
示例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;
}
开发者ID:speier,项目名称:shake,代码行数:10,代码来源:const.cs
示例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);
}
开发者ID:emtees,项目名称:old-code,代码行数:15,代码来源:expression.cs
示例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);
}
开发者ID:0xb1dd1e,项目名称:NRefactory,代码行数:46,代码来源:ExtractMethodAction.cs
示例12: OptionalAssign
public OptionalAssign (Expression t, Expression s, Location loc)
: base (t, s, loc)
{
}
开发者ID:KAW0,项目名称:Alter-Native,代码行数:4,代码来源:eval.cs
示例13: OptionalAssign
public OptionalAssign (Expression s, Location loc)
: base (null, s, loc)
{
}
开发者ID:FrancisVarga,项目名称:mono,代码行数:4,代码来源:eval.cs
示例14: Visit
public override object Visit (Expression expression)
{
Console.WriteLine ("Visit unknown expression:" + expression);
return null;
}
开发者ID:pgoron,项目名称:monodevelop,代码行数:5,代码来源:CSharpParser.cs
示例15: HoistedFieldAssign
public HoistedFieldAssign (Expression target, Expression source)
: base (target, source, target.Location)
{
}
开发者ID:rabink,项目名称:mono,代码行数:4,代码来源:anonymous.cs
示例16: EmitStoreyInstantiation
//
// Initializes all hoisted variables
//
public void EmitStoreyInstantiation (EmitContext ec, ExplicitBlock block)
{
// There can be only one instance variable for each storey type
if (Instance != null)
throw new InternalErrorException ();
//
// Create an instance of this storey
//
ResolveContext rc = new ResolveContext (ec.MemberContext);
rc.CurrentBlock = block;
var storey_type_expr = CreateStoreyTypeExpression (ec);
var source = new New (storey_type_expr, null, Location).Resolve (rc);
//
// When the current context is async (or iterator) lift local storey
// instantiation to the currect storey
//
if (ec.CurrentAnonymousMethod is StateMachineInitializer && (block.HasYield || block.HasAwait)) {
//
// Unfortunately, normal capture mechanism could not be used because we are
// too late in the pipeline and standart assign cannot be used either due to
// recursive nature of GetStoreyInstanceExpression
//
var field = ec.CurrentAnonymousMethod.Storey.AddCompilerGeneratedField (
LocalVariable.GetCompilerGeneratedName (block), storey_type_expr, true);
field.Define ();
field.Emit ();
var fexpr = new FieldExpr (field, Location);
fexpr.InstanceExpression = new CompilerGeneratedThis (ec.CurrentType, Location);
fexpr.EmitAssign (ec, source, false, false);
Instance = fexpr;
} else {
var local = TemporaryVariableReference.Create (source.Type, block, Location);
if (source.Type.IsStruct) {
local.LocalInfo.CreateBuilder (ec);
} else {
local.EmitAssign (ec, source);
}
Instance = local;
}
EmitHoistedFieldsInitialization (rc, ec);
// TODO: Implement properly
//SymbolWriter.DefineScopeVariable (ID, Instance.Builder);
}
开发者ID:rabink,项目名称:mono,代码行数:54,代码来源:anonymous.cs
示例17: ContextualReturn
public ContextualReturn (Expression expr)
: base (expr, expr.StartLocation)
{
}
开发者ID:0xb1dd1e,项目名称:NRefactory,代码行数:4,代码来源:lambda.cs
示例18: CloneTo
protected override void CloneTo (CloneContext clonectx, Expression target)
{
throw new NotSupportedException ("should not be reached");
}
开发者ID:rabink,项目名称:mono,代码行数:4,代码来源:constant.cs
示例19: FieldDeclarator
public FieldDeclarator (SimpleMemberName name, Expression initializer)
{
this.Name = name;
this.Initializer = initializer;
}
开发者ID:agallero,项目名称:mono,代码行数:5,代码来源:field.cs
示例20: SideEffectConstant
public SideEffectConstant (Constant value, Expression side_effect, Location loc)
: base (loc)
{
this.value = value;
type = value.Type;
eclass = ExprClass.Value;
while (side_effect is SideEffectConstant)
side_effect = ((SideEffectConstant) side_effect).side_effect;
this.side_effect = side_effect;
}
开发者ID:rabink,项目名称:mono,代码行数:11,代码来源:constant.cs
注:本文中的Mono.CSharp.Expression类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论