コード例 #1
0
        /// <summary>
        /// Registers a delegate to get the value of a property from an object.
        /// </summary>
        /// <param name="type">The type the property belongs to.</param>
        /// <param name="propertyName">The name of the property obtained by <paramref name="getter"/>.</param>
        /// <param name="getter">A delegate to get the value of the property.</param>
        public void Register(Type type, string propertyName, Func <object, object> getter)
        {
            Contract.RequiresNotNull(type, nameof(type));

            TypeGetterCache typeCache;

            if (!_types.TryGetValue(type, out typeCache))
            {
                typeCache    = new TypeGetterCache(type);
                _types[type] = typeCache;
            }

            typeCache.Register(propertyName, getter);
        }
コード例 #2
0
        /// <summary>
        /// Gets a delegate which obtains the value of the property with the given name.
        /// </summary>
        /// <param name="type">The type the property belongs to.</param>
        /// <param name="propertyName">The name of the property.</param>
        /// <returns>A delegate to get the value of the property.</returns>
        public Func <object, object> Get(Type type, string propertyName)
        {
            Contract.RequiresNotNull(type, nameof(type));
            Contract.RequiresNotNull(propertyName, nameof(propertyName));

            TypeGetterCache typeCache;

            if (!_types.TryGetValue(type, out typeCache))
            {
                typeCache    = new TypeGetterCache(type);
                _types[type] = typeCache;
            }

            return(typeCache[propertyName]);
        }
コード例 #3
0
        /// <summary>
        /// Gets a <see cref="TypeGetterCache"/> for the given type.
        /// </summary>
        /// <param name="type">The type whose cache to get.</param>
        /// <returns>A cache of delegates for a specific type.</returns>
        public TypeGetterCache this[Type type]
        {
            get
            {
                TypeGetterCache typeCache;

                if (!_types.TryGetValue(type, out typeCache))
                {
                    typeCache    = new TypeGetterCache(type);
                    _types[type] = typeCache;
                }

                return(typeCache);
            }
        }