我需要使用AutoMapper将对象映射到另一个对象.棘手的问题是如何在映射配置内或自定义类型转换器内访问映射器实例(IMapper实例)?
下面的代码不起作用,但它是我想要实现的一个例子 - 请注意mapper.Map调用并假设映射Customer => CustomerDto和Customer => DetailedCustomerDto定义.
var config = new MapperConfiguration(
cfg => cfg.CreateMap<Order, OrderDto>()
.ForMember(dst => dst.Customer, src => src.ResolveUsing(o => {
return o.Type == 1
? mapper.Map<Customer, CustomerDto>(o.Customer)
: mapper.Map<Customer, DetailedCustomerDto>(o.Customer)
})
);
Run Code Online (Sandbox Code Playgroud)
客户端部分是:
var mapper = config.CreateMapper();
var orderDto = mapper.Map<Order, OrderDto>(order);
Run Code Online (Sandbox Code Playgroud)
我要映射的对象的简化版本是:
public class Order
{
public int Type { get; set; }
public Customer Customer { get; set; }
}
public class Customer
{
public long Id …Run Code Online (Sandbox Code Playgroud) 想象一下 Angular 16 中的一个组件 ( ),它的属性some.component.ts值来自父路由。请参阅下面的示例:fooactiveRoute
@Input() foo!: string;
constructor(private activeRoute: ActivatedRoute) {
this.foo = this.activeRoute.parent?.snapshot.params['foo'];
}
Run Code Online (Sandbox Code Playgroud)
我想使用 Angular 16 输入绑定来路由参数。它适用于其他情况,但我不确定当参数实际上来自父路由时如何使其工作。
路线如下:
{
path: 'bar/:foo',
component: IrrelevantComponent,
children: [
{
path: 'some',
component: SomeComponent,
},
],
},
Run Code Online (Sandbox Code Playgroud)
这是否可以使用新的路由参数绑定来实现?如果是这样那怎么办?
我想使用Windows Server 2016(x64)来远程调试UWP应用程序.原因?我的工作PC仍然运行Windows 7实例,无法在Windows 7计算机上部署UWP应用程序.
我已经在Windows Server 2016计算机上安装了Visual Studio 2015远程工具,并在端口4020上启动它.身份验证模式设置为"无".我也在服务器上启用了Developer模式.我还在Visual Studio中设置了我的项目以使用远程机器进行调试.
问题是,每当我尝试将我的解决方案部署(仅部署,甚至不调试)到服务器时,都会发生以下情况:
Visual Studio显示以下输出:
Deploy started: Project: MyProject.UI.Uwp, Configuration: Debug x86
Starting remote deployment...
Reading package recipe file "C:\SourceCode\MyProject\MyProject.UI.Uwp\bin\x86\Debug\MyProject.UI.Uwp.build.appxrecipe"...
Run Code Online (Sandbox Code Playgroud)
和然后挂起永远.
与此同时,服务器上的远程工具显示以下输出:
UserAbc connected.
Run Code Online (Sandbox Code Playgroud)
这表明我的Windows 7 PC和目标Windows Server 2016计算机之间必须至少进行一些通信.
无论是在Visual Studio中还是在远程调试器中都没有显示任何错误消息.
知道为什么部署会在没有错误消息的情况下永久挂起吗?或者我是否想要完成一项不可能完成的任务?Windows Server 2016是否能够运行UWP应用程序?
我直接在Windows Server 2016上安装了VS 2015 Update 3.我能够直接在服务器上创建和调试简单的UWP应用程序,因此服务器显然能够运行UWP应用程序.但是我仍然无法使远程调试工作.也许问题完全在我的本地Windows 7 PC上,与Windows Server无关.奇怪的是,这个过程在"读取包装配方文件"时挂起.可能是防病毒正在拦截?
我正在将AngularJS(即Angular 1.6)应用程序升级到Angular(即Angular 4.1.3).我选择进行增量升级,因此目前AngularJS和Angular都是自举和运行的.到目前为止这么好,但是:应该重写为Angular的AngularJS服务之一依赖于众所周知的服务$translate,该服务是第三方AngularJS(读取Angular 1)模块pascalprecht.translate的一部分.换句话说,$translate注入服务MyService应该成为Angular(读取Angular 4)服务.
MyService (剥离)看起来像这样:
import { Injectable } from '@angular/core';
@Injectable()
export class MyService {
// Here comes the injection (how to do it?).
constructor(private $translate: $translate) {
}
foo() {
// Use the service
this.$translate('HELLO_WORLD');
}
}
Run Code Online (Sandbox Code Playgroud)
它位于MyModule:
import { NgModule } from '@angular/core';
import { MyService } from './my.service';
@NgModule({
providers: [
MyService
]
})
export class MyModule {
}
Run Code Online (Sandbox Code Playgroud)
现在,我怎么能注入$translate到 …
angular ×2
.net ×1
angularjs ×1
automapper ×1
c# ×1
deployment ×1
mapping ×1
routes ×1
typescript ×1
uwp ×1