public void WriteFieldValue(BinaryWriter f, Definition item, String FName)
        {
            try
            {
                FieldInfo FType = MainForm.Instance.DatInfo.getDefinition().GetType().GetField(FName);
                Object    obj   = FType.GetValue(item);
                if (obj is IType)
                {
                    var type = (IType)obj;

                    type.write(f);
                }
                else
                {
                    throw new NotImplementedException("Format " + obj.GetType().Name + " is not implement IType");
                }
            }
            catch (Exception ex)
            {
                item.DumpFieldValues();
                ex = new ApplicationException(
                    String.Format("Error compiling string file (FieldName: {0} RecordOffset: 0x{1:X})",
                                  FName, f.BaseStream.Position), ex);
            }
        }
        public Definition ReadFieldValue(BinaryReader f, Definition info, String FName)
        {
            Definition TmpInfo = info;
            long       curPos  = f.BaseStream.Position;

            try
            {
                FieldInfo FType = MainForm.Instance.DatInfo.getDefinition().GetType().GetField(FName);

                Type field = FType.FieldType;

                if (FType.GetValue(info) == null)
                {
                    Object obj = field.InvokeMember(null, BindingFlags.CreateInstance, null, null, null);

                    if (obj is IType)
                    {
                        var type = (IType)obj;
                        FType.SetValue(info, type.read(f));
                    }
                    else
                    {
                        throw new NotImplementedException("Format " + obj.GetType().Name + " is not implement IType");
                    }
                }
                else
                {
                    FType.SetValue(info, ((IType)FType.GetValue(info)).read(f));
                }
            }
            catch (Exception ex)
            {
                TmpInfo.DumpFieldValues();
                ex = new ApplicationException(
                    String.Format("Error parsing string file (FieldName: {0} RecordOffset: 0x{1:X} DumpData: {2})",
                                  FName, f.BaseStream.Position, DatTool.Debug_DumpString(f, curPos, 8)), ex);
            }
            return(info);
        }
Exemple #3
0
        public void WriteFieldValue(BinaryWriter f, Definition item, String FName)
        {
            try
            {
                FieldInfo FType = MainForm.Instance.DatInfo.getDefinition().GetType().GetField(FName);
                Object obj = FType.GetValue(item);
                if (obj is IType)
                {
                    var type = (IType) obj;

                    type.write(f);
                }
                else
                {
                    throw new NotImplementedException("Format " + obj.GetType().Name + " is not implement IType");
                }
            }
            catch (Exception ex)
            {
                item.DumpFieldValues();
                ex = new ApplicationException(
                    String.Format("Error compiling string file (FieldName: {0} RecordOffset: 0x{1:X})",
                                  FName, f.BaseStream.Position), ex);
            }
        }