Пример #1
0
        public static T Clone <T>(this T serializable, ConsensusFactory consensusFactory) where T : IBitcoinSerializable, new()
        {
            T instance = consensusFactory.TryCreateNew <T>();

            if (instance == null)
            {
                instance = new T();
            }

            instance.FromBytes(serializable.ToBytes(consensusFactory), consensusFactory);
            return(instance);
        }
Пример #2
0
        public void ReadWrite <T>(ref T data) where T : IBitcoinSerializable
        {
            var obj = data;

            if (obj == null)
            {
                if (!ConsensusFactory.TryCreateNew <T>(out obj))
                {
                    obj = Activator.CreateInstance <T>();
                }
            }
            obj.ReadWrite(this);
            if (!Serializing)
            {
                data = obj;
            }
        }