小编Pau*_*aul的帖子

自动映射器根据源类型中枚举的值解析目标类型

我试图找到一种方法让Automapper根据Source类型中设置的Enum值选择映射调用的目标类型...

例如,给出以下类:

public class Organisation
{ 
    public string Name {get;set;}
    public List<Metric> Metrics {get;set;}
}

public class Metric
{
   public int NumericValue {get;set;}
   public string TextValue {get;set;}
   public MetricType MetricType {get;set;}
}

public enum MetricType
{
    NumericMetric,
    TextMetric
}
Run Code Online (Sandbox Code Playgroud)

如果我有以下对象:

var Org = new Organisation { 
    Name = "MyOrganisation",
    Metrics = new List<Metric>{
        new Metric { Type=MetricType.TextMetric, TextValue = "Very Good!" },
        new Metric { Type=MetricType.NumericMetric, NumericValue = 10 }
    }
}
Run Code Online (Sandbox Code Playgroud)

现在,我想将它映射到具有类的viewmodel表示:

public class OrganisationViewModel
{ 
    public string Name …
Run Code Online (Sandbox Code Playgroud)

.net c# automapper

10
推荐指数
1
解决办法
1933
查看次数

电子邮件验证MX Lookup

我被要求在网络应用程序上实现一些电子邮件地址验证 - 我确信我们已经在那里进行了一千次...但是,这次我被要求在域上进行MX查找以查看是否它接受电子邮件.

有没有人知道这样做的任何潜在问题?mx查找是否是查明域是否接受电子邮件的可靠方法?是否有任何边缘情况,有效的电子邮件地址可能无法进行MX查找检查?

谢谢你的建议!

email email-validation

9
推荐指数
1
解决办法
4454
查看次数

设置可拖动对象的边界限制

我有两个要素:

1.身高固定的父母,overflow:hidden

2.它的孩子更大的固定高度.

<style type="text/css">
    .myList {list-style:none; margin:0px; padding:1px;}
    .myList li{ height:50px;  margin:4px; padding:2px;}
    .dragPanel {height:230px; border:solid; overflow:hidden;}
</style>

<div class="dragPanel">
    <ul class="myList">
        <li>1</li>
        <li>2</li>
        ...   ....
        <li>8</li>
        <li>9</li>
    </ul>
</div>
Run Code Online (Sandbox Code Playgroud)

我希望能够在父div中上下拖动列表.我使用jquery ui draggable插件来实现Verticle拖动,但我不确定如何约束父div中的列表.

<script type="text/javascript" src="http://jqueryui.com/latest/jquery-1.3.2.js"></script>
<script type="text/javascript" src="http://jqueryui.com/latest/ui/ui.core.js"></script>
<script type="text/javascript" src="http://jqueryui.com/latest/ui/ui.draggable.js"></script>

<script type="text/javascript">
    $(document).ready(function() {
        $('.dragPanel').addClass("hover");
        $('.myList').draggable({ axis: 'y' });
    });
</script>
Run Code Online (Sandbox Code Playgroud)

我如何为列表的位置设置Verticle上限和下限?

javascript jquery jquery-ui draggable

7
推荐指数
3
解决办法
3万
查看次数

ASP.NET WebApi测试 - 断言请求会返回404响应

我用以下方法创建了一个ApiController:

    public User Get(int id)
    {
        var user = DocumentSession.Load<User>(id);
        if(user!=null)
        {
            return Mapper.Map<User>(user); 
        }
        throw new HttpResponseException(HttpStatusCode.NotFound);
    }
Run Code Online (Sandbox Code Playgroud)

我试图为这个方法编写一个测试,该测试断言当一个无效的id传递给该函数时,它会返回一个适当的404响应.

目前我有:

    [Test]
    public void get_invalid_user_returns_404()
    {
        Assert.Throws<HttpResponseException>(()=>_usersController.Get(1001));
    }
Run Code Online (Sandbox Code Playgroud)

这工作并通过,但它没有断言它是404响应,只是抛出了正确的异常类型.我该怎么做才能断言结果是404?

谢谢

asp.net-web-api

7
推荐指数
1
解决办法
1881
查看次数

使用asp webapi发布嵌套资源

我正在使用mvc webapi创建REST API,并努力寻找一个处理嵌套资源的POST的示例.

基本上,我想POST使用以下网址对博客文章发表评论:

~/posts/2/comments

我也希望能够发送DELETE和PUTs以下内容

~/posts/2/comments/5

我的路线注册应该是什么样的,我的方法签名应该是什么PostsController样的呢?

谢谢!

rest asp.net-mvc asp.net-web-api

7
推荐指数
1
解决办法
1518
查看次数

Subsonic 3 - SimpleRepository

我正在玩Subsonic 3的简单存储库,并且正在了解如何处理外键...

如果我有一个包含的产品对象

int ID; 

string name; 

string description; 

Category category; 

int categoryID (this one is just to persist the product's categoryID to the DB)

and a category object containing 

int ID; 

string name;
Run Code Online (Sandbox Code Playgroud)

如何使用存储库返回实例化其类别对象的所有产品的列表?

目前我已经编写了一个连接在product.categoryID = category.ID上的linq查询,这一切都很好,但是当我.ToList()查询结果时,产品的类别没有实例化.

有没有办法做到这一点,还是我必须手动实例化每个产品的类别?

谢谢,

保罗

.net c# subsonic repository subsonic3

6
推荐指数
1
解决办法
1587
查看次数

自动映射:从自动对象中解析源属性名称

鉴于以下课程:

public class User
{
  public int Id {get;set;}
  public PersonName Name {get;set;}
}

public class PersonName 
{
  public string FirstName {get;set;}
  public string LastName {get;set;}
}


public class UserDto 
{
  public int Id {get;set;}
  public string FirstName {get;set;}
}
Run Code Online (Sandbox Code Playgroud)

以及映射配置如下:

 Mapper.CreateMap<User, UserDto>()
            .ForMember(destination => destination.FirstName, 
            options => options.MapFrom(source => source.Name.FirstName))
Run Code Online (Sandbox Code Playgroud)

是否可以解析目标对象上给定属性的源属性的名称:

就像是:

Assert.AreEqual(GetSourcePropertyName<User, UserDto>("FirstName"), "Name.FirstName")
Run Code Online (Sandbox Code Playgroud)

.net c# automapper

5
推荐指数
1
解决办法
2600
查看次数

选择菜单上的IE8和边框css属性

当我在IE中查看一个非常简单的HTML文件时,我发现了一个非常奇怪的行为.我无法解释这个......

采取以下HTML

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">

<html>
  <head>
    <style>
      .iWantaBorder
      { 
        border:red solid 1px ;  
      }
    </style>
  </head>
  <body>
    <select class="iWantaBorder">
  <option>1</option>
    </select>
  </body>
</html>
Run Code Online (Sandbox Code Playgroud)

将html文件另存为桌面.在IE8中查看时,选择菜单有一个红色边框.

现在将文件复制到IIS 5.1或IIS6中的网站或虚拟目录.

在IE8中浏览到该文件...没有红色边框.

谁能告诉我这里发生了什么?我真的想要这个菜单上的边框.认为这应该是简单的说实话,但我很困惑!

html css iis internet-explorer

3
推荐指数
1
解决办法
2万
查看次数