コード例 #1
0
ファイル: DynamicSerializer.cs プロジェクト: merlox/roshambo
        private void WritePropertyValues(DataBuffer buff, object inst)
        {
            object[] values = new object[Properties.Length];
            Type[]   types  = new Type[values.Length];
            bool[]   isNull = new bool[values.Length];
            for (int i = 0; i < values.Length; i++)
            {
                values[i] = Properties[i].GetValue(inst);
                types[i]  = Properties[i].PropertyType;
                isNull[i] = values[i] == null;
            }

            var fold = DataHelpers.Fold(isNull);

            for (int i = 0; i < fold.Length; i++)
            {
                buff.Write((byte)fold[i]);
            }

            for (int i = 0; i < values.Length; i++)
            {
                if (values[i] != null)
                {
                    Parent.Write(buff, types[i], values[i]);
                }
            }
        }
コード例 #2
0
ファイル: DynamicSerializer.cs プロジェクト: merlox/roshambo
        private object ReadPropertyValues(DataBuffer buff, object inst)
        {
            if (inst == null)
            {
                if (ActivationFunction == null)
                {
                    inst = Activator.CreateInstance(ModelType);
                }
                else
                {
                    inst = ActivationFunction.Invoke();
                }
            }

            Type[] types = new Type[Properties.Length];
            for (int i = 0; i < Properties.Length; i++)
            {
                types[i] = Properties[i].PropertyType;
            }

            var foldBytes = (Properties.Length + 7) / 8;

            byte[] fold = new byte[foldBytes];
            for (int i = 0; i < fold.Length; i++)
            {
                fold[i] = buff.ReadByte();
            }

            var isNull = DataHelpers.Unfold(fold);

            for (int i = 0; i < Properties.Length; i++)
            {
                if (isNull[i] == false)
                {
                    Properties[i].SetValue(inst, Parent.Read(buff, types[i], Properties[i].GetValue(inst)));
                }
            }

            return(inst);
        }