示例#1
0
        /// <summary>
        /// Property Level: Gets the cached property handler object that is being mapped on a specific <see cref="PropertyInfo"/> object.
        /// </summary>
        /// <typeparam name="TPropertyHandler">The type of the handler.</typeparam>
        /// <param name="entityType">The type of the data entity.</param>
        /// <param name="propertyInfo">The instance of <see cref="PropertyInfo"/>.</param>
        /// <returns>The mapped property handler object of the property.</returns>
        internal static TPropertyHandler Get <TPropertyHandler>(Type entityType,
                                                                PropertyInfo propertyInfo)
        {
            // Validate
            ThrowNullReferenceException(propertyInfo, "PropertyInfo");

            // Variables
            var key    = GenerateHashCode(entityType, propertyInfo);
            var value  = (object)null;
            var result = default(TPropertyHandler);

            // Try get the value
            if (m_cache.TryGetValue(key, out value) == false)
            {
                // Attribute
                var attribute = propertyInfo.GetCustomAttribute <PropertyHandlerAttribute>();
                if (attribute != null)
                {
                    result = Converter.ToType <TPropertyHandler>(Activator.CreateInstance(attribute.HandlerType));
                }

                // Property Level
                if (result == null)
                {
                    result = PropertyHandlerMapper.Get <TPropertyHandler>(entityType, propertyInfo);
                }

                // Type Level
                if (result == null)
                {
                    result = PropertyHandlerMapper.Get <TPropertyHandler>(propertyInfo.PropertyType);
                }

                // Add to cache
                m_cache.TryAdd(key, result);
            }
            else
            {
                // Set the result
                result = Converter.ToType <TPropertyHandler>(value);
            }

            // Return the value
            return(result);
        }
示例#2
0
        /// <summary>
        /// Type Level: Gets the cached property handler object that is being mapped into a specific .NET CLR type.
        /// </summary>
        /// <typeparam name="TPropertyHandler">The type of the handler.</typeparam>
        /// <param name="type">The target .NET CLR type.</param>
        /// <returns>The mapped property handler object of the .NET CLR type.</returns>
        public static TPropertyHandler Get <TPropertyHandler>(Type type)
        {
            // Validate
            ThrowNullReferenceException(type, "Type");

            // Variables
            var key    = GenerateHashCode(type);
            var value  = (object)null;
            var result = default(TPropertyHandler);

            // Try get the value
            if (m_cache.TryGetValue(key, out value) == false)
            {
                result = PropertyHandlerMapper.Get <TPropertyHandler>(type);
                m_cache.TryAdd(key, result);
            }

            // Return the value
            return(result);
        }
示例#3
0
 /// <summary>
 /// Type Level: Gets the mapped property handler object of the .NET CLR type.
 /// </summary>
 /// <typeparam name="TPropertyHandler">The type of the property handler.</typeparam>
 /// <param name="type">The target .NET CLR type.</param>
 /// <returns>An instance of mapped property handler for .NET CLR type.</returns>
 public static TPropertyHandler Get <TPropertyHandler>(Type type) =>
 PropertyHandlerMapper.Get <TPropertyHandler>(type);
示例#4
0
        /*
         * Get
         */

        /// <summary>
        /// Type Level: Gets the mapped property handler object of the .NET CLR type.
        /// </summary>
        /// <typeparam name="TType">The target .NET CLR type.</typeparam>
        /// <typeparam name="TPropertyHandler">The type of the property handler.</typeparam>
        /// <returns>An instance of mapped property handler for .NET CLR type.</returns>
        public static TPropertyHandler Get <TType, TPropertyHandler>() =>
        PropertyHandlerMapper.Get <TType, TPropertyHandler>();
示例#5
0
 /// <summary>
 /// Property Level: Gets the mapped property handler object of the data entity type property (via <see cref="Field"/> object).
 /// </summary>
 /// <typeparam name="TEntity">The type of the data entity.</typeparam>
 /// <typeparam name="TPropertyHandler">The type of the property handler.</typeparam>
 /// <param name="field">The instance of <see cref="Field"/> object.</param>
 /// <returns>The mapped property handler object of the property.</returns>
 public static TPropertyHandler Get <TEntity, TPropertyHandler>(Field field)
     where TEntity : class =>
 PropertyHandlerMapper.Get <TEntity, TPropertyHandler>(TypeExtension.GetProperty <TEntity>(field.Name));
示例#6
0
 /// <summary>
 /// Property Level: Gets the mapped property handler object of the data entity type property (via property name).
 /// </summary>
 /// <typeparam name="TEntity">The type of the data entity.</typeparam>
 /// <typeparam name="TPropertyHandler">The type of the property handler.</typeparam>
 /// <param name="propertyName">The name of the property.</param>
 /// <returns>The mapped property handler object of the property.</returns>
 public static TPropertyHandler Get <TEntity, TPropertyHandler>(string propertyName)
     where TEntity : class =>
 PropertyHandlerMapper.Get <TEntity, TPropertyHandler>(TypeExtension.GetProperty <TEntity>(propertyName));
示例#7
0
        /*
         * Get
         */

        /// <summary>
        /// Property Level: Gets the mapped property handler object of the data entity type property (via expression).
        /// </summary>
        /// <typeparam name="TEntity">The type of the data entity.</typeparam>
        /// <typeparam name="TPropertyHandler">The type of the property handler.</typeparam>
        /// <param name="expression">The expression to be parsed.</param>
        /// <returns>The mapped property handler object of the property.</returns>
        public static TPropertyHandler Get <TEntity, TPropertyHandler>(Expression <Func <TEntity, object> > expression)
            where TEntity : class =>
        PropertyHandlerMapper.Get <TEntity, TPropertyHandler>(ExpressionExtension.GetProperty <TEntity>(expression));