public void LittleEndian( Type type, object expectedValue, int alignment, byte[] bigEndianData, byte[] littleEndianData, IEqualityComparer <object> returnComparer) { // via Delegate { MessageReader reader = CreateMessageReader(EndianFlag.Little, littleEndianData); var method = s_createReadDelegateMethod.MakeGenericMethod(type); var readMethodDelegate = (Delegate)method.Invoke(null, null); var readValue = readMethodDelegate.DynamicInvoke(new object[] { reader }); Assert.IsAssignableFrom(type, readValue); if (returnComparer != null) { Assert.Equal(expectedValue, readValue, returnComparer); } else { Assert.Equal(expectedValue, readValue); } } // via ReadMethod { if (type.GetTypeInfo().IsEnum) { // TODO return; } MessageReader reader = CreateMessageReader(EndianFlag.Little, littleEndianData); var ReadMethodInfo = ReadMethodFactory.CreateReadMethodForType(type); object readValue; if (ReadMethodInfo.IsStatic) { readValue = ReadMethodInfo.Invoke(null, new object[] { reader }); } else { readValue = ReadMethodInfo.Invoke(reader, null); } Assert.IsAssignableFrom(type, readValue); if (returnComparer != null) { Assert.Equal(expectedValue, readValue, returnComparer); } else { Assert.Equal(expectedValue, readValue); } } }
public void Invalid(Type type) { var method = s_createReadDelegateMethod.MakeGenericMethod(type); Exception exception = null; try { method.Invoke(null, null); } catch (TargetInvocationException tie) { exception = tie.InnerException; } Assert.IsAssignableFrom <ArgumentException>(exception); Assert.Throws <ArgumentException>(() => ReadMethodFactory.CreateReadMethodForType(type)); }
public object Read(Type type) { if (type.GetTypeInfo().IsEnum) { var value = Read(Enum.GetUnderlyingType(type)); return(Enum.ToObject(type, value)); } if (type == typeof(bool)) { return(ReadBoolean()); } else if (type == typeof(byte)) { return(ReadByte()); } else if (type == typeof(double)) { return(ReadDouble()); } else if (type == typeof(short)) { return(ReadInt16()); } else if (type == typeof(int)) { return(ReadInt32()); } else if (type == typeof(long)) { return(ReadInt64()); } else if (type == typeof(ObjectPath)) { return(ReadObjectPath()); } else if (type == typeof(Signature)) { return(ReadSignature()); } else if (type == typeof(string)) { return(ReadString()); } else if (type == typeof(float)) { return(ReadSingle()); } else if (type == typeof(ushort)) { return(ReadUInt16()); } else if (type == typeof(uint)) { return(ReadUInt32()); } else if (type == typeof(ulong)) { return(ReadUInt64()); } else if (type == typeof(object)) { return(ReadVariant()); } else if (type == typeof(IDBusObject)) { return(ReadBusObject()); } var method = ReadMethodFactory.CreateReadMethodForType(type); if (method.IsStatic) { return(method.Invoke(null, new object[] { this })); } else { return(method.Invoke(this, null)); } }