ICSharpCode.NRefactory.MonoCSharp.Nullable.NullableInfo.GetGetValueOrDefault C# (CSharp) Method

GetGetValueOrDefault() public static method

public static GetGetValueOrDefault ( TypeSpec nullableType ) : MethodSpec
nullableType TypeSpec
return MethodSpec
		public static MethodSpec GetGetValueOrDefault (TypeSpec nullableType)
		{
			return (MethodSpec) MemberCache.FindMember (nullableType,
				MemberFilter.Method ("GetValueOrDefault", 0, ParametersCompiled.EmptyReadOnlyParameters, null), BindingRestriction.None);
		}

Usage Example

Example #1
0
        protected override void EmitOperation(EmitContext ec)
        {
            Label is_null_label = ec.DefineLabel();
            Label end_label     = ec.DefineLabel();

            LocalTemporary lt = new LocalTemporary(type);

            // Value is on the stack
            lt.Store(ec);

            var call = new CallEmitter();

            call.InstanceExpression = lt;
            call.EmitPredefined(ec, NullableInfo.GetHasValue(expr.Type), null);

            ec.Emit(OpCodes.Brfalse, is_null_label);

            call = new CallEmitter();
            call.InstanceExpression = lt;
            call.EmitPredefined(ec, NullableInfo.GetGetValueOrDefault(expr.Type), null);

            lt.Release(ec);

            base.EmitOperation(ec);

            ec.Emit(OpCodes.Newobj, NullableInfo.GetConstructor(type));
            ec.Emit(OpCodes.Br_S, end_label);

            ec.MarkLabel(is_null_label);
            LiftedNull.Create(type, loc).Emit(ec);

            ec.MarkLabel(end_label);
        }
All Usage Examples Of ICSharpCode.NRefactory.MonoCSharp.Nullable.NullableInfo::GetGetValueOrDefault