我正在尝试将字符串转换为布尔值.有几种方法可以做到这一点
let input = "true";
let boolVar = (input === 'true');
Run Code Online (Sandbox Code Playgroud)
这里的问题是我必须验证输入是真还是假.而不是验证第一个输入然后进行转换是否有更优雅的方式?在.NET中bool.TryParse,如果字符串无效,则返回false.打字稿中是否有相应的东西?
我正在尝试使用以下GetValue<T>方法从appsettings.json文件中读取列表:
var builder = new ConfigurationBuilder().SetBasePath(System.AppContext.BaseDirectory)
.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true);
IConfigurationRoot configuration = builder.Build();
var rr = configuration.GetValue<IList<ConnectionSettings>>("Connections");
public class ConnectionSettings
{
public string Name { get; set; }
public string Host { get; set; }
public string Account { get; set; }
public string Password { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
和我的appsettings.json
{
"Connections": [
{
"Name": "",
"Host": "192.168.1.5",
"Account": "74687",
"Password": "asdsdadsq"
},
{
"Name": "",
"Host": "127.0.0.1",
"Account": "45654",
"Password": "asdasads"
}
]
} …Run Code Online (Sandbox Code Playgroud) 我已经阅读了很多关于 Angular 文件夹结构的文章。我仍然不清楚我们把组件服务放在哪里。组件之间的共享服务被置于共享之下。但是仅由组件使用的服务呢?通常,我将所有组件逻辑都放入一个服务中,并将仅与 UI 相关的代码留给组件。哪个更好用:
每个组件和它的服务放到同一个文件夹中
.
??? app.component.html
??? app.component.ts
??? app.module.ts
??? app-routing.module.ts
??? shop
??? clients
? ??? clients.component.html
? ??? clients.component.ts
? ??? clients.component.css
? ??? clients.service.ts
??? orders
? ??? orders.component.html
? ??? orders.component.ts
? ??? orders.component.css
? ??? orders.service.ts
??? shop.module.ts
??? shop-routing.module.ts
Run Code Online (Sandbox Code Playgroud)
或服务文件夹下模块的所有服务
.
??? app.component.html
??? app.component.ts
??? app.module.ts
??? app-routing.module.ts
??? shop
??? clients
? ??? clients.component.html
? ??? clients.component.ts
? ??? clients.component.css
??? orders
? ??? orders.component.html
? ??? orders.component.ts …Run Code Online (Sandbox Code Playgroud) 我在 Windows 服务中的 EF Core 和 Autofac 上使用存储库模式。
我有一项服务需要与几十个数据库连接,这些数据库具有相同的架构(相同的 dbcontext)但只有不同的数据。如何使用 Autofac 在我的服务中实现这一目标?贝洛
public class ReportRepository : IReportRepository
{
private readonly ReportDbContext dbContext;
public ReportRepository(ReportDbContext dbContext)
{
this.dbContext = dbContext
}
public SomeModel GetData()
{
return dbContext.SalesData;
}
}
public class ReportService : IReportService
{
private readonly IReportRepository reportRepositoryEUServer;
public ReportService(IReportRepository reportRepositoryEUServer)
{
this.reportRepositoryEUServer = reportRepositoryEUServer
}
public SomeModelDto GenerateReport()
{
var euData = reportRepositoryEUServer.GetData();
// I need to call other servers (e.g LATAM) here and get the data and aggregate …Run Code Online (Sandbox Code Playgroud) 我正在使用protobuf-net序列化对象,但出现异常:
无法将更改应用于属性TestProject.TestMessage.ClientId
使用stacktrace:
at ProtoBuf.Serializers.PropertyDecorator.SanityCheck(TypeModel model, PropertyInfo property, IProtoSerializer tail, Boolean& writeValue, Boolean nonPublic, Boolean allowInternal)
at ProtoBuf.Serializers.PropertyDecorator..ctor(TypeModel model, Type forType, PropertyInfo property, IProtoSerializer tail)
at ProtoBuf.Meta.ValueMember.BuildSerializer()
at ProtoBuf.Meta.ValueMember.get_Serializer()
at ProtoBuf.Meta.MetaType.BuildSerializer()
at ProtoBuf.Meta.MetaType.get_Serializer()
at ProtoBuf.Meta.RuntimeTypeModel.Serialize(Int32 key, Object value, ProtoWriter dest)
at ProtoBuf.Meta.TypeModel.SerializeCore(ProtoWriter writer, Object value)
at ProtoBuf.Meta.TypeModel.Serialize(Stream dest, Object value, SerializationContext context)
at ProtoBuf.Meta.TypeModel.Serialize(Stream dest, Object value)
at ProtoBuf.Serializer.Serialize[T](Stream destination, T instance)
Run Code Online (Sandbox Code Playgroud)
我的课程是:
[DataContract]
public class TestMessage
{
private int clientId;
[DataMember(Order = 1)]
public int ClientId
{
get { …Run Code Online (Sandbox Code Playgroud) 我已在带有最新 resharper 的新笔记本电脑上安装了 VS2017 Enterprise 15.9.11,当我单击 Ctrl + 时。在类类型上,“快速操作和重构”菜单会打开,但缺少提取界面。
知道为什么它不显示吗?
我有一张三列的桌子。客户ID为空。
public class ProductType
{
public int Id { get; set; }
public string Name { get; set; }
public long? ClientId { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
当我运行以下代码时:
public async Task GetClientType(string productTypeName, long clientId)
{
var clientResult = await (from productType in context.ProductType
where productType.Name == productTypeName
&& productType.ClientId == clientId
select productType).FirstOrDefaultAsync();
.......
}
Run Code Online (Sandbox Code Playgroud)
尽管数据库包含此查询的结果,但我没有得到任何结果。然后,我检查了由EF Core生成的查询,并且看到生成了以下内容:
SELECT TOP(1) [productType].[Id], [productType].[Name], [productType].[ClientId]
FROM [ProductType] AS [productType]
WHERE [productType].[ClientId] IS NULL AND (([productType].[Name] = 'test client') AND ([productType].[ClientId] = 1)) …Run Code Online (Sandbox Code Playgroud) 我正在尝试映射从数据库中获得的结果,并且我有以下模型
public class ClientTest
{
public int Id { get; set; }
public string Name { get; set; }
}
public class ClientTestDto
{
public int Id { get; set; }
public string Name { get; set; }
}
public class ClientDbItem
{
public ClientTest Client { get; set; }
public Address Address { get; set; }
}
public class Address
{
public int Id { get; set; }
public string Value { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
和以下映射
CreateMap<ClientTest, ClientTestDto>(); …Run Code Online (Sandbox Code Playgroud) 我正在cmd中输入:
dotnet publish MyProject.Web.csproj --configuration Release --framework netcoreapp3.1 --runtime win-x64 --self-contained true --output '\bin\Release\netcoreapp3.1\publish'
Run Code Online (Sandbox Code Playgroud)
我收到以下错误。
C:\Program Files\dotnet\sdk\3.1.102\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Publish.targets(152,5): error MSB3094: "DestinationFiles" refers to 1 item(s), and "SourceFiles" refers to 428 item(s). They must have the same number of items. [C:\BuildAgent\work\7e7906b985af1c3\src\MyProject.Web\MyProject.Web.csproj]
Run Code Online (Sandbox Code Playgroud)
这是我的 MyProject.Web.csproj 文件
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<Authors>MyCompany Ltd</Authors>
<Company>MyCompany Ltd</Company>
<AssemblyVersion>1.0.0</AssemblyVersion>
<FileVersion>1.0.0</FileVersion>
<Version>1.0.0</Version>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Autofac" Version="5.1.4" />
<PackageReference Include="Autofac.Extensions.DependencyInjection" Version="6.0.0" />
<PackageReference Include="AutoMapper.Extensions.Microsoft.DependencyInjection" Version="7.0.0" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="3.1.3" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="3.1.3" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="3.1.3">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; …Run Code Online (Sandbox Code Playgroud) 我已经在生产机器上部署了我的应用程序。我正在发布 Release、win-x64 和 --self-contained true。我已经安装了 .net core 3.1.7 重新启动了 VPS,我得到:
未找到指定版本的 Microsoft.NetCore.App 或 Microsoft.AspNetCore.App。
dotnet --info 返回:
It was not possible to find any installed .NET Core SDKs
Did you mean to run .NET Core SDK commands? Install a .NET Core SDK from:
https://aka.ms/dotnet-download
Host (useful for support):
Version: 3.1.7
Commit: fcfdef8d6b
.NET Core SDKs installed:
No SDKs were found.
.NET Core runtimes installed:
Microsoft.AspNetCore.App 3.1.7 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.NETCore.App 3.1.7 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
To install additional .NET Core runtimes or SDKs: …Run Code Online (Sandbox Code Playgroud) c# ×8
.net ×6
.net-core ×6
asp.net-core ×2
angular ×1
autofac ×1
automapper ×1
javascript ×1
protobuf-net ×1
resharper ×1
typescript ×1