首页 \ 问答 \ 在WP7代码中检测DesignTime(Detect DesignTime in WP7 code)

在WP7代码中检测DesignTime(Detect DesignTime in WP7 code)

简单的问题,没有人知道如何检测代码是否与WP7设计时执行? HtmlPage.IsEnabled的通常Silverlight解决方案在此上下文中不起作用。


simple question, does anyone know how to detect whether code is executed design-time with WP7? The usual Silverlight solution of HtmlPage.IsEnabled doesn't work in this context.


原文:https://stackoverflow.com/questions/4828319
更新时间:2022-12-25 14:12

最满意答案

如果要使用.Cast方法,则需要实现转换运算符。 你可以在这里查看如何做到这一点。 如何为班级提供自定义演员支持?

或者您可以使用.Select方法执行此操作,但您需要自己初始化每个对象。

//Get Data
var data =  db2Repo.GetDB2Data();

var sqlData = data.Select(x => 
    new Common.Sql.MyModel(){ 
    // Do your mapping here 
    });

//Post Data 
sqlRepo.PostToSql(sqlData );

我对此场景的建议:如果这些模型是您域的一部分,请在架构告诉您的时候创建映射。 否则,只需创建构造函数即可进行映射。

您可以了解更多信息。请在此处选择: https ://msdn.microsoft.com/en-us/library/bb548891( v = vs.110).aspx


If you want to use the .Cast method, you need to implement the casting operators. You can check how to do it here. How do I provide custom cast support for my class?

Or you can do this using the .Select method, but you'll need to initialize each object by yourself.

//Get Data
var data =  db2Repo.GetDB2Data();

var sqlData = data.Select(x => 
    new Common.Sql.MyModel(){ 
    // Do your mapping here 
    });

//Post Data 
sqlRepo.PostToSql(sqlData );

My suggestion for this scenario: If these models are part of your domain, create the mapping in whenever your architecture tells you to do. Otherwise, just create constructors to do the mapping.

You can learn more about .Select here: https://msdn.microsoft.com/en-us/library/bb548891(v=vs.110).aspx

相关问答

更多