示例#1
0
        /// <summary>
        /// Constructor for the NetworkingStream with a passed in stream
        /// </summary>
        /// <param name="stream">The stream passed in to be used</param>
        public NetworkingStreamRPC(NetworkingStream stream, bool skipCall = false)
        {
            FailedExecution = false;

            // TODO:  Check for null NetworkedBehavior or if it is the base class
            if (!skipCall && ReferenceEquals(stream.NetworkedBehavior, null))
            {
                return;
            }

#if NETFX_CORE
            IEnumerable <PropertyInfo> properties = stream.GetType().GetRuntimeProperties();
#else
            PropertyInfo[] properties = stream.GetType().GetProperties(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);
#endif
            foreach (PropertyInfo property in properties)
            {
                if (property.CanRead && property.CanWrite)
                {
                    property.SetValue(this, property.GetValue(stream, null), null);
                }
            }

            if (!skipCall)
            {
                FailedExecution = !NetworkedBehavior.InvokeRPC(this);
            }
            else
            {
                Bytes = new BMSByte().Clone(stream.Bytes);
            }
        }
        /// <summary>
        /// Constructor for the NetworkingStream with a passed in stream
        /// </summary>
        /// <param name="stream">The stream passed in to be used</param>
        public NetworkingStreamRPC(NetworkingStream stream, bool skipCall = false)
        {
            FailedExecution = false;

            // TODO:  Check for null NetworkedBehavior or if it is the base class
            if (!skipCall && ReferenceEquals(stream.NetworkedBehavior, null))
            {
                return;
            }

#if NETFX_CORE
            var properties = stream.GetType().GetRuntimeProperties();
#else
            var properties = stream.GetType().GetProperties(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);
#endif
            foreach (PropertyInfo property in properties)
            {
                //if (property.PropertyType == typeof(BMSByte))
                //	continue;

                if (property.CanRead && property.CanWrite)
                {
                    property.SetValue(this, property.GetValue(stream, null), null);
                }
            }

            if (!skipCall)
            {
                FailedExecution = !NetworkedBehavior.InvokeRPC(this);
            }
            else
            {
                Bytes = new BMSByte().Clone(stream.Bytes.byteArr, stream.Bytes.byteArr.Length - 1);
                Bytes.MoveStartIndex(stream.Bytes.StartIndex());
                Bytes.SetSize(stream.Bytes.Size);
            }
        }