Ejemplo n.º 1
0
        public void OnBeforeSerialize()
        {
            var container = new PropertyDataContainer();

            foreach (var property in GetType().GetProperties())
            {
                foreach (var attribute in property.GetCustomAttributes(true))
                {
                    if (attribute is Config)
                    {
                        switch (property.PropertyType.Name)
                        {
                        case "Int32":
                            container.intDict.Add(property.Name, (int)property.GetValue(this, null));
                            break;

                        case "Single":
                            container.floatDict.Add(property.Name, (float)property.GetValue(this, null));
                            break;

                        case "String":
                            container.stringDict.Add(property.Name, (string)property.GetValue(this, null));
                            break;

                        case "Boolean":
                            container.boolDict.Add(property.Name, (bool)property.GetValue(this, null));
                            break;
                        }
                    }
                }
            }

            //save if there are chanages
            var newBytes = ProtoBufSerializer.SerializeToBytes(container);

            if (dataBytes.Length != newBytes.Length)
            {
                SetBytes(newBytes);
            }
            else
            {
                for (int i = 0; i < dataBytes.Length; i++)
                {
                    if (dataBytes[i] != newBytes[i])
                    {
                        SetBytes(newBytes);
                        return;
                    }
                }
            }
        }
Ejemplo n.º 2
0
 public void OnBeforeSerialize()
 {
     bytes = ProtoBufSerializer.SerializeToBytes(logs);
 }