ICSharpCode.NRefactory.MonoCSharp.Nullable.Wrap.Create C# (CSharp) Method

Create() public static method

public static Create ( Expression expr, TypeSpec type ) : Expression
expr System.Linq.Expressions.Expression
type TypeSpec
return System.Linq.Expressions.Expression
		public static Expression Create (Expression expr, TypeSpec type)
		{
			//
			// Avoid unwraping and wraping of the same type
			//
			Unwrap unwrap = expr as Unwrap;
			if (unwrap != null && expr.Type == NullableInfo.GetUnderlyingType (type))
				return unwrap.Original;
		
			return new Wrap (expr, type);
		}
		

Usage Example

Example #1
0
        protected override Expression DoResolve(ResolveContext ec)
        {
            //
            // It's null when lifting non-nullable type
            //
            if (unwrap == null)
            {
                // S -> T? is wrap only
                if (type.IsNullableType)
                {
                    return(Wrap.Create(expr, type));
                }

                // S -> T can be simplified
                return(expr);
            }

            // Wrap target for T?
            if (type.IsNullableType)
            {
                if (!expr.Type.IsNullableType)
                {
                    expr = Wrap.Create(expr, type);
                    if (expr == null)
                    {
                        return(null);
                    }
                }

                null_value = LiftedNull.Create(type, loc);
            }
            else if (TypeSpec.IsValueType(type))
            {
                null_value = LiftedNull.Create(type, loc);
            }
            else
            {
                null_value = new NullConstant(type, loc);
            }

            eclass = ExprClass.Value;
            return(this);
        }
All Usage Examples Of ICSharpCode.NRefactory.MonoCSharp.Nullable.Wrap::Create