/// <summary> /// Gets the value by the key, adds it if no value was found. /// </summary> /// <param name="key"></param> /// <returns></returns> public TValue GetOrCreate(string key) { // Attempt to fetch first TValue value; if (this.TryGetValue(key, out value)) { return(value); } // Add and return value = ReplicatedActivator.CreateInstance <TValue>(); this.Add(key, value); return(value); }
/// <summary> /// Gets the value by the key, adds if if no value was found. /// </summary> /// <param name="key"></param> /// <returns></returns> public T GetOrCreate <T>(string key) where T : IReplicated { // Attempt to fetch first IReplicated value; if (this.TryGetValue(key, out value)) { return((T)value); } // Add and return value = ReplicatedActivator.CreateInstance <T>(); this.Add(key, value); return((T)value); }
/// <summary> /// Creates a value that should be used for deserialization. /// </summary> /// <param name="reader">The reader to use.</param> /// <returns>The created value.</returns> protected virtual TValue ReadValuePrefix(PacketReader reader) { return(ReplicatedActivator.CreateInstance <TValue>()); }
/// <summary> /// Creates a value that should be used for deserialization. /// </summary> /// <returns>The created value.</returns> protected sealed override IReplicated ReadValuePrefix(PacketReader reader) { // Read the identity of the type and create an instance for it return(ReplicatedActivator.CreateInstance(reader.ReadInt32())); }