小编Mas*_*aus的帖子

为什么不允许使用nameof(object)?

在C#6.0中,您可以这样写:

var instance = default(object);
var type = typeof(object);
Run Code Online (Sandbox Code Playgroud)

他们有相同的结果:

var instance = default(System.Object);
var type = typeof(System.Object);
Run Code Online (Sandbox Code Playgroud)

但你不能写这个:

var name = nameof(object);
Run Code Online (Sandbox Code Playgroud)

它会生成以下错误:

表达式术语"对象"无效.

但是你仍然可以这样写:

var name = nameof(System.Object);
Run Code Online (Sandbox Code Playgroud)

为什么nameof(object)不编译?

c# c#-6.0 nameof

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

Angular 2单元测试:无法读取未定义的属性"root"

我的模板包含

<a [routerLink]="['/my-profile']" routerLinkActive="active">
    <i class="icon-user"></i>{{ 'MY_PROFILE' | translate }}
</a>
Run Code Online (Sandbox Code Playgroud)

错误是因为routerLinkrouterLinkActive指令.

单元测试文件.

TestBed.configureTestingModule({
    imports: [
        MultilingualModule, CommonModule,
        RouterTestingModule.withRoutes([
            { path: 'my-profile', component: MockComponent },
            { path: 'change-password', component: MockComponent },
        ])
    ],
    schemas: [ NO_ERRORS_SCHEMA ],
    declarations: [TopNavigationBarComponent, TestComponent,MockComponent],
    providers: [
        { provide: LoginService, useValue: MockLoginService },
        { provide: Router, useClass: RouterStub }
    ]
});
Run Code Online (Sandbox Code Playgroud)

unit-testing karma-jasmine angular

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

EventArgs作为事件模式中的基类的目的是什么?

经典的一般C#事件具有以下参数:

(object sender, EventArgs e)
Run Code Online (Sandbox Code Playgroud)

我可以为e参数实现一个具有更具体签名的事件,派生EventArgs.

现在,基类的目的是什么EventArgs?我的意思是......它是空的.没有基础/抽象/虚拟属性,也没有字段或其他内容.

为什么基本事件的参数不像下面那样?

(object sender, object eventArgs)
Run Code Online (Sandbox Code Playgroud)

也就是说,为什么所有带有一些已实现和特定的event-args参数的事件都是EventArgs从一个简单的派生而不是从一个简单派生出来的object

上述问题与以下问题相对应.通用表单中的事件委托是:

delegate void EventHandler<TEventArgs>(object sender, TEventArgs e)
Run Code Online (Sandbox Code Playgroud)

并且对参数没有限制e.但是我会期待类似的东西where TEventArgs : EventArgs,一致......

.net c# events eventargs

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

Blazor 绑定值:事件 oninput

我正在尝试使用EditForm.

出于某种原因,oninput如果使用InputText,似乎不会调用该事件,但它使用一个简单的input元素工作。

我错过了什么吗?

这是一个 HTML 示例:

<EditForm Model="@Model" OnValidSubmit="@OnValidSubmit" id="authorize">
    <h1 class="mb-3">
       <span class="d-block">Authorize</span>
    </h1>
    <DataAnnotationsValidator />
    <div class="form-group">
        <label class="sr-only" for="AuthorizeUsername">Username</label>
        <div class="input-group mb-2">
            <div class="input-group-prepend">
                <div class="input-group-text"><i class="fas fa-user"></i></div>
            </div>
            <InputText type="text" class="form-control" id="AuthorizeUsername" placeholder="Username" @bind-value="@Model.Username" @bind-value:event="oninput" />
        </div>
    </div>
    <div class="form-group">
        <label class="sr-only" for="AuthorizePassword">Password</label>
        <div class="input-group mb-2">
            <div class="input-group-prepend">
                <div class="input-group-text"><i class="fas fa-asterisk"></i></div>
            </div>
            <InputText type="password" class="form-control" id="AuthorizePassword" placeholder="Password" @bind-value="@Model.Password" @bind-value:event="oninput" />
        </div>
    </div>
    <div class="form-group">
        <ValidationSummary />
        <button …
Run Code Online (Sandbox Code Playgroud)

c# blazor

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

Asp.Net MVC:为什么我的视图将NULL模型传递回我的控制器?

我无法弄清楚为什么我的视图只将模型的NULL传回给我的控制器.这适用于Edit Post方法.我使用Edit Post方法检查了其他控制器,其结构与此相同,并且它们工作正常.它似乎只是这个视图和控制器.

这是我的观点:

@model Non_P21_Quote_System_v1._0.Models.gl_code

@{
    ViewBag.Title = "Edit";
    Layout = "~/Views/Shared/_Layout.cshtml";
}

<h2>Edit</h2>

@if (TempData["Message"] != null)
{
    <div style="color:green">
        @TempData["Message"]
    </div><br />
}
@if (ViewBag.error != null)
{
    <div style="color:red">
        <h3>@ViewBag.error</h3>
    </div><br />
}

@using (Html.BeginForm())
{
    @Html.AntiForgeryToken()

    <div class="form-horizontal">
        <h4>gl_code</h4>
        <hr />
        @Html.ValidationSummary(true, "", new { @class = "text-danger" })
        @Html.HiddenFor(model => model.ID)

        <div class="form-group">
            @Html.LabelFor(model => model.GL_code, "GL Code", htmlAttributes: new { @class = "control-label col-md-2" })
            <div class="col-md-10">
                @Html.EditorFor(model => model.GL_code, new { htmlAttributes …
Run Code Online (Sandbox Code Playgroud)

asp.net-mvc

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

如何使用标头将对象序列化为string\xml

我正在使用第三方Web服务客户端(使用"添加服务引用"创建)以检索某些数据.

在使用适当的数据填充Web服务对象后,我们需要向标头添加一些数据(加密密码和一些其他预定义数据)

然后,我们使用标准.net序列化发送到Web服务的每个请求XmlSerializer.

但是,在序列化的结果中,我没有看到请求的标头.我已经搜索了很长时间,也找不到任何方法来"打印"它们.

这是一些示例代码:

Ibooking proxy = new BookingManager();

/* Init proxy Data...*/
GetAvailabilityRequest request = new GetAvailabilityRequest();

/*Fill more data on the request...*/
GetAvailabilityResponse response = proxy.GetAvailability(request); //Send request to the web service
var xmlString2 = response.Serialize(); //only body, no headers in the XML


/* Extension class to Serialize any object */
public static class ExtensionUtil
{
    public static string Serialize<T>(this T value)
    {
        try
        {
            XmlSerializer  xmlserializer = new XmlSerializer(typeof(T));
            var stringWriter = new StringWriter(); …
Run Code Online (Sandbox Code Playgroud)

c# serialization web-services

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

在ASP.NET Core中的SelectList中显示数据

我尝试过几种不同的方法.我不确定为什么但我的SelectList/DropDown是空的.它没有显示数据.我不确定我哪里出错了.

我有一个ASP.NET核心应用程序.实体框架核心.Db首先.我正在使用存储库模式.

这是我的模型类

public partial class Commodity
{
    public Guid Oid { get; set; }
    public string Code { get; set; }
}
Run Code Online (Sandbox Code Playgroud)

这是我的界面:

interface ICommodityRepository
{
    IEnumerable<Commodity> GetAll();
}
Run Code Online (Sandbox Code Playgroud)

我的存储库:

public class CommodityRepository : ICommodityRepository
{
    private ltgwarehouseContext context;

    public CommodityRepository()
    { }

    public IEnumerable<Commodity> GetAll()
    {
        return context.Commodity.ToList();
    }
}
Run Code Online (Sandbox Code Playgroud)

我的控制器:

public class CommoditiesController : Controller
{
    static readonly CommodityRepository commodities = new CommodityRepository();

    public CommoditiesController(CommodityRepository commodities)
    { }

    // GET: /<controller>/
    public IEnumerable<Commodity> CommoditiesList()
    {
        return commodities.GetAll(); …
Run Code Online (Sandbox Code Playgroud)

c# asp.net-mvc ienumerable selectlist asp.net-core

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

是否可以在Azure功能的Hub启动时运行代码?

我希望在Azure Function的集线器启动时运行代码,并确保在该集线器中调用任何Azure功能之前执行该代码.我能这样做吗?

azure azure-functions

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

顺序订阅一系列可观察对象

在这里,我使用forkJoinrxjs来并行地订阅一个可观察对象数组。但是我要一个一个地订阅,什么是最好的解决方案?

下面是我的代码:

var observables = [];

Observable.forkJoin(observables)
    .subscribe(() => {
        this.msgs = [];
        this.msgs.push({
            severity: 'success',
            summary: 'Saved Successfully'
        });
        this.onSaveComplete();
    }, (error: any) => this.errorMessage = <any>error);
}, (error: any) => this.errorMessage = <any>error);
Run Code Online (Sandbox Code Playgroud)

fork-join observable rxjs angular

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

Blazor:System.InvalidOperationException:“RemoteNavigationManager”尚未初始化

我在 ASP.NET Core MVC 3.1 网站上使用 Blazor 服务器来处理某些需要 Blazor 功能的组件。一切正常,但是,我无法从 Blazor 组件导航到 ASP.NET MVC 路由。

为了导航,我设置了以下属性:

[Inject]
public NavigationManager NavigationManager { get; set; }
Run Code Online (Sandbox Code Playgroud)

当我打电话时NavigationManager.NavigateTo("/games/details/" + gameId, true),出现以下错误:

错误:System.InvalidOperationException:“RemoteNavigationManager”尚未初始化。在 Microsoft.AspNetCore.Components.NavigationManager.AssertInitialized() 在 Microsoft.AspNetCore.Components.NavigationManager.NavigateTo(String uri, Boolean forceLoad) 在 MyWebSite.Web.Pages.Search.SearchBar.GoToGamePage(Int32 gameId) 在 D:\repos \MyWebSite\src\MyWebSite.Web\Pages\Search\SearchBar.razor.cs: 第 58 行位于 D:\repos\MyWebSite\src\MyWebSite 中的 MyWebSite.Web.Pages.Search.SearchBar.<>c__DisplayClass47_0.b__5() .Web\Pages\Search\SearchBar.razor:第 22 行,位于 Microsoft.AspNetCore.Components.EventCallbackWorkItem.InvokeAsync[T](MulticastDelegate 委托,T arg),位于 Microsoft.AspNetCore.Components.ComponentBase.Microsoft.AspNetCore.Components.IHandleEvent。 Microsoft.AspNetCore.Components.RenderTree.Renderer.DispatchEventAsync(UInt64 eventHandlerId、EventFieldInfo fieldInfo、EventArgs eventArgs)的 HandleEventAsync(EventCallbackWorkItem 回调,对象 arg)

我发现的有关 NavigationManager 的所有内容都适用于 Blazor Web 项目,而不是带有 Blazor 组件的 ASP.NET Core MVC。

c# asp.net asp.net-mvc asp.net-core blazor-server-side

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