我有一个简单的登录方案,要求用户在Typescript中输入电子邮件和密码.我需要创建一些类型来获得强类型并将其发送到后端.
应该写成:
export interface UserLogin {
email: string;
password: string;
}
//OR
export class UserLogin {
email: string;
password: string;
}
Run Code Online (Sandbox Code Playgroud)
以及如何知道何时使用这些方案?
我在新的C#7中看到了var模式的这个例子
if (o is var x) Console.WriteLine($"it's a var pattern with the type {x?.GetType()?.Name}");
Run Code Online (Sandbox Code Playgroud)
只是使用有什么不同:
var x = o;
Console.WriteLine($"it's a var pattern with the type {x?.GetType()?.Name}");
Run Code Online (Sandbox Code Playgroud)
当这种模式是一个有用的解决方案.
我有一个 app.config xml 文件来保存实体框架的连接字符串,如下例所示:
<configuration>
<connectionStrings>
<add name="MyEntities" connectionString="metadata=res://*/EntityFramework.MyEntities.csdl|res://*/EntityFramework.MyEntities.ssdl|res://*/EntityFramework.MyEntities.msl;provider=System.Data.SqlClient;provider connection string="data source=myserver;initial catalog=Example;persist security info=True;user id=myId;password=myPassword;multipleactiveresultsets=false;application name=EntityFramework"" providerName="System.Data.EntityClient" />
</connectionStrings>
</configuration>
Run Code Online (Sandbox Code Playgroud)
但我使用的是 ASP.NET Core,我使用环境变量管理多个服务器。所以我需要将此连接字符串保存在我的 appsettings.{enviroment}.json 中,读取此连接并将其设置为属性实体框架上下文。
我上课了Person
:
public class Person
{
public int Id { get; set; }
public string Name { get; set; }
public void Deconstruct(out int id) { id = Id; }
}
Run Code Online (Sandbox Code Playgroud)
当我尝试使用以下代码解构它时:
var (id) = new Person();
Run Code Online (Sandbox Code Playgroud)
编译器说:
无法推断出隐式类型的解构变量'id'的类型.
当有多个参数时,编译器不会说出来.像这样:
public void Deconstruct(out int id, out string name) { id = Id; name = Name; }
var (id, name) = new Person();
Run Code Online (Sandbox Code Playgroud) 我在单线程环境中有以下过程:
int[] ages = { 40, 30, 18, 23, 60, 24 };
for (int i = 0; i < ages.Length; i++)
{
if (ages[i] < 21) ages[i] = 0;
}
Run Code Online (Sandbox Code Playgroud)
作为一个例子,但现在我想在多线程环境中执行此过程。是否有并发集合在多线程环境中模拟数组?
我有以下课程:
public class Entity
{
public string Name { get; set; }
}
public class SomethingDto
{
public string NameChanged { get; set; }
public void Mapping(Entity something)
{
NameChanged = something.Name;
}
}
Run Code Online (Sandbox Code Playgroud)
我想使用 DTO 的映射方法来创建地图,如下所示:
conf.CreateMap<Entity, SomethingDto>().ForMember(t => t.NameChanged, opt => opt.MapFrom(t => t.Name));
Run Code Online (Sandbox Code Playgroud)
AutoMapper 中有一种方法可以使用自定义方法创建地图,谁使用他的投影?
c# ×4
.net ×1
appsettings ×1
asp.net-core ×1
automapper ×1
c#-7.0 ×1
class ×1
concurrency ×1
interface ×1
mapping ×1
typescript ×1
web ×1