private static void IncrementVersion(Type memberType, ref Primitive version) { if (memberType.IsAssignableFrom(typeof(Byte))) { version = version.AsByte() + 1; } else if (memberType.IsAssignableFrom(typeof(SByte))) { version = version.AsSByte() + 1; } else if (memberType.IsAssignableFrom(typeof(int))) { version = version.AsInt() + 1; } else if (memberType.IsAssignableFrom(typeof(uint))) { version = version.AsUInt() + 1; } else if (memberType.IsAssignableFrom(typeof(long))) { version = version.AsLong() + 1; } else if (memberType.IsAssignableFrom(typeof(ulong))) { version = version.AsULong() + 1; } else if (memberType.IsAssignableFrom(typeof(short))) { version = version.AsShort() + 1; } else if (memberType.IsAssignableFrom(typeof(ushort))) { version = version.AsUShort() + 1; } }
private static void IncrementVersion(Type memberType, ref Primitive version) { var memberTypeWrapper = TypeFactory.GetTypeInfo(memberType); if (memberTypeWrapper.IsAssignableFrom(TypeFactory.GetTypeInfo(typeof(Byte)))) { version = version.AsByte() + 1; } else if (memberTypeWrapper.IsAssignableFrom(TypeFactory.GetTypeInfo(typeof(SByte)))) { version = version.AsSByte() + 1; } else if (memberTypeWrapper.IsAssignableFrom(TypeFactory.GetTypeInfo(typeof(int)))) { version = version.AsInt() + 1; } else if (memberTypeWrapper.IsAssignableFrom(TypeFactory.GetTypeInfo(typeof(uint)))) { version = version.AsUInt() + 1; } else if (memberTypeWrapper.IsAssignableFrom(TypeFactory.GetTypeInfo(typeof(long)))) { version = version.AsLong() + 1; } else if (memberTypeWrapper.IsAssignableFrom(TypeFactory.GetTypeInfo(typeof(ulong)))) { version = version.AsULong() + 1; } else if (memberTypeWrapper.IsAssignableFrom(TypeFactory.GetTypeInfo(typeof(short)))) { version = version.AsShort() + 1; } else if (memberTypeWrapper.IsAssignableFrom(TypeFactory.GetTypeInfo(typeof(ushort)))) { version = version.AsUShort() + 1; } }
// Primitive <--> Value type private static bool TryFromPrimitive(Type targetType, Primitive value, out object output) { if (value.Value == null) { output = null; return(true); } if (targetType.IsAssignableFrom(typeof(Boolean))) { output = value.AsBoolean(); } else if (targetType.IsAssignableFrom(typeof(Byte))) { output = value.AsByte(); } else if (targetType.IsAssignableFrom(typeof(Char))) { output = value.AsChar(); } else if (targetType.IsAssignableFrom(typeof(DateTime))) { output = value.AsDateTime(); } else if (targetType.IsAssignableFrom(typeof(Decimal))) { output = value.AsDecimal(); } else if (targetType.IsAssignableFrom(typeof(Double))) { output = value.AsDouble(); } else if (targetType.IsAssignableFrom(typeof(int))) { output = value.AsInt(); } else if (targetType.IsAssignableFrom(typeof(long))) { output = value.AsLong(); } else if (targetType.IsAssignableFrom(typeof(SByte))) { output = value.AsSByte(); } else if (targetType.IsAssignableFrom(typeof(short))) { output = value.AsShort(); } else if (targetType.IsAssignableFrom(typeof(Single))) { output = value.AsSingle(); } else if (targetType.IsAssignableFrom(typeof(String))) { output = value.AsString(); } else if (targetType.IsAssignableFrom(typeof(uint))) { output = value.AsUInt(); } else if (targetType.IsAssignableFrom(typeof(ulong))) { output = value.AsULong(); } else if (targetType.IsAssignableFrom(typeof(ushort))) { output = value.AsUShort(); } else if (targetType.IsAssignableFrom(typeof(Guid))) { output = value.AsGuid(); } else if (targetType.IsAssignableFrom(typeof(byte[]))) { output = value.AsByteArray(); } else if (targetType.IsAssignableFrom(typeof(MemoryStream))) { output = value.AsMemoryStream(); } else { output = null; return(false); } return(true); }
// Primitive <--> Value type private static bool TryFromPrimitive(Type targetType, Primitive value, out object output) { if (value.Value == null) { output = null; return(true); } try { var targetTypeWrapper = TypeFactory.GetTypeInfo(targetType); if (targetTypeWrapper.IsAssignableFrom(TypeFactory.GetTypeInfo(typeof(Boolean)))) { output = value.AsBoolean(); } else if (targetTypeWrapper.IsAssignableFrom(TypeFactory.GetTypeInfo(typeof(Byte)))) { output = value.AsByte(); } else if (targetTypeWrapper.IsAssignableFrom(TypeFactory.GetTypeInfo(typeof(Char)))) { output = value.AsChar(); } else if (targetTypeWrapper.IsAssignableFrom(TypeFactory.GetTypeInfo(typeof(DateTime)))) { output = value.AsDateTime(); } else if (targetTypeWrapper.IsAssignableFrom(TypeFactory.GetTypeInfo(typeof(Decimal)))) { output = value.AsDecimal(); } else if (targetTypeWrapper.IsAssignableFrom(TypeFactory.GetTypeInfo(typeof(Double)))) { output = value.AsDouble(); } else if (targetTypeWrapper.IsAssignableFrom(TypeFactory.GetTypeInfo(typeof(int)))) { output = value.AsInt(); } else if (targetTypeWrapper.IsAssignableFrom(TypeFactory.GetTypeInfo(typeof(long)))) { output = value.AsLong(); } else if (targetTypeWrapper.IsAssignableFrom(TypeFactory.GetTypeInfo(typeof(SByte)))) { output = value.AsSByte(); } else if (targetTypeWrapper.IsAssignableFrom(TypeFactory.GetTypeInfo(typeof(short)))) { output = value.AsShort(); } else if (targetTypeWrapper.IsAssignableFrom(TypeFactory.GetTypeInfo(typeof(Single)))) { output = value.AsSingle(); } else if (targetTypeWrapper.IsAssignableFrom(TypeFactory.GetTypeInfo(typeof(String)))) { output = value.AsString(); } else if (targetTypeWrapper.IsAssignableFrom(TypeFactory.GetTypeInfo(typeof(uint)))) { output = value.AsUInt(); } else if (targetTypeWrapper.IsAssignableFrom(TypeFactory.GetTypeInfo(typeof(ulong)))) { output = value.AsULong(); } else if (targetTypeWrapper.IsAssignableFrom(TypeFactory.GetTypeInfo(typeof(ushort)))) { output = value.AsUShort(); } else if (targetTypeWrapper.IsAssignableFrom(TypeFactory.GetTypeInfo(typeof(Guid)))) { output = value.AsGuid(); } else if (targetTypeWrapper.IsAssignableFrom(TypeFactory.GetTypeInfo(typeof(byte[])))) { output = value.AsByteArray(); } else if (targetTypeWrapper.IsAssignableFrom(TypeFactory.GetTypeInfo(typeof(MemoryStream)))) { output = value.AsMemoryStream(); } else { output = null; return(false); } return(true); } catch (InvalidCastException) { throw new InvalidCastException(string.Format(CultureInfo.InvariantCulture, "Unable to cast value [{0}] of type [{1}] to type [{2}]", value.Value, value.Value.GetType().FullName, targetType.FullName)); } }