首页 \ 问答 \ AutoMapper:如果source == null,则创建目标类型的实例(AutoMapper: create instance of destination type if source == null)

AutoMapper:如果source == null,则创建目标类型的实例(AutoMapper: create instance of destination type if source == null)

如果源对象为空,是否可以配置AutoMapper以返回目标类型的新实例?

Source source = null;
Dest d1 = AutoMapper.Mapper.Map<Source, Dest>(source);
// d1 == null

// I'm looking for a way to configure AutoMapper to
// eliminate this code:
Dest d2 = AutoMapper.Mapper.Map<Source, Dest>(source) ?? new Dest();

Is it possible to configure AutoMapper to return a new instance of the destination type if the source object is null?

Source source = null;
Dest d1 = AutoMapper.Mapper.Map<Source, Dest>(source);
// d1 == null

// I'm looking for a way to configure AutoMapper to
// eliminate this code:
Dest d2 = AutoMapper.Mapper.Map<Source, Dest>(source) ?? new Dest();

原文:https://stackoverflow.com/questions/3407838
更新时间:2024-04-10 10:04

最满意答案

免责声明:我为创建我提到的产品的公司工作。

有很多方法可以跟踪应用程序使用情况。 其中之一就是在服务器上显示一个网页作为安装过程的最后一步,或者在应用程序中有一个闪现在该网页的启动画面。 使用这两种方法之一,您可以使用网络分析为您提供已安装或运行应用程序的用户与下载数量的粗略衡量。

另一种方法是使用PreEmptive Solutions的Runtime Intelligence产品,该产品可将使用情况跟踪功能直接注入到.NET(或Java)应用程序中。 这会给你测量有多少人正在运行你的软件以及系统配置文件信息。 您还可以添加跟踪特定功能的使用情况,以便您可以查看您的应用程序内部人们正在使用的内容(包括他们执行特定操作需要多长时间)。 我们使用Dotfuscator(或DashO for Java)作为我们的代码注入引擎,在编译后将新指令插入到您的应用程序中(类似于PostSharp的IL Weaving工作方式)。

Visual Studio 2010附带了该产品的免费版本。Beta 1目前可用,并将包含在未来的Beta版和Visual Studio的发行版中。 这将允许你使用任何.NET应用程序。

我已经撰写了一篇关于使用Visual Studio 2010中的免费版将Correcting Downloads to Usage关联的博客文章,还有一篇博客文章概述了免费版中包含的所有功能。 我正计划编写未来的博客文章,详细介绍向应用程序添加功能级别跟踪和度量。

有关免费Community Edition中提供的更多功能,您可以要求免费评估PreEmptive Solutions的商业版本。

你也可以看到这些其他的StackOverflow问题:

Windows应用程序分析

观察或监视使用远程应用程序的用户


Disclaimer: I work for the company that has created the product I mention.

There are a number of ways to track application usage. One of them is to display a web page on your server as the last step in the installation process or to have a splash screen in your application that hits that web page. With either of these you can use web analytics to give you a rough measurement of the users that have installed or run your application versus the number of downloads.

Another method is to use the Runtime Intelligence product from PreEmptive Solutions, which will inject usage tracking functionality directly into your .NET (or Java) applications. This will give you measurements of how many people are actually running your software as well as system profile information. You can also add in tracking of specific feature usage so that you can see what people are using inside of your applications (including how long they take to perform certain actions). We use Dotfuscator (or DashO for Java) as our code injection engine to insert new instructions into your applications after they have been compiled (similar to how PostSharp's IL Weaving works).

There is a free version of this product that is included with Visual Studio 2010. The Beta 1 is currently available and will be included in future Beta's and the release version of Visual Studio. This will allow you to instrument any .NET application.

I have written a blog article on Correlating Downloads To Usage using the free version in Visual Studio 2010 and there is also a blog article with an overview of all of the functionality included in the free version. I am planning on writing future blog posts detailing adding feature level tracking and measurements to applications as well.

For more features than are available in the free Community Edition you can request a free evaluation of the commercial version from PreEmptive Solutions.

You can also see these other StackOverflow questions:

Analytics for Windows Applications

Observing Or Monitoring Users Working With An Application Remotely

相关问答

更多
  • 免责声明:我为创建我提到的产品的公司工作。 有很多方法可以跟踪应用程序使用情况。 其中之一就是在服务器上显示一个网页作为安装过程的最后一步,或者在应用程序中有一个闪现在该网页的启动画面。 使用这两种方法之一,您可以使用网络分析为您提供已安装或运行应用程序的用户与下载数量的粗略衡量。 另一种方法是使用PreEmptive Solutions的Runtime Intelligence产品,该产品可将使用情况跟踪功能直接注入到.NET(或Java)应用程序中。 这会给你测量有多少人正在运行你的软件以及系统配置文件 ...
  • 使用ps或类似的工具,您只能获得该进程分配的内存页面数量。 这个数字是正确的,但是: 不反映应用程序使用的实际内存量,只能为其保留的内存量 如果页面是共享的,例如通过多个线程或通过使用动态链接的库,这可能会导致误导 如果您真的想知道应用程序实际使用的内存量,则需要在分析器中运行它。 例如, valgrind可以让您深入了解使用的内存量,更重要的是,可能会导致程序中可能的内存泄漏。 valgrind的堆分析器工具称为“massif”: Massif是一个堆分析器。 它通过定期获取程序堆的快照来执行详细的堆分析 ...
  • Process类提供了大部分这些信息。 我想你以后会是Process.PrivateMemorySize64 。 你应该能够做到: var memoryUsage = Process.GetCurrentProcess().PrivateMemorySize64; The Process class provides most of this information. I think what you're after would be Process.PrivateMemorySize64. You s ...
  • 好的这个作品: public static function isAndroid():Boolean { return (Capabilities.version.substr(0,3) == "AND"); } public static function isIOS():Boolean { return (Capabilities.version.substr(0,3) == "IOS"); } ... //is Blackberry public static function i ...
  • 无论是每30分钟还是每2小时检查一次,都应该没有区别。 (我假设您检查时正在进行的处理很小。)检查太频繁是电池耗尽的问题,但仅限于检查间隔<1秒的情况。 因此,如果您的问题是“最佳使用间隔是多少?” 然后30分钟应该不是问题。 如果您的问题是“我遇到电池耗尽问题,需要找出它的位置”,那么这就成了一个分析问题。 而且它变得更加复杂,特别是当你试图从类或甚至轻量级过程(例如线程)角度查看事物时。 您可以在类或线程级别进行分析,但除非您的硬件具有用于记录功率,电流或电压信息的特殊寄存器,否则它将变得非常复杂。 如 ...
  • 如果你使用Apache,你可以使用ApacheBench , 在这里有一个教程。 如果您使用NGIX,您可以像本教程一样使用Siege。 在测试应用程序时,您可以看到内存使用情况,在Linux中,您可以使用HTOP。 If you use Apache you can use the ApacheBench, have a tutorial here. If you use NGIX you can use the Siege like this tutorial. When you test your a ...
  • 这取决于你的设置。 如果您的Web服务器具有(接近)专用物理接口,则可以直接从界面收集统计数据。 这样做的方法可能包括SNMP(尝试net-snmp)或“ifconfig”,结合RRDTool或简单的日志记录到平面文件。 另一种方法是使用Apache日志,它可能如下所示: 192.168.101.155 - - [17/Apr/2005:20:39:19 -0700] "GET / HTTP/1.1" 200 1456 192.168.101.155 - - [17/Apr/2005:20:39:19 -0 ...
  • 但是,由于我在代码中的许多不同位置和许多不同位置下载了内容,是否有其他可能性来衡量每个应用程序的数据使用情况? TrafficStats可以通过UID报告事情。 我说“可能”是因为它似乎与设备有关。 我怀疑Android 3.0+会一直由UID报告,但我的2.2和2.3经验混杂在一起。 这里是一个示例应用程序演示记录这些信息。 However, as I downloaded things in many different situations and in many different position ...
  • 对于实时测量,我使用来自第三方存储库的基于tex的htop。 它像顶部但更好,它以图形方式显示cpu(所有cpu的单独),ram负载。 For real time measurement I use tex-based htop from third-party repositories. It is like top but better, it shows graphically cpu (all cpu's separately), ram load.
  • 不,clock()不包括服务器端Java程序的CPU使用率。 您可以在这里参考可用的Java分析工具/分析器列表 No, clock() does not include the CPU usage of server side Java program. You could refer here for the list of java analysis tools/profilers available

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)