コード例 #1
0
        private T GetValueInternal <T>(string name, bool serverSide = false)
        {
            if (parameters.ContainsKey(name))
            {
                object value = parameters[name].RawValue;

                if (value == null)
                {
                    return(default(T));
                }
                else if (typeof(T).IsAssignableFrom(value.GetType()))
                {
                    return((T)value);
                }
                else if (Utils.CanChangeType(value, typeof(T)))
                {
                    return((T)Convert.ChangeType(value, typeof(T)));
                }
                else
                {
                    throw new InvalidCastException(string.Format("Cannot cast {0} to {1}", value.GetType().Name, typeof(T).Name));
                }
            }
            else
            {
                parameters.Add(name, StateParameter.Construct(name, default(T), !serverSide));
                return(parameters[name].GetValueInternal <T>());
            }
        }
コード例 #2
0
        internal void InvokeUpdated(StateParameter stateParameter)
        {
            if (stateParameter != null)
            {
                if (!SilentSets && OnStateChanged != null)
                {
                    OnStateChanged(this, stateParameter);
                }

                if (changedEvents.ContainsKey(stateParameter.Name))
                {
                    changedEvents[stateParameter.Name](this, stateParameter);
                }
                else
                {
                    string name = changedEvents.Keys.FirstOrDefault(X => stateParameter.Name.Substring(1, stateParameter.Name.Length - 1) == X);
                    if (name != null)
                    {
                        changedEvents[name](this, stateParameter);
                    }
                }

                Tuple <string, object> key = stateEqualsEvents.Keys.FirstOrDefault(X => X.Item1 == stateParameter.Name);

                if (key != null && stateParameter.RawValue.Equals(key.Item2))
                {
                    stateEqualsEvents[key](this, stateParameter);
                }
            }
        }
コード例 #3
0
        public void Decode(BinaryReader reader)
        {
            var numParams = reader.ReadInt32();

            for (int index = 0; index < numParams; index++)
            {
                StateParameter.Decode(reader, this);
            }
        }
コード例 #4
0
        public StateParameter GetParameter <T>(string name, bool serverSide = false)
        {
            if (!parameters.ContainsKey(name))
            {
                parameters.Add(name, StateParameter.Construct <T>(name, (T)Activator.CreateInstance(typeof(T)), serverSide));
            }

            return(parameters[name]);
        }
コード例 #5
0
 public void UpdateParam(StateParameter parameter)
 {
     if (parameters.ContainsKey(parameter.Name))
     {
         InternalSet(parameter.Name, parameter.RawValue, !parameter.IsSynced);
     }
     else
     {
         parameters.Add(parameter.Name, parameter);
     }
 }
コード例 #6
0
        private void InternalSet <T>(string name, T value, bool serverSide)
        {
            if (!parameters.ContainsKey(name))
            {
                parameters.Add(name, StateParameter.Construct(name, value, !serverSide));
            }
            else
            {
                parameters[name].SetValueInternal(value);
            }

            InvokeUpdated(parameters[name]);
        }