コード例 #1
0
        public uint ExportSize(T srcObj, bool bHavMag)
        {
            if (srcObj == null)
            {
                return(0);
            }
            Type t = srcObj.GetType();

            FieldInfo[] fiarr = t.GetFields();
            if (fiarr == null)
            {
                return(0);
            }
            uint nExportSize = 0;

            if (bHavMag)
            {
                nExportSize += 4;
            }
            CUniStruct <object> pUnkownObj = new CUniStruct <object>();
            uint nCount = (uint)fiarr.GetLength(0);

            for (uint i = 0; i < nCount; i++)
            {
                object poValue = fiarr[i].GetValue(srcObj);
                Type   itt     = fiarr[i].FieldType;
                if ((poValue != null) && ((itt == typeof(UniSZ)) || (itt == typeof(UniDW))))
                {
                    UniVarItem puiValue = (UniVarItem)poValue;
                    if (!puiValue.IsValid())
                    {
                        continue;
                    }
                }
                nExportSize += 4;
                if (poValue == null)
                {
                    continue;
                }
                if (itt == typeof(UniSZ))
                {
                    UniSZ pValue = (UniSZ)poValue;
                    if (!pValue.IsEmpty() && !pValue.IsLock())
                    {
                        nExportSize += pValue.Size();
                    }
                }
                else if (itt == typeof(UniDW))
                {
                    UniDW pValue = (UniDW)poValue;
                    if (!pValue.IsEmpty() && !pValue.IsLock())
                    {
                        nExportSize += 4;
                    }
                }
                else
                {
                    nExportSize -= 4;
                    uint nSize = pUnkownObj.ExportSize(poValue, false);
                    nExportSize += nSize;
                }
            }
            return((uint)nExportSize);
        }
コード例 #2
0
        public uint Export(T srcObj, bool bHavMag, ref byte[] pOut, uint _nIndex)
        {
            if (srcObj == null || pOut == null || pOut.Length < _nIndex + 4)
            {
                return(0);
            }
            Type t = srcObj.GetType();

            FieldInfo[] fiarr = t.GetFields();
            if (fiarr == null)
            {
                return(0);
            }
            uint nIndex = _nIndex;

            if (bHavMag)
            {
                uint2byte((uint)UNISMAG.UNISTRUCT, ref pOut, nIndex); nIndex += 4;
            }
            CUniStruct <object> pUnkownObj = new CUniStruct <object>();
            uint nCount = (uint)fiarr.GetLength(0);

            for (uint i = 0; i < nCount; i++)
            {
                object poValue = fiarr[i].GetValue(srcObj);
                Type   itt     = fiarr[i].FieldType;
                if ((poValue != null) && ((itt == typeof(UniSZ)) || (itt == typeof(UniDW))))
                {
                    UniVarItem puiValue = (UniVarItem)poValue;
                    if (!puiValue.IsValid())
                    {
                        continue;
                    }
                }
                if (itt == typeof(UniSZ))
                {
                    if (pOut.Length < nIndex + 4)
                    {
                        return(0);
                    }
                    if (poValue != null)
                    {
                        UniSZ pValue = (UniSZ)poValue;
                        uint2byte((uint)pValue.m_dwType, ref pOut, nIndex); nIndex += 4;
                        if (!pValue.IsEmpty() && !pValue.IsLock())
                        {
                            if (pOut.Length < nIndex + pValue.Size())
                            {
                                return(0);
                            }
                            Array.Copy(pValue.Get(), 0, pOut, nIndex, pValue.Size());
                            nIndex += pValue.Size();
                        }
                    }
                    else
                    {
                        uint2byte((uint)UTFLAG.DEFUNISZTYPE, ref pOut, nIndex); nIndex += 4;
                    }
                }
                else if (itt == typeof(UniDW))
                {
                    if (pOut.Length < nIndex + 4)
                    {
                        return(0);
                    }
                    if (poValue != null)
                    {
                        UniDW pValue = (UniDW)poValue;
                        uint2byte((uint)pValue.m_dwType, ref pOut, nIndex); nIndex += 4;
                        if (!pValue.IsEmpty() && !pValue.IsLock())
                        {
                            if (pOut.Length < nIndex + 4)
                            {
                                return(0);
                            }
                            uint2byte((uint)pValue.m_dwValue, ref pOut, nIndex); nIndex += 4;
                        }
                    }
                    else
                    {
                        uint2byte((uint)UTFLAG.DEFUNIDWTYPE, ref pOut, nIndex); nIndex += 4;
                    }
                }
                else
                {
                    uint nSize = pUnkownObj.Export(poValue, false, ref pOut, nIndex);
                    nIndex += nSize;
                }
            }
            return(nIndex - _nIndex);
        }