Exemplo n.º 1
0
        public string Info()
        {
            StringBuilder sb = new StringBuilder();

            for (int index = 0; index < _fields.Count; index++)
            {
                FIELD f = _fields.Find(x => x.index == index);
                if (f != null)
                {
                    sb.Append(string.Format("{0:0000} - {1,-10} : ", f.offset, f.name));
                    string temp = f.type.ToString();
                    if (f.count > 1)
                    {
                        temp += string.Format("[{0}]", f.count);
                    }
                    sb.Append(string.Format("{0,-12} : ", temp));
                    string value = "";
                    switch (f.type)
                    {
                    case TYPE.BOOL:
                        for (int i = 0; i < f.count; i++)
                        {
                            value += f.GetBool(i).ToString() + " ";
                        }
                        break;

                    case TYPE.CHAR:
                        value = f.GetString();
                        break;

                    case TYPE.BYTE:
                        for (int i = 0; i < f.count; i++)
                        {
                            value += string.Format("0x{0:X2} ", f.GetNumeric <byte>(i));
                        }
                        break;

                    case TYPE.UINT64:
                        for (int i = 0; i < f.count; i++)
                        {
                            value += f.GetNumeric <UInt64>(i).ToString() + " ";
                        }
                        break;

                    case TYPE.UINT8:
                    case TYPE.UINT16:
                    case TYPE.UINT32:
                    case TYPE.INT8:
                    case TYPE.INT16:
                    case TYPE.INT32:
                    case TYPE.INT64:
                        for (int i = 0; i < f.count; i++)
                        {
                            value += f.GetNumeric <Int64>(i).ToString() + " ";
                        }
                        break;

                    default:
                        value = "{unknown}";
                        break;
                    }
                    sb.AppendLine(value);
                }
            }
            return(sb.ToString());
        }
Exemplo n.º 2
0
        public T GetNumeric <T>(string name, int index = 0)
        {
            FIELD f = GetField(name);

            return(f.GetNumeric <T>(index));
        }
Exemplo n.º 3
0
        public bool Copy(STRUCT source, bool allowMissing)
        {
            Clear();
            bool success = true;

            foreach (FIELD f in _fields)
            {
                if (f.name != "")
                {
                    if (source.Exists(f.name))
                    {
                        FIELD fs = source.GetField(f.name);
                        if ((f.type == TYPE.CHAR) && (fs.type == TYPE.CHAR))
                        {
                            f.SetString(fs.GetString());
                        }
                        else if (((f.type == TYPE.BOOL) && (fs.type == TYPE.BOOL)) ||
                                 (f.IsNumeric() && fs.IsNumeric()))
                        {
                            try
                            {
                                int maxCount = Math.Min(f.count, fs.count);
                                for (int i = 0; i < maxCount; i++)
                                {
                                    if (f.type == TYPE.BOOL)
                                    {
                                        f.SetBool(fs.GetBool(i), i);
                                    }
                                    else if (fs.type == TYPE.UINT64)
                                    {
                                        // have to use UInt64 to handle UINT64, otherwise can use INT64 for all other cases
                                        f.SetNumeric(fs.GetNumeric <UInt64>(i), i);
                                    }
                                    else
                                    {
                                        f.SetNumeric(fs.GetNumeric <Int64>(i), i);
                                    }
                                }
                            } catch (Exception)
                            {
                                success = false;
                                break;
                            }
                        }
                        else
                        {
                            success = false;
                            break;
                        }
                    }
                    else
                    {
                        if (!allowMissing)
                        {
                            success = false;
                            break;
                        }
                    }
                }
            }
            if (!success)
            {
                Clear();
            }
            return(success);
        }