Ejemplo n.º 1
0
        public static long SizeOf(this FieldInfo field, object value)
        {
            Type type = field.FieldType;

            if (type.IsValueType && type != typeof(DateTime))
            {
                return(Marshal.SizeOf(type));
            }
            else if (type.IsArray)
            {
                IEnumerable array = value as IEnumerable;
                return(array.SizeOf());
            }
            else if (type == typeof(string))
            {
                StringLimitAttribute attribute = field.GetCustomAttribute <StringLimitAttribute>();
                return(attribute.SizeOf());
            }
            else if (type == typeof(DateTime))
            {
                return(4);
            }
            else
            {
                return(0);
            }
        }
Ejemplo n.º 2
0
        public static long SizeOf(this StringLimitAttribute attribute)
        {
            if (attribute == null)
            {
                return(0);
            }

            int charSize = Marshal.SizeOf <char>();
            int length   = attribute.MaxLength;

            long totalSize = charSize * length;

            return(totalSize);
        }