Example #1
0
        public virtual string GenerateGetSizeOf(string indent)
        {
            string       cstype     = SymbolTable.Table.GetCSType(CType, true);
            string       res        = "";
            IGeneratable gen        = SymbolTable.Table[CType];
            var          is_pointer = false;

            if (IsCPointer())
            {
                is_pointer = true;
                cstype     = "IntPtr";
            }
            else if (gen != null)
            {
                res = gen.GenerateGetSizeOf();
            }

            if (res != null && res != "")
            {
                if (IsFixedSizeArray())
                {
                    res += " * " + ArrayLength;
                }

                return(indent + res);
            }

            var _enum = gen as EnumGen;

            if (_enum != null && !is_pointer)
            {
                res = "(uint) Marshal.SizeOf(System.Enum.GetUnderlyingType(typeof(" + cstype + ")))";
            }
            else
            {
                res = "(uint) Marshal.SizeOf(typeof(" + cstype + "))";
            }

            if (IsFixedSizeArray())
            {
                res += " * " + ArrayLength;
            }

            return(res);
        }