public static ThrowValueTypeCannotBeNull ( string name, |
||
name | string | The name of the member. |
memberType | The type of the member. | |
declaringType | The type that declares the member. | |
return | void |
public static T ConvertWithEnsuringNotNull <T>(object boxed, string name, Type targetType) { if (typeof(T).GetIsValueType() && boxed == null && Nullable.GetUnderlyingType(typeof(T)) == null) { SerializationExceptions.ThrowValueTypeCannotBeNull(name, typeof(T), targetType); } return(( T )boxed); }
private static void VerifyNilImplication(Type type, IEnumerable <SerializingMember> entries) { foreach (var serializingMember in entries) { if (serializingMember.Contract.NilImplication == NilImplication.Null) { var itemType = serializingMember.Member.GetMemberValueType(); if (itemType != typeof(MessagePackObject) && itemType.GetIsValueType() && Nullable.GetUnderlyingType(itemType) == null) { SerializationExceptions.ThrowValueTypeCannotBeNull(serializingMember.Member.ToString(), itemType, type); } bool isReadOnly; FieldInfo asField; PropertyInfo asProperty; if ((asField = serializingMember.Member as FieldInfo) != null) { isReadOnly = asField.IsInitOnly; } else { asProperty = serializingMember.Member as PropertyInfo; #if DEBUG Contract.Assert(asProperty != null, serializingMember.Member.ToString()); #endif // DEBUG isReadOnly = asProperty.GetSetMethod() == null; } if (isReadOnly) { SerializationExceptions.ThrowNullIsProhibited(serializingMember.Member.ToString()); } } } }