Example #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ParameterKey"/> class.
        /// </summary>
        /// <param name="name">The name.</param>
        /// <param name="parameterKeyMetadata">Associated metadatas</param>
        protected ParameterKey(Type propertyType, string name, int length, ParameterKeyMetadata parameterKeyMetadata)
            : base(name, propertyType, null, parameterKeyMetadata)
        {
            Length = length;
            // Cache hashCode for faster lookup (string is immutable)
            // TODO: Make it unique (global dictionary?)
            UpdateName();

            DefaultMetadata = parameterKeyMetadata;
        }
Example #2
0
        public static ParameterKey <T> NewDynamic <T>(ParameterDynamicValue <T> dynamicValue, string name = null)
        {
            if (name == null)
            {
                name = string.Empty;
            }

            var metadata = new ParameterKeyMetadata <T>(dynamicValue);
            var result   = new ParameterKey <T>(name, 1, metadata);

            return(result);
        }
Example #3
0
        public static ParameterKey <T[]> NewDynamic <T>(int arraySize, ParameterDynamicValue <T[]> dynamicValue, string name = null) where T : struct
        {
            if (name == null)
            {
                name = string.Empty;
            }

            var metadata = new ParameterKeyMetadata <T[]>(dynamicValue);
            var result   = new ParameterKey <T[]>(name, arraySize, metadata);

            return(result);
        }
Example #4
0
        /// <summary>
        /// Creates a value key.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="defaultValue">The default value.</param>
        /// <param name="name"></param>
        /// <returns></returns>
        public static ParameterKey <T> New <T>(T defaultValue, string name = null)
        {
            if (name == null)
            {
                name = string.Empty;
            }

            var length   = typeof(T).IsArray ? (defaultValue != null ? ((Array)(object)defaultValue).Length : -1) : 1;
            var metadata = new ParameterKeyMetadata <T>(defaultValue);
            var result   = new ParameterKey <T>(name, length, metadata);

            return(result);
        }
Example #5
0
        public override void Serialize(ref ParameterKey <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 = (ParameterKey <T>)ParameterKeys.FindByName(parameterName);

                // If parameter could not be found, create one matching this type.
                if (obj == null)
                {
                    var metadata = new ParameterKeyMetadata <T>();
                    obj = new ParameterKey <T>(parameterName, parameterLength, metadata);
                    ParameterKeys.Merge(obj, null, parameterName);
                }
            }
        }