在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
最满意答案
如果要使用.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
相关问答
更多-
将列表转换为另一种类型并更改其每个元素的变量(cast list to another type and change variable of each element of it)[2022-08-24]
使用选项严格 On您将看到ToList方法不是扩展方法,它实际上是List类的一部分。 此方法接受Action aka。 sub,而不是Func aka。 功能。 应用所有这些修复程序,代码应如下所示: 单线: results.OfType(Of SearchResultWithDetails).ToList().ForEach(Sub(item) item.ShortDescription = item.DetailsText) 多行: results.OfType(Of Searc ... -
如果要使用.Cast方法,则需要实现转换运算符。 你可以在这里查看如何做到这一点。 如何为班级提供自定义演员支持? 或者您可以使用.Select方法执行此操作,但您需要自己初始化每个对象。 //Get Data var data = db2Repo.GetDB2Data(); var sqlData = data.Select(x => new Common.Sql.MyModel(){ // Do your mapping here }); //Post Data s ...
-
使用Java 8将一种类型的List转换为另一种类型的Array(Convert List of one type to Array of another type using Java 8)[2022-04-15]
我会这样写: securityPolicyIds.stream() .map(Long::valueOf) .map(TeamsNumberIdentifier::new) .toArray(TeamsNumberIdentifier[]::new); I would write it like this: securityPolicyIds.stream() .map( ... -
使用map()将Stream转换为Stream
-
如何将一种类型的通用列表转换为未知类型的通用列表(How To Cast Generic List of One Type To Generic List of an Unknown Type)[2021-12-31]
如果您知道列表中的每个项目都是ObjectType ,则可以这样做: List -
您需要自行构建一种Mapper ,将Dataset转换为objects ; 或者您可以使用可用的工具,如AutoMapper 。 这些映射通常需要了解Adapter和Builder设计模式。 我会强调更多的构建这个映射的Builder模式更重要。 按照这个例子,你也可以使用LINQ和Extension Methods来实现你的需求。 You would need to either build a kind of Mapper on your own, that transforms your Datase ...
-
无论如何在linq或其他.net方式做到这一点? 当然: List
list = ...; // Make your user list List< UserProtectedDetails> = list .Select(u => new UserProtectedDetails{name=u.name}) .ToList(); 编辑:(回应评论 )如果你想避免{name = u.name}部分,你需要(1)一个为你做映射的函数,或者(2) UserProtectedDeta ... -
对类使用泛型如何将值从一种类型转换为另一种类型?(Using generics for a class how can I convert the values from one type to another?)[2022-12-10]
也许你可以使用Function界面 ? public abstract class Field implements FieldType { ... public T convert(F value, Function converter) { try { return converter.apply(value); } catch(Exception e) { r ... -
您可以使用Enumerable.Cast<> : var oldTabs = Tabs.Cast
().ToList(); 或者如果有一些非CormantRadTab元素,并且您只想选择CormantRadTab元素,请使用OfType OfType<> : var oldTabs = Tabs.OfType ().ToList(); (在这两种情况下,结果都是List 类型 - 使用显式键入或隐式键入,无论你喜欢什么。 ... -
你可以像这样做一些递归的东西: public class Source { public int Id { get; set; } public List