小编Chr*_*ers的帖子

原型上的Object.defineProperty阻止JSON.stringify序列化它

我正在使用TypeScript来定义一些类,当我创建一个属性时,它会生成Class1以下plunkr中的等价物:

http://plnkr.co/edit/NXUo7zjJZaUuyv54TD9i?p=preview

var Class1 = function () {
  this._name = "test1";
}

Object.defineProperty(Class1.prototype, "Name", {
  get: function() { return this._name; },
  set: function(value) { this._name = value; },
  enumerable: true
});

JSON.stringify(new Class1()); // Will be "{"_name":"test1"}"
Run Code Online (Sandbox Code Playgroud)

序列化时,它不会输出我刚刚定义的属性.

instance2并且instance3通过序列化已定义的属性来表现我的期望.(参见plunkr输出).

我的实际问题是:这是正常的吗?

如果是这样,我该如何以最有效的方式解决它?

javascript json typescript

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

使用Dapper映射超过5种类型

我目前正在构建一个将12个表连接在一起的SELECT查询.我一直在使用Dapper进行所有其他查询,效果很好.问题是,泛型方法只需要五个通用参数.

我之前修改过代码以支持最多6个用于另一个查询,但现在我真的不认为我应该破解6个更多级别的泛型.

有没有办法将dapper传递给一个类型数组,并将结果作为一个对象数组返回,如果必须的话我可以手动编译?

我也可能以错误的方式接近问题!任何帮助将不胜感激!

c# sql dapper

15
推荐指数
1
解决办法
6074
查看次数

asp.net MVC Url.Content()CDN重定向

我想知道是否有一种简单的方法可以为我在视图中通过Url.Content引用的所有内容指定CDN.

我可以在Web.config文件中以类似于以下的方式配置的东西.

    <cdn>
        <add filetype="css" root="http://mycdn.mydomain.com/stylesheets/" />
        <add filetype="js" root="http://myjscdn.mydomain.com/js/ />
    </cdn>

然后,我可以只有<%= Url.Content("〜/ Content/StyleSheets/What.css")%>并输出http://mycdn.mydomain.com/stylesheets/Content/StyleSheets/What.css.

如果没有可用的东西,我会通过扩展方法自己做,但我想知道它是否可以开箱即用.

asp.net-mvc redirect cdn

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

asp.NET MVC 2 DataAnnotations UpdateModel <T>验证

我正在尝试使用DataAnnotations在asp.NET MVC 2 RC2中为我的模型添加验证,使用TryUpdateModel

        var user = UserManager.Find(id);

        this.TryUpdateModel<IProvisioningObject>(user, form.ToValueProvider());
Run Code Online (Sandbox Code Playgroud)

这会更新模型,但永远不会调用验证.我也尝试使用TryUpdateModel(这是用户的直接类型),不使用表单值提供程序,直接使用ProvisioningObject(具有验证元数据),无济于事.

谷歌搜索示例仅为我提供了通过参数绑定来使用DataAnnotations的方法

public ActionResult Update(User user)
Run Code Online (Sandbox Code Playgroud)

我不喜欢更新方案.

任何提示和/或解决方案?

编辑 我的对象是来自WCF服务的自动生成的对象.

我做了部分能够添加DataAnnotations.我调用TryUpdateModel三次,因为它显然不支持继承,我认为这也是我对DataAnnotations的问题.我为ProvisioningObject指定了验证属性,绑定不会查找类似的继承内容.

[MetadataType(typeof(ProvisioningObjectMetadata))]
public partial class ProvisioningObject : IProvisioningObject
{
    public string DisplayNameInvariant { get { return string.IsNullOrEmpty(this.DisplayName) ? this.Name : this.DisplayName; } }
}


[MetadataType(typeof(UserMetadata))]
public partial class User : IUser
{
}


public class ProvisioningObjectMetadata
{
    [DisplayName("Country")]
    public string CountryIsoCode { get; set; }

    [Required(ErrorMessageResourceType = typeof(Properties.Validation), ErrorMessageResourceName = "DisplayNameIsRequired")]
    [TempValidator]
    public string DisplayName { get; set; }
} …
Run Code Online (Sandbox Code Playgroud)

c# asp.net-mvc updatemodel data-annotations

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

使用C#编写Workflow Foundation工作流程

我正在尝试使用C#而不是设计器和XAML编写一些活动。VS2010一直存在错误,并且运行缓慢,并且它对编译的支持也很差(变量名称,属性等)。

因此,我试图通过直接从Activity类继承来创建活动,但是遇到了麻烦。

这是我的代码:

public class TestActivity : Activity
{
    public InArgument<string> Username { get; set; }
    public InArgument<string> Password { get; set; }
    public OutArgument<bool> ValidCredential { get; set; }
    public OutArgument<ProvisioningRole> Role { get; set; }
    public OutArgument<Guid> Guid { get; set; }

    protected override Func<Activity> Implementation
    {
        get
        {
            return () =>
                {
                    return new Sequence()
                    {
                        Activities =
                        {
                            new AuthenticateUserActivity()
                            {
                                Username = this.Username,
                                Password = this.Password,
                                Guid = this.Guid,
                                Result = this.ValidCredential
                            },
                            new If() …
Run Code Online (Sandbox Code Playgroud)

c# workflow-foundation workflow-foundation-4

0
推荐指数
1
解决办法
1627
查看次数