在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)不编译?
我的模板包含
<a [routerLink]="['/my-profile']" routerLinkActive="active">
<i class="icon-user"></i>{{ 'MY_PROFILE' | translate }}
</a>
Run Code Online (Sandbox Code Playgroud)
错误是因为routerLink和routerLinkActive指令.
单元测试文件.
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) 经典的一般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,一致......
我正在尝试使用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) 我无法弄清楚为什么我的视图只将模型的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) 我正在使用第三方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) 我尝试过几种不同的方法.我不确定为什么但我的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) 我希望在Azure Function的集线器启动时运行代码,并确保在该集线器中调用任何Azure功能之前执行该代码.我能这样做吗?
在这里,我使用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) 我在 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# ×6
asp.net-mvc ×3
angular ×2
asp.net-core ×2
.net ×1
asp.net ×1
azure ×1
blazor ×1
c#-6.0 ×1
eventargs ×1
events ×1
fork-join ×1
ienumerable ×1
nameof ×1
observable ×1
rxjs ×1
selectlist ×1
unit-testing ×1
web-services ×1