Mono.CSharp.LocalVariable.CreateReferenceExpression C# (CSharp) Method

CreateReferenceExpression() public method

public CreateReferenceExpression ( ResolveContext rc, Mono.CSharp.Location loc ) : Mono.CSharp.Expression
rc ResolveContext
loc Mono.CSharp.Location
return Mono.CSharp.Expression
		public Expression CreateReferenceExpression (ResolveContext rc, Location loc)
		{
			if (IsConstant && const_value != null)
				return Constant.CreateConstantFromValue (Type, const_value.GetValue (), loc).Resolve (rc);

			return new LocalVariableReference (this, loc);
		}

Usage Example

Example #1
0
			protected virtual Statement CreateDisposeCall (BlockContext bc, LocalVariable lv)
			{
				var lvr = lv.CreateReferenceExpression (bc, lv.Location);
				var type = lv.Type;
				var loc = lv.Location;

				if (TypeManager.void_dispose_void == null) {
					TypeManager.void_dispose_void = TypeManager.GetPredefinedMethod (
						TypeManager.idisposable_type, "Dispose", loc, TypeSpec.EmptyTypes);
				}

				var dispose_mg = MethodGroupExpr.CreatePredefined (TypeManager.void_dispose_void, TypeManager.idisposable_type, loc);
				dispose_mg.InstanceExpression = TypeManager.IsNullableType (type) ?
					new Cast (new TypeExpression (TypeManager.idisposable_type, loc), lvr, loc).Resolve (bc) :
					lvr;

				Statement dispose = new StatementExpression (new Invocation (dispose_mg, null));

				// Add conditional call when disposing possible null variable
				if (!type.IsStruct || TypeManager.IsNullableType (type))
					dispose = new If (new Binary (Binary.Operator.Inequality, lvr, new NullLiteral (loc), loc), dispose, loc);

				return dispose;
			}
All Usage Examples Of Mono.CSharp.LocalVariable::CreateReferenceExpression