Data/CafeLib.Data.Mapping/MappedEntity.cs
/// <summary>
/// Copy values from data model to mapped entity.
/// </summary>
/// <param name="entity"></param>
/// <returns>mapped entity</returns>
Copy values from data model to mapped entity.
Copy values from data model to mapped entity .
public TEntity ToEntity(TEntity entity = default)
        {
            var dto = entity ?? Activator.CreateInstance<TEntity>();
            foreach (var (_, propertyConverter) in _propertyConverters)
            {
                var entityProperty = EntityProperties[propertyConverter.PropertyInfo.Name];
                if (entityProperty == null || !entityProperty.CanRead || entityProperty.GetGetMethod() == null) continue;
                var value = propertyConverter.ToOutput != null
                            ? ((Delegate) propertyConverter.ToOutput).DynamicInvoke(propertyConverter.PropertyInfo.GetValue(this))
                            : propertyConverter.PropertyInfo.GetValue(this);
                entityProperty.SetValue(dto, value);
            }
            return dto;
        }
public TEntity ToEntity ( TEntity entity = default ) { var dto = entity ?? Activator . CreateInstance < TEntity > ( ) ; foreach ( var ( _ , propertyConverter ) in _propertyConverters ) { var entityProperty = EntityProperties [ propertyConverter . PropertyInfo . Name ] ; if ( entityProperty == null || ! entityProperty . CanRead || entityProperty . GetGetMethod ( ) == null ) continue ; var value = propertyConverter . ToOutput != null ? ( ( Delegate ) propertyConverter . ToOutput ) . DynamicInvoke ( propertyConverter . PropertyInfo . GetValue ( this ) ) : propertyConverter . PropertyInfo . GetValue ( this ) ; entityProperty . SetValue ( dto , value ) ; } return dto ; }
Copy values from data model to mapped entity.
Copy values from data model to mapped entity .
None
entity
TEntity
None