26 热度

Removing ALL assembly names in Json.NET TypeNameHandling output

In some cases, it may be desirable to include type name information in Json.NET output but for those type names to not include assembly names. In my case it's because I have a Shared Project that contains classes that I want to appear in my .NET Core C# server code and in my Bridge.NET client code and this results in the class names existing in assemblies with different names (but there are also other people with their own cases, such as How do I omit the assembly name from the type name while serializing and deserializing in JSON.Net?.

收录时间: 2020-08-06
分类: .NET
贡献者: Rector
26 热度

Roslyn 读取 PackageReference 的版本号和内容

在写 msbuild 的预编译逻辑,如果想要拿到项目安装的 NuGet 库和版本,可以通过获取 PackageReference 的方法获取。获取方法是放在 Target 里面,如下面代码...

收录时间: 2020-08-06
分类: .NET
贡献者: Rector
36 热度

Best way to create an empty collection (array and list) in C# (.NET)

I one of APIs I was working a while back I needed to return an empty collection. It was not a performance critical code, yet I decided what would be the best way to do it. Exploring and learning. The signature required me to return List, but I started with testing arrays first. I expected Array.Empty to be clear winner, but I was also interested how other “common” ways stack up.

收录时间: 2020-08-05
分类: .NET
贡献者: Rector
33 热度

OpenTelemetry .NET Beta Released!

Today, we are happy to announce that the OpenTelemetry .NET SDK has reached beta. This means that you can now begin integrating the OpenTelemetry .NET SDK into your applications and libraries to capture and export metrics and traces.

收录时间: 2020-08-04
分类: .NET
贡献者: Rector
27 热度

Working efficiently with legacy database using Dapper

A year ago I started working on a set of projects that requires accessing data from a huge legacy database. There was a decision to use Dapper to facilitate database access code. For those of you who are not familiar with Dapper, it’s a set of extension methods to IDbConnection, which allows to easily map C# object to SQL query parameters, as well as SQL query result to C# objects. I was quite skeptical to use a library that requires writing SQL queries directly in the C# code, because I got used to relying always on ORMs (NHibernate in particular). Throughout the year, Dapper has proven to be the right tool for the job. In the meantime, I also discovered a couple of features and tricks that allow me to write quite concise and easy to maintain database access code, and I think it’s worth sharing them here.

收录时间: 2020-08-04
分类: .NET
贡献者: Rector
25 热度

Cleaner tests with XUnit's IAsyncLifetime and expression-bodied members

When writing tests, sometimes it can be tempting to dump a bunch of asserts into the same test to avoid duplication across multiple tests...

收录时间: 2020-08-04
分类: .NET
贡献者: Rector
AD 友情赞助
39 热度

Learn about the latest .NET Productivity features

The .NET Productivity team (a.k.a. Roslyn) is constantly thinking of new ways to make .NET developers more productive. We’ve been working hard to take the feedback you’ve sent us and turn it into tools that you want! In this post, I’ll cover some of the latest .NET productivity features available in Visual Studio 2019.

收录时间: 2020-07-31
分类: .NET
贡献者: Rector
47 热度

Tales from the Evil Empire - LunrCore, a lightweight search library for .NET

I'm pretty much convinced almost all applications need search. No matter what you're building, you'll likely handle data, and no matter how well you organize it, a good text search is often the fastest way for your users to find what they're looking for. As such, search should be a commodity, a feature that should be as easy as possible to integrate. I'm so convinced of that in fact that my day job is on Azure Cognitive Search, a Microsoft product that provides search as a service and makes indexing smart by adding a customizable pipeline of AI and machine learning enrichments.

收录时间: 2020-07-28
分类: .NET
贡献者: Rector
41 热度

Calling Generic Methods from Non-Generic Code in .Net

Somewhat often (or at least it feels that way this week) I’ll run into the need to call a method with a generic type argument from code that isn’t generic. To make that concrete, here’s an example from Marten. The main IDocumentSession service has a method called Store() that directs Marten to persist one or more documents of the same type. That method has this signature...

收录时间: 2020-07-28
分类: .NET
贡献者: Rector
58 热度

.NET Framework July 2020 Cumulative Update Preview

Today, we are releasing the July 2020 Cumulative Update Preview Updates for .NET Framework.

收录时间: 2020-07-24
分类: .NET
贡献者: Rector
45 热度

Stop throwing Exceptions! Start being Explicit

If you’re writing a library for other developers to consume on NuGet or if you’re creating an API within your own project, stop throwing exceptions and start being explicit. Exceptions are like landmines. Consuming callers have absolutely no idea what exceptions you might throw or how/when/why they will step on one. C# is dishonest when it comes to looking at method signatures.

收录时间: 2020-07-23
分类: .NET
贡献者: Rector
36 热度

Look Behind the IQueryable Curtain

In a previous blog post, I explored the power of expressions and used them to dynamically build a rules engine based on a JSON payload. In this post I flip everything upside down and start with the expression. Given the variety of possible expression types and complexity of expression trees, what is the best way to decompose the tree? And, while we’re at it, can we mutate the expression to make it behave differently? I’ll explain why that’s important.

收录时间: 2020-07-23
分类: .NET
贡献者: Rector
42 热度

New Preview of WinUI 3, Native UI Platform of Windows, Fixes Stuff

Microsoft shipped preview 2 of WinUI, the UI framework that uses Fluent Design to provide a native user experience (UX) framework for both Windows Desktop (Win32) and Universal Windows Platform (UWP) applications, focusing on stability and bug fixes.

收录时间: 2020-07-21
分类: .NET
贡献者: Rector
50 热度

How to get the SyntaxNode of an ISymbol using Roslyn

In this post, I’ll describe how to determine if a property is an auto-property, using its ISymbol as the source, and not by using reflection into Roslyn which computes this information internally. During the original development of the Uno CodeGen source generators, when building the Immutable generators (soon to be deprecated by the records feature in C# 9.0), we had to determine if a property’s backing field is generated or not.

收录时间: 2020-07-21
分类: .NET
贡献者: Rector
40 热度

Exploring the .NET open source hybrid ORM library RepoDB

It's nice to explore alternatives, especially in open source software. Just because there's a way, or an "official" way doesn't mean it's the best way. Today I'm looking at RepoDb. It says it's "a hybrid ORM library for .NET. It is your best alternative ORM to both Dapper and Entity Framework." Cool, let's take a look.

收录时间: 2020-07-21
分类: .NET
贡献者: Rector
AD 友情赞助
46 热度

Cross-Platform Real-Time Communication with Uno & SignalR

In this article we will see how to use Uno Platform and SignalR to create applications that run on all major platforms - PC, Mac, Android, iOS and Web - and are capable of receiving real-time updates from a SignalR service. As you will see, these two technologies work incredibly well together, providing an elegant solution to a use-case which, just a few years ago, would have been fiendishly difficult.

收录时间: 2020-07-18
分类: .NET
贡献者: Rector
44 热度

Announcing WinUI 3 Preview 2

At our monthly community call this morning we announced that a new preview of WinUI 3 is ready for you all to try out – WinUI 3 Preview 2! If you’re too excited to read ahead, check out the release notes here. WinUI 3 Preview 2 was a quality and stability-driven release. It builds directly on Preview 1 by fixing quite a few critical and serious bugs that didn’t make the cut in time for our release at Build 2020 two months ago. The team wanted to put together a small release post-Build to make sure that WinUI 3 is stable and easy to use for everyone. Our community dove right into using Preview 1 and you all provided us with tons of valuable feedback, specifically regarding the critical bugs that you found. This feedback, in addition to the team’s known issues from Preview 1, drove us towards creating the long list of bugs that we set out to fix for this release.

收录时间: 2020-07-18
分类: .NET
贡献者: Rector
68 热度

Bypassing Polymorphism with Reflection in .NET

While implementing support for interface default implementations in NUKE we’ve added the new fluent methods Base and Inherit. In order to let an overridden target inherit from its base declaration (or a re-implemented target with default implementation), we needed to make non-virtual calls using reflection. This wasn’t exactly easy, since even when reflecting on a member through its declaring type, it will follow the principle of polymorphism and call the member virtual. With a bit of Stack Overflow, we ended up implementing the following generic method...

收录时间: 2020-07-15
分类: .NET
贡献者: Rector
51 热度

Understanding How Assemblies Load in C# .NET

For better or for worse, a senior .NET developer needs to understand how the .NET runtime loads assemblies. We are constantly dealing with libraries and NuGet packages. These libraries depend on other popular libraries and there are a lot of shared dependencies. With a large enough web of dependencies, you’ll eventually get into conflicts or hard situations.

收录时间: 2020-07-14
分类: .NET
贡献者: Rector
59 热度

A .NET Color Console Helper

In this post I'll discuss a small Console helper class I've been using to make it easier and more consistent to use colors with the .NET Console command. While colors are easy enough to access in the Console, to switch colors is a bit of a pain with the plain Console API. The simple class I present here makes it easier to write a line or string in a given color, write a line with multiple colors (using simple [color]text[/color] templating) and an easy way to create a header. The following is a very simple ColorConsole class that provides some useful color helpers...

收录时间: 2020-07-14
分类: .NET
贡献者: Rector
AD 友情赞助