我刚开始使用automapper来映射DTO < - >实体,它似乎工作得很好.
在某些特殊情况下,我想只映射一些属性并执行其他检查.没有automapper,代码看起来像这样(使用fasterflect的PropertyExtensions):
object target;
object source;
string[] changedPropertyNames = { };
foreach (var changedPropertyName in changedPropertyNames)
{
var newValue = source.GetPropertyValue(changedPropertyName);
target.SetPropertyValue(changedPropertyName, newValue);
}
Run Code Online (Sandbox Code Playgroud)
当然,如果需要类型转换,此代码将不起作用.Automapper使用内置的TypeConverters,我还创建了一些特定的TypeConverter实现.
现在我想知道是否可以映射单个属性并使用automapper的类型转换实现,就像这样
Mapper.Map(source, target, changedPropertyName);
Run Code Online (Sandbox Code Playgroud)
我认为有必要提供更多信息:
我已经创建了一些地图,例如
Mapper.CreateMap<CalendarEvent, CalendarEventForm>()
Run Code Online (Sandbox Code Playgroud)
我还为CalendarEvent中的可为空的dateTime属性创建了一个带有自定义typeconverter的地图,例如
Mapper.CreateMap<DateTimeOffset?, DateTime?>().ConvertUsing<NullableDateTimeOffsetConverter>();
Run Code Online (Sandbox Code Playgroud)
我在web api OData Controller中使用这些映射.发布新的EntityDTO时,我使用
Mapper.Map(entityDto, entity);
Run Code Online (Sandbox Code Playgroud)
并将实体保存到数据存储区.
但是如果使用PATCH,则将a Delta<TDto> entityDto传递给我的控制器方法.因此,我需要entityDto.GetChangedPropertyNames()使用更改的值调用和更新现有的持久实体.
基本上这是使用我的简单解决方案,但如果其中一个更改的属性是例如DateTimeOffset?我想用我的NullableDateTimeOffsetConverter.
我正在使用Visual Studio 2017中的cordova应用程序,我正在尝试使用文件插件访问文件系统.不幸的是,当使用"在浏览器中模拟"(使用cordova-simulate)调试应用程序时,这不起作用.
'SecurityError:确定某些文件对Web应用程序内的访问不安全,或者对文件资源进行了太多调用.提出错误.
我想如果必须将'--allow-file-access-from-files'选项传递给chrome,但我不知道怎么做,因为chrome在新窗口中自动启动,我找不到任何配置选项在Visual Studio中.
visual-studio cordova visual-studio-cordova visual-studio-2017