public override object WrapValue(GraphEntityInfo entityInfo, GraphTypeInfo typeInfo, object value, bool isSpecified) { if (typeInfo.TypeRepresentation.IsGenericType(typeof(Optional <>))) { return(Optional.Construct(typeInfo, value, isSpecified)); } return(value); }
public void Can_Construct_WithNull() { var typeResolver = new TypeResolver(); var typeInfo = typeof(Optional <int?>).GetTypeInfo(); var graphTypeInfo = new GraphTypeInfo(typeResolver, typeInfo); var optional = (Optional <int?>)Optional.Construct(graphTypeInfo, null, true); Assert.IsNotNull(optional); Assert.IsNull(optional.Value); }
public void Can_Construct_WithNullable() { int?value = 2; var typeResolver = new TypeResolver(); var typeInfo = typeof(Optional <int?>).GetTypeInfo(); var graphTypeInfo = new GraphTypeInfo(typeResolver, typeInfo); var optional = (Optional <int?>)Optional.Construct(graphTypeInfo, value, true); Assert.IsNotNull(optional); Assert.IsNotNull(optional.Value); Assert.AreEqual(value, optional.Value); }