Search

Tutorials, tips&tricks, snippets..

K.I.S.S.: Keep It Simple, Stupid!

Extension Methods #4: check if object has a property

We have a lot of confortable methods ready to use in our .NET objects and this is wonderful: just think for example the method .toString()! How much do we use it? But, sometimes, these methods aren’t enough and we need to create others on our own.

Continue reading “Extension Methods #4: check if object has a property”

Extension Methods #3: get property name starting from its own name

We have a lot of confortable methods ready to use in our .NET objects and this is wonderful: just think for example the method .toString()! How much do we use it? But, sometimes, these methods aren’t enough and we need to create others on our own.

Continue reading “Extension Methods #3: get property name starting from its own name”

Extension Methods #2: toString with NULL values

We have a lot of confortable methods ready to use in our .NET objects and this is wonderful: just think for example the method .toString()! How much do we use it? But, sometimes, these methods aren’t enough and we need to create others on our own.

Continue reading “Extension Methods #2: toString with NULL values”

Extension Methods #1: truncate a string

We have a lot of confortable methods ready to use in our .NET objects and this is wonderful: just think for example the method .toString()! How much do we use it? But, sometimes, these methods aren’t enough and we need to create others on our own.

Continue reading “Extension Methods #1: truncate a string”

Generate random strings

private static Random random = new Random();
public static string RandomString(int length)
{
    const string chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
    return new string(Enumerable.Repeat(chars, length)
        .Select(s => s[random.Next(s.Length)]).ToArray());
}

HTTP POST Request with C#

In the following samples, you can find out how to send a HTTP POST request with C#. I work a lot with JSON, so here I’ll show how to send a JSON string. Here we go!

Continue reading “HTTP POST Request with C#”

HTTP GET Request with C#

In the following samples, you can find out how to send a HTTP GET request, using C# with authentication and without it. Here we go!

Continue reading “HTTP GET Request with C#”

How to enable, disable and check if Service Broker is enabled on a database

To enable Service Broker run:

ALTER DATABASE [Database_name] SET ENABLE_BROKER with rollback immediate;

To disable Service Broker:

ALTER DATABASE [Database_name] SET DISABLE_BROKER;

To check if Service Broker is enabled on a SQL Server database:

SELECT is_broker_enabled FROM sys.databases WHERE name = 'Database_name';

Parsing a JSON string in C# without creating a dedicated class

JSON is a very useful format, able to stringify all your data. It is based on the key:value pattern and it a JSON value can contains a JSON structure itself.

How can we parse a JSON string and use it like an object in C#, without having a destination class? With the following code, we are able to navigate a JSON string without defining a class for it.

Continue reading “Parsing a JSON string in C# without creating a dedicated class”

Create a free website or blog at WordPress.com.

Up ↑