示例#1
0
        /// <summary>
        /// Gets an object.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="parameter"></param>
        /// <returns></returns>
        public T Get <T>(ObjectParameterKey <T> parameter, bool createIfNew = false)
        {
            var accessor = GetAccessor(parameter, createIfNew);

            if (accessor.BindingSlot == -1)
            {
                return(parameter.DefaultValueMetadataT.DefaultValue);
            }

            return(Get(accessor));
        }
示例#2
0
        public override void Serialize(ref ObjectParameterKey <T> obj, ArchiveMode mode, SerializationStream stream)
        {
            if (mode == ArchiveMode.Serialize)
            {
                stream.Write(obj.Name);
                stream.Write(obj.Length);
            }
            else
            {
                var parameterName   = stream.ReadString();
                var parameterLength = stream.ReadInt32();
                obj = (ObjectParameterKey <T>)ParameterKeys.FindByName(parameterName);

                // If parameter could not be found, create one matching this type.
                if (obj == null)
                {
                    var metadata = new ParameterKeyValueMetadata <T>();
                    obj = new ObjectParameterKey <T>(parameterName, parameterLength, metadata);
                    ParameterKeys.Merge(obj, null, parameterName);
                }
            }
        }
示例#3
0
 /// <summary>
 /// Sets an object.
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="parameter"></param>
 /// <param name="value"></param>
 public void Set <T>(ObjectParameterKey <T> parameter, T value)
 {
     Set(GetAccessor(parameter), value);
 }
示例#4
0
        /// <summary>
        /// Gets an accessor to get and set objects more quickly.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="parameterKey"></param>
        /// <returns></returns>
        public ObjectParameterAccessor <T> GetAccessor <T>(ObjectParameterKey <T> parameterKey, bool createIfNew = true)
        {
            var accessor = GetObjectParameterHelper(parameterKey, createIfNew);

            return(new ObjectParameterAccessor <T>(accessor.Offset, accessor.Count));
        }