/// <summary>
 /// Defines a mapping between a data entity type property and a property handler object.
 /// </summary>
 /// <typeparam name="TPropertyHandler">The type of the property handler.</typeparam>
 /// <param name="expression">The expression to be parsed.</param>
 /// <param name="propertyHandler">The instance of the property handler.</param>
 /// <param name="force">A value that indicates whether to force the mapping. If one is already exists, then it will be overwritten.</param>
 /// <returns>The current instance.</returns>
 public EntityMapFluentDefinition <TEntity> PropertyHandler <TPropertyHandler>(Expression <Func <TEntity, object> > expression,
                                                                               TPropertyHandler propertyHandler,
                                                                               bool force)
 {
     PropertyHandlerMapper.Add <TEntity, TPropertyHandler>(expression, propertyHandler, force);
     return(this);
 }
 /// <summary>
 /// Adds a property handler mapping into a data entity type property (via <see cref="Field"/> object).
 /// </summary>
 /// <typeparam name="TPropertyHandler">The type of the property handler.</typeparam>
 /// <param name="field">The instance of <see cref="Field"/> object to be mapped.</param>
 /// <param name="propertyHandler">The instance of the property handler.</param>
 /// <param name="force">A value that indicates whether to force the mapping. If one is already exists, then it will be overwritten.</param>
 /// <returns>The current instance.</returns>
 public EntityMapFluentDefinition <TEntity> PropertyHandler <TPropertyHandler>(Field field,
                                                                               TPropertyHandler propertyHandler,
                                                                               bool force)
 {
     PropertyHandlerMapper.Add <TEntity, TPropertyHandler>(field, propertyHandler, force);
     return(this);
 }
 /// <summary>
 /// Adds a property handler mapping into a data entity type property (via property name).
 /// </summary>
 /// <typeparam name="TPropertyHandler">The type of the property handler.</typeparam>
 /// <param name="propertyName">The name of the class property to be mapped.</param>
 /// <param name="propertyHandler">The instance of the property handler.</param>
 /// <param name="force">A value that indicates whether to force the mapping. If one is already exists, then it will be overwritten.</param>
 /// <returns>The current instance.</returns>
 public EntityMapFluentDefinition <TEntity> PropertyHandler <TPropertyHandler>(string propertyName,
                                                                               TPropertyHandler propertyHandler,
                                                                               bool force)
 {
     PropertyHandlerMapper.Add <TEntity, TPropertyHandler>(propertyName, propertyHandler, force);
     return(this);
 }
示例#4
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);
        }
示例#5
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);
        }
示例#6
0
        /*
         * Add
         */

        /// <summary>
        /// Type Level: Adds a mapping between a .NET CLR type and a <see cref="IPropertyHandler{TInput, TResult}"/> object.
        /// </summary>
        /// <typeparam name="TType">The target .NET CLR type.</typeparam>
        /// <typeparam name="TPropertyHandler">The type of the property handler.</typeparam>
        /// <param name="propertyHandler">The instance of the property handler. The type must implement the <see cref="IPropertyHandler{TInput, TResult}"/> interface.</param>
        /// <param name="force">Set to true if to override the existing mapping, otherwise an exception will be thrown if the mapping is already present.</param>
        public static void Add <TType, TPropertyHandler>(TPropertyHandler propertyHandler,
                                                         bool force = false) =>
        PropertyHandlerMapper.Add(typeof(TType), propertyHandler, force);
示例#7
0
        /*
         * Clear
         */

        /// <summary>
        /// Clears all the existing cached property handlers.
        /// </summary>
        public static void Clear() =>
        PropertyHandlerMapper.Clear();
示例#8
0
 /// <summary>
 /// Property Level: Removes the existing mapped property handler from a data entity type property (via <see cref="Field"/> object).
 /// </summary>
 /// <typeparam name="TEntity">The target .NET CLR type.</typeparam>
 /// <param name="field">The instance of <see cref="Field"/> object to be mapped.</param>
 public static void Remove <TEntity>(Field field)
     where TEntity : class =>
 PropertyHandlerMapper.Remove <TEntity>(field);
 /// <summary>
 /// Defines a mapping between a .NET CLR type and a <see cref="IPropertyHandler{TInput, TResult}"/> object.
 /// </summary>
 /// <typeparam name="TPropertyHandler">The type of the handler.</typeparam>
 /// <param name="propertyHandler">The instance of the property handler. The type must implement the <see cref="IPropertyHandler{TInput, TResult}"/> interface.</param>
 /// <param name="force">A value that indicates whether to force the mapping. If one is already exists, then it will be overwritten.</param>
 /// <returns>The current instance.</returns>
 public TypeMapFluentDefinition <TType> PropertyHandler <TPropertyHandler>(TPropertyHandler propertyHandler,
                                                                           bool force)
 {
     PropertyHandlerMapper.Add <TType, TPropertyHandler>(propertyHandler, force);
     return(this);
 }
示例#10
0
 /// <summary>
 /// Maps the property handler to be used by the current target property.
 /// </summary>
 /// <typeparam name="TPropertyHandler">The type of the handler.</typeparam>
 /// <param name="propertyHandler">The instance of the handler.</param>
 /// <param name="force">A value that indicates whether to force the mapping. If one is already exists, then it will be overwritten.</param>
 /// <returns>The current instance.</returns>
 public IPropertyOptions <TEntity> PropertyHandler <TPropertyHandler>(TPropertyHandler propertyHandler,
                                                                      bool force)
 {
     PropertyHandlerMapper.Add(m_expression, propertyHandler);
     return(this);
 }
示例#11
0
 /// <summary>
 /// Type Level: Removes the existing mapped property handler of the .NET CLR type.
 /// </summary>
 /// <param name="type">The target .NET CLR type.</param>
 public static void Remove(Type type) =>
 PropertyHandlerMapper.Remove(type);
示例#12
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);
示例#13
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));
示例#14
0
 /// <summary>
 /// Property Level: Adds a property handler mapping into a data entity type property (via <see cref="Field"/> object).
 /// </summary>
 /// <typeparam name="TEntity">The target .NET CLR type.</typeparam>
 /// <typeparam name="TPropertyHandler">The type of the property handler.</typeparam>
 /// <param name="field">The instance of <see cref="Field"/> object to be mapped.</param>
 /// <param name="propertyHandler">The instance of the property handler.</param>
 /// <param name="force">A value that indicates whether to force the mapping. If one is already exists, then it will be overwritten.</param>
 public static void Add <TEntity, TPropertyHandler>(Field field,
                                                    TPropertyHandler propertyHandler,
                                                    bool force)
     where TEntity : class =>
 PropertyHandlerMapper.Add <TEntity, TPropertyHandler>(field, propertyHandler, force);
示例#15
0
 /// <summary>
 /// Property Level: Adds a property handler mapping into a data entity type property (via property name).
 /// </summary>
 /// <typeparam name="TEntity">The target .NET CLR type.</typeparam>
 /// <typeparam name="TPropertyHandler">The type of the property handler.</typeparam>
 /// <param name="propertyName">The instance of property handler.</param>
 /// <param name="propertyHandler">The instance of property handler.</param>
 /// <param name="force">A value that indicates whether to force the mapping. If one is already exists, then it will be overwritten.</param>
 public static void Add <TEntity, TPropertyHandler>(string propertyName,
                                                    TPropertyHandler propertyHandler,
                                                    bool force)
     where TEntity : class =>
 PropertyHandlerMapper.Add <TEntity, TPropertyHandler>(propertyName, propertyHandler, force);
示例#16
0
 /// <summary>
 /// Property Level: Adds a property handler mapping into a 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>
 /// <param name="propertyHandler">The instance of the property handler.</param>
 /// <param name="force">A value that indicates whether to force the mapping. If one is already exists, then it will be overwritten.</param>
 public static void Add <TEntity, TPropertyHandler>(Expression <Func <TEntity, object> > expression,
                                                    TPropertyHandler propertyHandler,
                                                    bool force)
     where TEntity : class =>
 PropertyHandlerMapper.Add <TEntity, TPropertyHandler>(ExpressionExtension.GetProperty <TEntity>(expression), propertyHandler, force);
示例#17
0
 /// <summary>
 /// Type Level: Adds a mapping between a .NET CLR type and a <see cref="IPropertyHandler{TInput, TResult}"/> object.
 /// </summary>
 /// <param name="type">The target .NET CLR type.</param>
 /// <param name="propertyHandler">The instance of the property handler. The type must implement the <see cref="IPropertyHandler{TInput, TResult}"/> interface.</param>
 /// <param name="force">Set to true if to override the existing mapping, otherwise an exception will be thrown if the mapping is already present.</param>
 public static void Add(Type type,
                        object propertyHandler,
                        bool force = false) =>
 PropertyHandlerMapper.Add(type, propertyHandler, force);
示例#18
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>();
示例#19
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));
示例#20
0
        /*
         * Remove
         */

        /// <summary>
        /// Type Level: Removes the existing mapped property handler of the .NET CLR type.
        /// </summary>
        /// <typeparam name="T">The target .NET CLR type.</typeparam>
        public static void Remove <T>() =>
        PropertyHandlerMapper.Remove(typeof(T));
示例#21
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));
示例#22
0
        /*
         * Add
         */

        /// <summary>
        /// Property Level: Adds a property handler mapping into a 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>
        /// <param name="propertyHandler">The instance of the property handler.</param>
        public static void Add <TEntity, TPropertyHandler>(Expression <Func <TEntity, object> > expression,
                                                           TPropertyHandler propertyHandler)
            where TEntity : class =>
        PropertyHandlerMapper.Add <TEntity, TPropertyHandler>(expression, propertyHandler, false);
示例#23
0
        /*
         * Add
         */

        /// <summary>
        /// Type Level: Adds a mapping between the .NET CLR Type and a property handler.
        /// </summary>
        /// <typeparam name="TType">The .NET CLR type.</typeparam>
        /// <typeparam name="TPropertyHandler">The type of the handler.</typeparam>
        /// <param name="propertyHandler">The instance of the property handler. The type must implement the <see cref="IPropertyHandler{TInput, TResult}"/> interface.</param>
        /// <param name="override">Set to true if to override the existing mapping, otherwise an exception will be thrown if the mapping is already present.</param>
        public static void Add <TType, TPropertyHandler>(TPropertyHandler propertyHandler,
                                                         bool @override = false) =>
        PropertyHandlerMapper.Add(typeof(TType), propertyHandler, @override);
示例#24
0
        /*
         * Remove
         */

        /// <summary>
        /// Property Level: Removes the existing mapped property handler from a data entity type property (via expression).
        /// </summary>
        /// <typeparam name="TEntity">The type of the data entity.</typeparam>
        /// <param name="expression">The expression to be parsed.</param>
        public static void Remove <TEntity>(Expression <Func <TEntity, object> > expression)
            where TEntity : class =>
        PropertyHandlerMapper.Remove <TEntity>(ExpressionExtension.GetProperty <TEntity>(expression));
示例#25
0
 /// <summary>
 /// Type Level: Adds a mapping between the .NET CLR Type and a property handler.
 /// </summary>
 /// <param name="type">The .NET CLR Type.</param>
 /// <param name="propertyHandler">The instance of the property handler. The type must implement the <see cref="IPropertyHandler{TInput, TResult}"/> interface.</param>
 /// <param name="override">Set to true if to override the existing mapping, otherwise an exception will be thrown if the mapping is already present.</param>
 public static void Add(Type type,
                        object propertyHandler,
                        bool @override = false) =>
 PropertyHandlerMapper.Add(type, propertyHandler, @override);
示例#26
0
 /// <summary>
 /// Property Level: Removes the existing mapped property handler from a data entity type property (via property name).
 /// </summary>
 /// <typeparam name="TEntity">The target .NET CLR type.</typeparam>
 /// <param name="propertyName">The instance of property handler.</param>
 public static void Remove <TEntity>(string propertyName)
     where TEntity : class =>
 PropertyHandlerMapper.Remove <TEntity>(propertyName);
示例#27
0
 public IPropertyOptions <T> PropertyHandler <THandler>(THandler propertyHandler)
 {
     PropertyHandlerMapper.Add(m_expression, propertyHandler);
     return(this);
 }