小编she*_*mus的帖子

私人制定者打字稿?

有没有办法在TypeScript中为属性设置私有的setter?

class Test
{
    private _prop: string;
    public get prop() : string
    {
        return this._prop;
    }

    private set prop(val: string)
    {
        //can put breakpoints here
        this._prop = val;
    }
}
Run Code Online (Sandbox Code Playgroud)

编译器抱怨getter和setter的可见性不匹配.我知道我可以设置支持字段,但是当设置值时我不能设置断点.

我虽然使用接口来隐藏setter,但是接口只能定义一个属性,而不是它是否在setter上有getter.

我在这里错过了什么吗?似乎没有任何理由不允许私有的setter,结果JS不会强制执行可见性,并且似乎比当前的替代品更好.

我错过了什么吗?如果不是,没有私人制定者的充分理由?

setter accessor getter-setter typescript

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

如何将Azure Web App连接到Azure SQL数据库

Azure在一年前玩的时候发生了变化.

我有一个Web应用程序,以及我的Azure资源组中的Sql DB.我希望我的网络应用程序从我的数据库中读取.我制定了一个防火墙规则,以便我的应用程序可以从我的工作站上的数据库中读取(在本地运行),这很好.但我希望我的应用程序在部署时从数据库中读取.

我是否只是制作了一个sql防火墙规则,以便在托管到数据库时允许应用程序的IP地址?或者,有没有办法告诉azure web应用程序和同一资源组中的数据库,它是一个安全的连接?也许他们可以在内部连接上相互通信?

我认为在旧的Azure中你可以"链接"一个应用程序和一个数据库,它完成了这一点.但不确定更新的Azure中的过程是什么.

sql-server azure azure-web-sites

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

将接口上的泛型参数限制为子类

以下是人为的,但请耐心等待:

interface Clonable<TSubClass>
{
    TSubClass Clone();
}
Run Code Online (Sandbox Code Playgroud)

如何将TSubClass限制为实现类型?

即只让实现者这样做:

class Dog : Clonable<Dog>
{
    Dog Clone() 
    {
        ....
    }
}
Run Code Online (Sandbox Code Playgroud)

不是这个:

class BadDog : Clonable<Rabbit>
{
    Rabbit Clone()
    {
        ....
    }
}
Run Code Online (Sandbox Code Playgroud)

c# generics parameters restrictions

10
推荐指数
2
解决办法
1798
查看次数

具有react-router-4的路由组

我的react应用程序有3个入口点,路径重叠,并且很难维护。基本上,其中两个应用只是停留在旧站点上的几个地方,直到主应用具有足以完全替换主站点的功能为止。

我正在使用React Router 4,并且所有路由都包含一个route.tsx文件。但是我想按功能对路由进行分组,然后让每个应用程序的路由组件都能满足需要。

目前,我的路线如下所示:

const MainAppRoutes: React.SFC = (): JSX.Element =>
{
    return (
        <Switch>
            <Route exact path='/' component={HomePage} />
            <Route path='/customers' component={CustomersDisplayPage} />
            <Route path='/customers/:id' component={CustomersDisplayPage} />
            <Route path='/cars' component={CarDisplayPage} />
            <Route path='/cars/:id' component={CarDisplayPage} />
        </Switch>
    );
};
Run Code Online (Sandbox Code Playgroud)

但我希望它看起来像这样:

const MainAppRoutes: React.SFC = (): JSX.Element =>
{
    return (
        <Switch>
            <Route exact path='/' component={HomePage} />
            <CustomerAppRoutes />
            <CarAppRoutes />
        </Switch>
    );

const CustomerAppRoutes: React.SFC = (): JSX.Element =>
{
    return (
        <Switch>
            <Route path='/customers' component={CustomersDisplayPage} />
            <Route path='/customers/:id' …
Run Code Online (Sandbox Code Playgroud)

typescript reactjs react-router-v4

8
推荐指数
3
解决办法
2891
查看次数

部署时不加载RazorGenerator.Mvc.dll

使用mvc.razor生成器可以正常工作.我的图书馆项目的视图在我的网站上显示得很好.它是一个.net 4.0,MVC4,EF5项目.IIS中的应用程序池设置为.net 4.0.

当我部署到服务器时,我在尝试加载PrecompiledMvc​​Engine类型时遇到异常.这是例外(我在附件中附加了错误的完整输出):

Source Error: 

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below. 

Stack Trace: 


[ReflectionTypeLoadException: Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information.]
System.Reflection.RuntimeModule.GetTypes(RuntimeModule module) +0
System.Reflection.Assembly.GetTypes() +159
RazorGenerator.Mvc.PrecompiledMvcEngine..ctor(Assembly assembly, String baseVirtualPath) +1209
RazorGenerator.Mvc.PrecompiledMvcEngine..ctor(Assembly assembly) +53
MyProj.Common.App_Start.RazorGeneratorMvcStart.Start() in E:\UserFiles\sheam\Documents\Visual Studio 2010\Projects\MyProj\Project.Common_vs2010\App_Start\RazorGeneratorMvcStart.cs:11
Run Code Online (Sandbox Code Playgroud)

正如您所看到的,这来自我的共同项目.

以下是bin director的内容:

2012-10-17 09:06 …
Run Code Online (Sandbox Code Playgroud)

deployment asp.net-mvc-4 razorgenerator

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

数据层中的IdentityUser

我正在努力设计(或过度设计)我正在做的网络项目.

我有一个MyProject.Data,MyProject.Business和MyProject.Web DLL.

我的数据层(基于EF6)包含我的实体,db context.

我的业务层包含我的存储库(是的,可能不是真正的repo模式).

我已经将IdentityFramwork添加到Web项目中,并且cource创建了ApplicationUser.我的数据层中已有用户POCO.我想将Application用户移动到Data层,因此我可以将它与其他实体一起使用.

一种方法是让我的Data.User扩展IdentityUser,并让我的Data.MyContext扩展IdentityDbContext.这导致数据层与asp.net.identity框架强烈耦合,这种框架感觉不太对劲.

这里的最佳做法是什么?

design-patterns entity-framework repository-pattern asp.net-identity

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

在 knex 迁移中运行更新

我想向表中添加一列,然后执行一些工作来填充该列作为迁移的一部分。填充该列需要对代码进行一些操作。

考虑两个表:

  • 用户[ user_id, first_name, last_name ],和
  • 订单[ order_id, user_id, other_field_1, other_field_2 ]

和功能

    var getNickName = function(user_row) {

        //do a bunch of javascripty stuff here
        //based on user_row.first_name and user_row.last_name.
        //i.e., stuff not possible in SQL

        return 'nickname';
    }
Run Code Online (Sandbox Code Playgroud)

我想要一个 knex 迁移,将一个user_nick_name字段添加到 Orders 表。然后使用来自 的输出更新新列getNickName()

我需要这是在交易中

我知道我需要将列添加到订单,然后选择所有订单,迭代执行的订单:将用户行传递给getNickName,然后使用它来调用用户表上的更新设置值。

当涉及事务时,我似乎无法获得所有这些的 knex 语法。

postgresql bookshelf.js knex.js

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

添加属性以在 Entity Framework Core 中配置小数精度

我的 EF 6 .Net Framework 应用程序具有以下属性:

[AttributeUsage(AttributeTargets.Property)]          
public sealed class DecimalPrecisionAttribute : Attribute
{              
    public DecimalPrecisionAttribute(Byte precision, Byte scale)
    {
        Precision = precision;
        Scale = scale;
    }

    public Byte Precision { get; set; }
    public Byte Scale { get; set; }
}

public class DecimalPrecisionAttributeConvention
    : PrimitivePropertyAttributeConfigurationConvention<DecimalPrecisionAttribute>
{
    public override void Apply(
        ConventionPrimitivePropertyConfiguration configuration,
        DecimalPrecisionAttribute attribute)
    {
        if (attribute.Precision < 1 || attribute.Precision > 38)
        {
            throw new InvalidOperationException("Precision must be between 1 and 38.");
        }

        if (attribute.Scale > attribute.Precision) …
Run Code Online (Sandbox Code Playgroud)

c# entity-framework entity-framework-core

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

如何在C#中初始化静态

好的,我已经大大改变了代码,以更清楚地显示实际问题.我已经测试了这段代码,它肯定会失败.

public class MyEnumBase
{
    private int _val;

    private static Dictionary<int, MyEnumBase> ValueMap = new Dictionary<int, MyEnumBase>();

    protected MyEnumBase()
    {
        _val = ValueMap.Count;
        ValueMap.Add(_val, this);
    }

    public static MyEnumBase ValueOf(int i)
    {
        return ValueMap[i];
    }

    public static IEnumerable<MyEnumBase> Values { get { return ValueMap.Values; } }

    public override string ToString()
    {
        return string.Format("MyEnum({0})", _val);
    }
}

public class Colors : MyEnumBase
{
    public static readonly Colors Red = new Colors();
    public static readonly Colors Green = new Colors();
    public static …
Run Code Online (Sandbox Code Playgroud)

c# static initialization

4
推荐指数
1
解决办法
144
查看次数

Ajax.BeginForm导致重定向到局部视图,而不是就地

我的Search.cshtml具有一个名为“ search-results”的div,该div将被更新。SearchResults是操作名称。我已经在MVC2 / VS2008项目上做了很多次,但这是我第一次使用MVC3和VS2010。

问题是,单击提交将重定向我的部分作为独立页面,而不是在div中呈现我的搜索结果。

我已经读到这可能是因为未启用Ajax。我的_Layout.cshtml看起来像这样:

<!DOCTYPE html>
<html>
<head>
    <title>@ViewBag.Title</title>
    <script src="@Url.Content("~/Scripts/2011.2.712/jquery-1.5.1.min.js")"  type="text/javascript"></script>
    <link href="@Url.Content("~/Content/themes/base/jquery.ui.core.css")" rel="stylesheet" type="text/css" />
    <link href="@Url.Content("~/Content/themes/base/jquery.ui.datepicker.css")" rel="stylesheet"  type="text/css" />
    <link href="@Url.Content("~/Content/themes/base/jquery.ui.theme.css")" rel="stylesheet" type="text/css" />
    <link href="@Url.Content("~/Content/main.css")" rel="stylesheet" type="text/css" />
    <link href="@Url.Content("~/Content/Site.css")" rel="stylesheet" type="text/css" />
    <script src="@Url.Content("~/Scripts/2011.2.712/jquery-1.5.1.min.js")" type="text/javascript"></script>
    @(Html.Telerik().StyleSheetRegistrar().DefaultGroup(group => group.Add("telerik.common.css").Add("telerik.transparent.css").Combined(true).Compress(true))) 
</head>
<body>
    <div class="page">
        <div id="header">
            <div id="title">
                <h1>My MVC Application</h1>
            </div>

            @(Html.Telerik().Menu()
                    .Name("menu")
                    .Items(menu => {
                        menu.Add().Text("Home").Action("Index", "Home");
                        menu.Add().Text("About").Action("About", "Home");
                        menu.Add().Text("Employees").Action("List", "Employee");
                    }))
        </div>

        <div id="main">
            @RenderBody()
            <div id="footer">
            </div>
        </div>
    </div>
    @(Html.Telerik().ScriptRegistrar().DefaultGroup(group => …
Run Code Online (Sandbox Code Playgroud)

c# forms ajax asp.net-mvc razor

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