我认为通常优良的做法是将包含在NuGet包中的C#build生成的XML文档文件与DLL一起包含,以便为消费者提供智能感知文档.
但是,我不清楚在使用VS 2017的项目文件格式构建软件包时如何做到这一点.
这可能吗?
显然我可以切换到维护一个nuspec文件,但VS2017格式非常方便将版本和依赖项保存在一个地方.
我试图利用DefinitelyTyped存储库中的类型声明文件.其中许多文件使用以下模式:
export = React;
export as namespace React;
Run Code Online (Sandbox Code Playgroud)
谷歌搜索,我发现这个引用用于制作一个可用于基于模块和非基于模块的系统的声明文件.但是,我正在努力找到一个明确的解释:(a)这些线路各自确切地做了什么,以及(b)这种组合究竟是如何工作来支持这两类消费者的.
我试图使用Json.NET和自定义JsonConverter对象反序列化一个类.该类当前使用JsonConverterAttribute为默认序列化定义转换器.我需要通过传入自定义转换器来进行自定义反序列化.但是,反序列化似乎仍然使用默认转换器.如何让Json.NET更喜欢我的自定义转换器?
以下是一些演示此问题的示例代码.我正在使用NewtonSoft.Json 4.5.11:
void Main()
{
JsonConvert.DeserializeObject<Foo>("{}"); // throws "in the default converter"
var settings = new JsonSerializerSettings { Converters = new[] { new CustomConverter() } };
JsonConvert.DeserializeObject<Foo>("{}", settings); // still throws "in the default converter" :-/
}
[JsonConverter(typeof(DefaultConverter))]
public class Foo {
}
public class DefaultConverter : JsonConverter {
public override bool CanConvert(Type objectType)
{
return typeof(Foo).IsAssignableFrom(objectType);
}
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
{
throw new Exception("in the default converter!");
}
public override …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用Roslyn来确定项目公开的API(然后使用这些信息做一些进一步的处理,所以我不能只使用反射).我正在使用SyntaxWalker访问声明语法节点,并为每个节点调用IModel.GetDeclaredSymbol.这似乎适用于方法,属性和类型,但它似乎不适用于字段.我的问题是,如何为FieldDeclarationSyntax节点获取FieldSymbol?
这是我正在使用的代码:
public override void VisitFieldDeclaration(FieldDeclarationSyntax node)
{
var model = this._compilation.GetSemanticModel(node.SyntaxTree);
var symbol = model.GetDeclaredSymbol(node);
if (symbol != null
&& symbol.CanBeReferencedByName
// this is my own helper: it just traverses the publ
&& symbol.IsExternallyPublic())
{
this._gatherer.RegisterPublicDeclaration(node, symbol);
}
base.VisitFieldDeclaration(node);
}
Run Code Online (Sandbox Code Playgroud) 假设你有一个像这样的简单类:
class MyClass
{
private readonly int a;
private int b;
public MyClass(int a, int b) { this.a = a; this.b = b; }
public int A { get { return a; } }
public int B { get { return b; } }
}
Run Code Online (Sandbox Code Playgroud)
我可以以多线程方式使用这个类:
MyClass value = null;
Task.Run(() => {
while (true) { value = new MyClass(1, 1); Thread.Sleep(10); }
});
while (true)
{
MyClass result = value;
if (result != null && (result.A != 1 || …Run Code Online (Sandbox Code Playgroud) 我发现EF的缓慢启动时间的一个重要组成部分可能与从数据库中获取提供者信息有关.在运行集成测试或进行其他迭代开发时,这非常烦人.任何人都可以解释为什么获取提供者信息很慢或可能做些什么呢?我们正在使用EF5.
这是一个演示此行为的示例:
void Main()
{
Database.SetInitializer<ModelDbContext>(null);
Database.SetInitializer<ModelCreatingDbContext>(null);
// passing the provider information in is very fast
var sw2 = Stopwatch.StartNew();
var builder = new DbModelBuilder();
builder.Entity<SqlConnectionStringBuilder>().HasKey(c => c.ConnectionString).ToTable("strings");
var q2 = new ModelDbContext(builder.Build(new DbProviderInfo("System.Data.SqlClient", "2008")).Compile()).Set<SqlConnectionStringBuilder>().Take(1).ToString();
Console.WriteLine(sw2.Elapsed); // < 1 second
// letting EF determine it from the connection string is sometimes very slow
var sw1 = Stopwatch.StartNew();
var q = new ModelCreatingDbContext().Set<SqlConnectionStringBuilder>().Take(1).ToString();
Console.WriteLine(sw1.Elapsed); // can be upwards of 13 seconds!
}
public class ModelDbContext : DbContext {
public static readonly …Run Code Online (Sandbox Code Playgroud) .NET参考源显示as 的实现NextBytes():
for (int i=0; i<buffer.Length; i++)
{
buffer[i]=(byte)(InternalSample()%(Byte.MaxValue+1));
}
Run Code Online (Sandbox Code Playgroud)
InternalSample在[0,int.MaxValue)中提供了一个值,正如它的doc注释所证明的那样Next(),记录为返回此范围的事实,只需调用InternalSample.
我担心的是,由于InternalSample可以产生int.MaxValue不同的值,并且该数字不能被256整除,因此我们应该在结果字节中有一些轻微的偏差,其中一些值(在这种情况下只有255)的发生频率低于其他值.
我的问题是:
我所知道的Random,不应该用于加密目的; 我在想它是有效的用例(例如模拟).
我正在尝试减少基于EF的应用程序的启动时间,但我发现即使对于单实体上下文,我也无法将初始读取所花费的时间减少到7秒以下.特别奇怪的是,这个时间不是特定于上下文类型的.
任何人都可以解释是什么导致这些缓慢的时间和/或我如何让事情更快地运行?
这是完整的示例代码:
在我的数据库中,我有一个名为se_stores的表,其主键列为AptId:
// a sample entity class
public class Apartment
{
public int AptId { get; set; }
}
// two identical DbContexts
public class MyDbContext1 : DbContext
{
public MyDbContext1(string connectionString) : base(connectionString)
{
}
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
Database.SetInitializer<MyDbContext1>(null);
var config = new EntityTypeConfiguration<Apartment>();
config.HasKey(a => a.AptId).ToTable("se_stores");
modelBuilder.Configurations.Add(config);
base.OnModelCreating(modelBuilder);
}
}
public class MyDbContext2 : DbContext
{
public MyDbContext2(string connectionString)
: base(connectionString)
{
}
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
Database.SetInitializer<MyDbContext2>(null);
var config = …Run Code Online (Sandbox Code Playgroud) 我有一个Autofac容器,我希望能够检索所有已注册的服务类型(不是实现类型,而是它们注册的类型).
如何从中获取此信息IComponentContext?
c# ×8
linq ×2
.net ×1
autofac ×1
json.net ×1
memory-model ×1
nuget ×1
performance ×1
random ×1
roslyn ×1
sql-server ×1
typescript ×1
volatile ×1