我在 Blazor 项目中使用第二个程序集。工作正常。但是两个程序集都有一个负责“/”路由的页面。引用的公共库中的公共索引页面和启动剃刀应用程序中的自定义索引页面。我如何告诉启动应用程序“/”应该仅由位于其自己的程序集中的页面提供?
自定义组件的应用程序代码:
<Router AppAssembly="@typeof(Program).Assembly" AdditionalAssemblies="new[] { typeof(Common.Server.Program).Assembly } ">
Run Code Online (Sandbox Code Playgroud)
我收到以下错误:
处理请求时发生未处理的异常。InvalidOperationException:以下路由不明确:“Specific.Server.Pages.Index”中的“/”“Common.Server.Pages.Index”中的“/”
这完全有道理,但我该如何处理呢?
使用 CountAsync 或 AsyncEnumerable CountAwaitAsync 有什么区别?
在AsyncEnumerable.cs中有:
public static ValueTask<int> CountAwaitAsync<[Nullable(2)] TSource>(
[Nullable(1)] this IAsyncEnumerable<TSource> source,
[Nullable(new byte[] {1, 1, 0})] Func<TSource, ValueTask<bool>> predicate,
CancellationToken cancellationToken = default (CancellationToken));
Run Code Online (Sandbox Code Playgroud)
两者对我来说都毫无意义,但我确信这是有道理的。我不明白。
即使我说 return 204 (NoContent),它也会返回 200。为什么?
app.MapGet("/api/alive", (context) => Task.FromResult(new StatusCodeResult(204)));
Run Code Online (Sandbox Code Playgroud)
浏览器中的状态码为200
Ich 有一个方法 ThrowNull 覆盖有DoesNotReturn 属性,表明该方法永远不会返回。
[DoesNotReturn]
public static void ThrowNull([InvokerParameterName] string argName, string? customErrorText = null, [CallerMemberName] string callerName = "") => throw new ArgumentException(AddMethodName(customErrorText != null ? customErrorText.InsertArgs(argName) : Strings.ArgumentMustNotBeNullArgumentTemplate.InsertArgs(callerName), callerName), customErrorText == null ? argName : null);
Run Code Online (Sandbox Code Playgroud)
但是,它似乎不起作用(按预期)
public static T ThrowIfNullOrGet<T>([MaybeNull, NotNullIfNotNull("source")] this T source, string argName, string? customErrorText = null, [CallerMemberName] string callerName = "") where T : class
{
if (source != null)
return source;
Requires.ThrowNull(argName, customErrorText, callerName);
return default; // still necessary to prevent …Run Code Online (Sandbox Code Playgroud) IAsyncEnumerable不可能运行两次枚举?
一旦CountAsync运行,await foreach就不会枚举任何项目。为什么?上好像没有 Reset 方法AsyncEnumerator。
var count = await itemsToImport.CountAsync();
await foreach (var importEntity in itemsToImport)
{
// won't run
}
Run Code Online (Sandbox Code Playgroud)
数据来源:
private IAsyncEnumerable<TEntity> InternalImportFromStream(TextReader reader)
{
var csvReader = new CsvReader(reader, Config);
return csvReader.GetRecordsAsync<TEntity>();
}
Run Code Online (Sandbox Code Playgroud) 在哪里点razor文件夹“_framework”和“_content”?
_host.cshtml
<script src="_framework/blazor.server.js"></script>
<script src="_content/BlazorInputFile/inputfile.js"></script>
Run Code Online (Sandbox Code Playgroud)
没有 inputfile.js 也没有 BlazorInputFile 文件夹
9.0 记录如何实现对象属性(如数组)的基于值的相等性?
我注意到,尽管所有字节都相同,但具有时间戳属性(字节数组)的两个相同类型的记录对象不被识别为相等。
例子:
public record C
{
public byte[] Timestamp {get; set;}
}
Run Code Online (Sandbox Code Playgroud)
将实现为
public virtual bool Equals(C other)
{
return (...) && EqualityComparer<byte[]>.Default.Equals(<Timestamp>k__BackingField, other.<Timestamp>k__BackingField);
}
Run Code Online (Sandbox Code Playgroud)
它使用不使用 SequenceEquals 的 EqualityComparer 因此结果是具有相同内容的两个记录不相等。
using System.Collections.Generic;
using System.Diagnostics;
var a = new byte[1] { 1 };
var b = new byte[1] { 1 };
var isEqual = EqualityComparer<byte[]>.Default.Equals(a, b);
Debug.Print(isEqual.ToString()); // false
Run Code Online (Sandbox Code Playgroud)
我认为记录会为每个属性实现基于值的平等,但这显然仍然是基于数组的引用。我是在错误的轨道上还是就这样?
是否可以为多个组件创建某种组件范围的 CSS 文件而不重复它?有什么命名约定吗?
假设有三个组件都使用相同的标签,但样式只能应用于命名方案的组件ComponentA。其他组件不应受到影响。
ComponentA_A.razor
ComponentA_B.razor
ComponentOther.razor
Run Code Online (Sandbox Code Playgroud)
拥有
ComponentA.razor.css
Run Code Online (Sandbox Code Playgroud)
代替
ComponentA_A.razor.css
ComponentA_B.razor.css
Run Code Online (Sandbox Code Playgroud)
如果复制是唯一的方法,是否可以在 css 文件本身中使用某种引用或在 blazor 组件中引用特定的 css 文件?
c# ×9
asp.net-core ×2
blazor ×2
c#-8.0 ×2
.net-6.0 ×1
async-await ×1
c#-9.0 ×1
razor ×1
razor-pages ×1