private HumanRepresentation ReadValue() { var typeMapping = new Dictionary <Type, Func <Object> > { { typeof(byte), () => code.CodeBytes[indexInCode] }, { typeof(Int16), () => byteConverter.ToInt16(code.CodeBytes, indexInCode) }, { typeof(Int32), () => byteConverter.ToInt32(code.CodeBytes, indexInCode) }, { typeof(UInt16), () => byteConverter.ToUInt16(code.CodeBytes, indexInCode) }, { typeof(UInt32), () => byteConverter.ToUInt32(code.CodeBytes, indexInCode) }, { typeof(Address), () => { byte[] addressBytes = new byte[4]; addressBytes[0] = 0; addressBytes[1] = (byte)(code.CodeBytes[indexInCode + 1] & 0x0f); addressBytes[2] = code.CodeBytes[indexInCode + 2]; addressBytes[3] = code.CodeBytes[indexInCode + 3]; return(new Address { value = byteConverter.ToUInt32(addressBytes, 0) }); } } }; InternalRepresentation value = default(InternalRepresentation); value = (InternalRepresentation)Convert.ChangeType(typeMapping[typeof(InternalRepresentation)](), typeof(InternalRepresentation)); return(converter.ConvertFromInternal(value)); }
private Address ReadValue() { if (!valueRead) { int foundIndex; Address foundValue = this.searchParameterLocator.Locate <Address>(parameterType, out foundIndex); indexInEcu = foundIndex; byteConverter.CopyBytesGeneric(foundValue, code.CodeBytes, indexInCode); foreach (int branchIndex in branchIndexesInCode) { int calculatedAddress = (foundIndex + Constants.BRANCH_INSTRUCTION_SIZE) - (Constants.INJECT_CODE_ADDRESS + branchIndex); Address branchAddress = new Address(); branchAddress.value = (UInt32)calculatedAddress; byteConverter.CopyBytesGeneric(branchAddress, code.CodeBytes, branchIndex); } valueRead = true; } var typeMapping = new Dictionary <Type, Func <Object> > { { typeof(byte), () => code.CodeBytes[indexInCode] }, { typeof(Int16), () => byteConverter.ToInt16(code.CodeBytes, indexInCode) }, { typeof(Int32), () => byteConverter.ToInt32(code.CodeBytes, indexInCode) }, { typeof(UInt16), () => byteConverter.ToUInt16(code.CodeBytes, indexInCode) }, { typeof(UInt32), () => byteConverter.ToUInt32(code.CodeBytes, indexInCode) }, { typeof(Address), () => { byte[] addressBytes = new byte[4]; addressBytes[0] = 0; addressBytes[1] = (byte)(code.CodeBytes[indexInCode + 1] & 0x0f); addressBytes[2] = code.CodeBytes[indexInCode + 2]; addressBytes[3] = code.CodeBytes[indexInCode + 3]; return(new Address { value = byteConverter.ToUInt32(addressBytes, 0) }); } } }; Address value = default(Address); value = (Address)Convert.ChangeType(typeMapping[typeof(Address)](), typeof(Address)); return(converter.ConvertFromInternal(value)); }
private HumanRepresentation ReadValue() { if (!valueRead) { InternalRepresentation foundValue = this.searchParameterLocator.Locate <InternalRepresentation>(parameterType); //Do we need transformation? if (transformFoundValue != null) { foundValue = transformFoundValue(foundValue); } byteConverter.CopyBytesGeneric(foundValue, code.CodeBytes, indexInCode); valueRead = true; } var typeMapping = new Dictionary <Type, Func <Object> > { { typeof(byte), () => code.CodeBytes[indexInCode] }, { typeof(Int16), () => byteConverter.ToInt16(code.CodeBytes, indexInCode) }, { typeof(Int32), () => byteConverter.ToInt32(code.CodeBytes, indexInCode) }, { typeof(UInt16), () => byteConverter.ToUInt16(code.CodeBytes, indexInCode) }, { typeof(UInt32), () => byteConverter.ToUInt32(code.CodeBytes, indexInCode) }, { typeof(Address), () => { byte[] addressBytes = new byte[4]; addressBytes[0] = 0; addressBytes[1] = (byte)(code.CodeBytes[indexInCode + 1] & 0x0f); addressBytes[2] = code.CodeBytes[indexInCode + 2]; addressBytes[3] = code.CodeBytes[indexInCode + 3]; return(new Address { value = byteConverter.ToUInt32(addressBytes, 0) }); } } }; InternalRepresentation value = default(InternalRepresentation); value = (InternalRepresentation)Convert.ChangeType(typeMapping[typeof(InternalRepresentation)](), typeof(InternalRepresentation)); return(converter.ConvertFromInternal(value)); }