Example #1
0
        public static int CalculateRowByteSize(List <PropertyInfo> infos, List <PropertyInfo> customInfos, List <PropertyInfo> primitiveInfos)
        {
            int total = 0;

            foreach (PropertyInfo info in infos)
            {
                if (customInfos.Contains(info))
                {
                    total += sizeof(int); //foreign key
                }
                else if (info.PropertyType == typeof(Boolean))
                {
                    total += 1; //marshal 4 döndürüyor, yanlışsın marshal.
                    //dosyaya yazarken booleanlar 1 yer kaplıyor.
                }
                else if (info.PropertyType == typeof(String))
                {
                    total += CustomAttr.GetLength(info) + delimiter.Length;
                }
                else if (info.PropertyType.IsGenericType)
                {
                    continue;
                }
                else
                {
                    total += System.Runtime.InteropServices.Marshal.SizeOf(info.PropertyType);
                }
            }
            return(total);
        }
Example #2
0
        /// <summary>
        /// Writes a single property to the file. Used in Add method, iterating through all properties.
        /// </summary>
        /// <param name="bw">BinaryWriter that has been created before</param>
        /// <param name="info">İnfo to be written</param>
        /// <param name="o">The object the info belongs to.</param>
        public static void WriteSingleProperty(BinaryWriter bw, PropertyInfo info, object o)
        {
            object value = o;
            Type   t     = info.PropertyType;

            if (t == typeof(String))
            {
                bw.Write(FillString((String)value, delimiter, CustomAttr.GetLength(info)).ToCharArray());
            }
            else if (t == typeof(bool))
            {
                bw.Write((bool)value);
            }
            else if (t == typeof(int))
            {
                bw.Write((int)value);
            }
            else if (t == typeof(DateTime))
            {
                char[] charArray = ((DateTime)value).ToString().ToCharArray();
                bw.Write(charArray);
            }
            else if (t == typeof(long))
            {
                bw.Write((long)value);
            }
            else if (t == typeof(byte[]))
            {
                bw.Write((byte[])value);
            }
            //else if custom info
        }
Example #3
0
        public static void MakeReferenceNull(Stream mainFile, PropertyInfo info, Type T, Dictionary <int, List <int> > toChange)
        {
            //ToChange:
            //key = silinecek id
            //list int = key'e eskiden referans eden kayıtlar

            BaseClass trash = (BaseClass)Activator.CreateInstance(T);

            int total = 0;

            foreach (PropertyInfo orderedInfo in trash.OrderedInfos()) //sütun kaçıncı pozisyonda bul
            {
                if (orderedInfo.Name.Equals(info.Name))                //yazacağımız sütunu bulduk.
                {
                    break;
                }
                else
                {
                    if (trash.OTORelInfos().Contains(orderedInfo))
                    {
                        total += sizeof(int); //foreign key
                    }
                    else if (orderedInfo.PropertyType == typeof(Boolean))
                    {
                        total += 1; //marshal 4 döndürüyor, yanlışsın marshal.
                                    //dosyaya yazarken booleanlar 1 yer kaplıyor.
                    }
                    else if (orderedInfo.PropertyType == typeof(String))
                    {
                        total += CustomAttr.GetLength(orderedInfo) + delimiter.Length;
                    }
                    else
                    {
                        total += System.Runtime.InteropServices.Marshal.SizeOf(orderedInfo.PropertyType);
                    }
                }
            }
            BinaryWriter bw = new BinaryWriter(mainFile);

            foreach (KeyValuePair <int, List <int> > kp in toChange)
            {
                foreach (int id in kp.Value)
                {
                    bw.BaseStream.Position = (id - 1) * trash.RowSize() + total;
                    bw.Write(-1);
                }
            }
        }