Log info with tracepoints – Visual Studio (Windows) | Microsoft Docs

Tracepoints allow you to log information to the Output window under configurable conditions without modifying or stopping your code. This feature is supported for both managed languages (C#, Visual Basic, F#) and native code as well as languages such as JavaScript and Python.

Source: Log info with tracepoints – Visual Studio (Windows) | Microsoft Docs

SharpLab Online Tool – Reveal what happens during compilation of C#

SharpLab is a .NET code playground that shows intermediate steps and results of code compilation. Some language features are thin wrappers on top of other features — e.g. using() becomes try/finally. SharpLab allows you to see the code as compiler sees it, and get a better understanding of .NET languages.

Recent versions include experimental support for running code, with some limitations.

Online tool: SharpLab

Readme: https://discoverdot.net/projects/sharplab

Retry and fault handling in C# .NET

Sometimes you need to implement some sort of retry logic if an error occurs in a c# program.

Existing libraries for retry and fault handling:
Polly
http://www.thepollyproject.org/

CircuitBreaker.Net
https://github.com/alexandrnikitin/CircuitBreaker.Net

Read more about the related Circuit Breaker pattern:

CircuitBreaker
http://martinfowler.com/bliki/CircuitBreaker.html

Circuit Breaker Pattern
https://msdn.microsoft.com/en-us/library/dn589784.aspx

Error handling and policies in general:

https://en.wikipedia.org/wiki/Exception_handling#Restarts_separate_mechanism_from_policy

https://docs.microsoft.com/en-us/dotnet/standard/exceptions/

https://stackify.com/csharp-exception-handling-best-practices/

Working with Equals() and GetHashCode() to compare your objects in C#

In general these interfaces and methods are good to implement when working with comparing objects of the same type in C#:

Interfaces:
System.IEquatable<T> – strongly typed implementation
IComparable<T> – strongly typed implementation

Override methods:
An override of Object.Equals(Object).
An override of Object.GetHashCode().
An override of Object.ToString() is usually a good idea.
Operator overloads for operator == and operator !=.

General rule of GetHashCode():
If two objects is equal then their hashvalues should be the same.
E.g.:
If Equals == true then
x.GetHashCode() == y.GetHashCode()
GetHashCode() is frequently used by collections like Dictionary<Key, Value> and HashSet<T>

Links:
Guidelines for Overloading Equals() and Operator == (C# Programming Guide)
https://msdn.microsoft.com/en-us/library/ms173147.aspx

How to Check AD Group Membership using cmd/powershell

Active Directory security groups are used to grant users’ permissions to various domain services and resources. Therefore, to understand what permissions are assigned to a specific user in the AD domain, it is enough to look at the groups in which the user account is a member.

Source: How to Check AD Group Membership? – TheITBros

My Ultimate PowerShell prompt with Oh My Posh and the Windows Terminal – Scott Hanselman’s Blog

I’ve long blogged about my love of setting up a nice terminal, getting the prompt just right, setting my colors, fonts, glyphs, and more. Here’s some of my posts.

I want to take a moment to update my pretty prompt post with a little more detail and a more complex PowerShell $PROFILE, due to some changes in Oh My Posh, PowerShell, and the Windows Terminal. I doubt that this post is perfect and I’m sure there’s stuff here that is a little extra. But I like it, and this post will serve as my “setting up a new machine” post until I get around to writing a script to do all this for me in one line.

I love my prompt.

A pretty prompt in Terminal with Oh My Posh and a lot of Colors
Pre made script to make it look like Scott Hanselmans example prompt:
https://github.com/springcomp/my-box

Source: My Ultimate PowerShell prompt with Oh My Posh and the Windows Terminal – Scott Hanselman’s Blog

EditorConfig settings – Visual Studio

You can add an EditorConfig file to your project or codebase to enforce consistent coding styles for everyone that works in the codebase. EditorConfig settings take precedence over global Visual Studio text editor settings. This means that you can tailor each codebase to use text editor settings that are specific to that project. You can still set your own personal editor preferences in the Visual Studio Options dialog box. Those settings apply whenever you’re working in a codebase without an .editorconfig file, or when the .editorconfig file doesn’t override a particular setting. An example of such a preference is indent style—tabs or spaces.

Source: EditorConfig settings – Visual Studio (Windows) | Microsoft Docs

Visual Studio – Snippet for Arrange Act Assert comments

I like to comment my tests following the arrange, act, assert pattern.

E.g.
//Arrange
//Act
//Assert

Here is a snippet you can add to “your” snippets folder in Visual Studio 2019:
(or use menu Tools -> Code snippet manager to find your correct path to add to / or Import file).
Filename: C:\Users\andreasp\Documents\Visual Studio 2019\Code Snippets\Visual C#\My Code Snippets\testmethodcomment_act_arrange_assert.snippet

<?xml version="1.0" encoding="utf-8"?>
<CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
  <CodeSnippet Format="1.0.0">
    <Header>
      <SnippetTypes>
        <SnippetType>Expansion</SnippetType>
      </SnippetTypes>
      <Title>Test Method Comment - Act Arrange Assert</Title>
      <Shortcut>testaaa</Shortcut>
      <Description>Code snippet for a test method structure comments. Act arrange assert</Description>
    </Header>
    <Snippet>
      <Code Language="csharp">
    <![CDATA[//Arrange
    $end$
    
    //Act 
    
    //Assert
    ]]></Code>
    </Snippet>
  </CodeSnippet>
</CodeSnippets>

Restart Visual Studio.

Usage:
Inside testmethod, type:

testaaa [tab]

The 3 comments will be inserted, and cursor below //Arrange comment line.

Angular – How to force reload components with router navigation

(Tested in Angular 11 project)

One trick is to “double” navigate to force components to destroy and “update” their lifecycle.

E.g.:

/// Navigates to detail view
navigateToDetail(id: string) {

  // Navigates to start page first to "destroy" detail components if on same url
  this.router.navigate(['/']).then(() => {
    // Then navigates to desired url 
    let navigationExtras: NavigationExtras = { queryParams: { 'id': id} };
    this.router.navigate(['/view'], navigationExtras);
  });

}

I also added this to app-routing.module.ts: (not sure if it makes a difference with the above code)

@NgModule({
  imports: [RouterModule.forRoot(routes, {
    onSameUrlNavigation: 'reload',
  })],
  exports: [RouterModule],
})
export class AppRoutingModule {}

 

Angular component navigation doesn’t work anymore in Webstorm IDE

Please try invalidating caches (File | Invalidate caches, Invalidate and restart) – does the problem persist? Do you have @angular node_modules installed and included in project?

Also try reinstall npm packages:
npm install

Source: Angular component navigation doesn’t work anymore (webstorm) – IDEs Support (IntelliJ Platform) | JetBrains