public static VByte Ref(Address addr, string name) { var v = new VByte { Address = new Address[] { addr }, Name = string.IsNullOrEmpty(name) ? addr.ToString() : name }; return(v); }
private StructType _makeCopy(int offset, IndexingRegister?index) { var structType = _baseInstance.GetType(); var newInstance = (Struct?)Activator.CreateInstance(structType); newInstance.Name = _baseInstance.Name; newInstance.Size = _baseInstance.Size; var i = 0; foreach (var p in structType.GetProperties().Where(x => typeof(Var).IsAssignableFrom(x.PropertyType)).ToList()) //user-defined Var properties //if type has >1 bytes, grab values from appropriate arrays, create an instance, and copy over properties { var numBytes = VarSize.GetSizeOf(p.PropertyType); var v = (Var?)Activator.CreateInstance(p.PropertyType); v.Index = index; if (numBytes > 1) { //Make a duplicate list of bytes of item[0], to prepare to copy into the new Struct/Var instance var bytes = new List <Var>(); for (var byteIndex = 0; byteIndex < numBytes; byteIndex++) { //Additional duplication here to set Index properties var newB = new VByte(); newB.Copy(_arrays[i][offset]); newB.Index = index; bytes.Add(newB); i++; } i--; v.Copy(bytes); //Move the bytes into the struct/var } else if (numBytes == 1) { v.Copy(_arrays[i][offset]); } v.Index = index; structType.InvokeMember(p.Name, BindingFlags.SetProperty | BindingFlags.Instance | BindingFlags.Public, null, newInstance, new object[] { v }); i++; } newInstance.Index = index; return((StructType)newInstance); }