Ejemplo n.º 1
0
        /// <summary>
        /// Gets whether or not this dynamic data instance has a property with the specified name.
        /// This is a case-insensitive search.
        /// </summary>
        /// <param name="name">The property name to check for</param>
        /// <returns>True if the property exists, false otherwise</returns>
        public bool HasProperty(string name)
        {
            Type type;

            if (_registeredTypes.TryGetType(name, out type))
            {
                return(_cache.HasData(type));
            }
            return(false);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Gets the property's value with the specified name. This is a case-insensitve search.
        /// </summary>
        /// <param name="name">The property name to access</param>
        /// <returns>object value of BaseData</returns>
        public object GetProperty(string name)
        {
            Lazy <object> value;

            if (_storage.TryGetValue(name, out value))
            {
                return(value.Value);
            }

            // check to see if the requested name matches one of the algorithm registered data types and if
            // so, we'll return a new empty list. this precludes us from always needing to check HasData<T>
            Type type;

            if (_registeredTypes.TryGetType(name, out type))
            {
                var listType = GetGenericListType(type);
                return(Activator.CreateInstance(listType));
            }

            var keys = _storage.Keys.OrderBy(k => k);

            throw new KeyNotFoundException($"Property with name '{name}' does not exist. Properties: {string.Join(", ", keys)}");
        }