Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
Confusingboat authored Jun 11, 2022
1 parent 020d70a commit d4ae15d
Showing 1 changed file with 8 additions and 11 deletions.
19 changes: 8 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,34 +1,31 @@
## TryGet
# TryGet

## Simple, fluent dictionary value retrieval.

![Nuget](https://img.shields.io/nuget/v/tryget)
![Nuget](https://img.shields.io/nuget/dt/tryget)
[![.NET](https://github.com/Confusingboat/tryget/actions/workflows/dotnet.yml/badge.svg)](https://github.com/Confusingboat/tryget/actions/workflows/dotnet.yml)

### Simple, fluent dictionary value retrieval.

**As anyone familiar wth C# knows, you cannot use the `as` or `is` keyword to change or check types with the `out var` syntax.**

For example, something like this is not possible:
```csharp
var dictionary = new Dictionary<string, object>();

if (dictionary.TryGetValue("key", out as string val))
{

}
if (dictionary.TryGetValue("key", out as string val)) { }
```

**This project aims to address the above desired use case.**

## Install
# Install

Package manager console:
`install-package tryget`

Dotnet CLI:
`dotnet add package tryget`

## Quick Start
# Quick Start

```csharp
using TryGet;
Expand Down Expand Up @@ -69,7 +66,7 @@ var dictionary = new Dictionary<string, object>
};
```

#### Check if a value
### Check if a value

**...exists**
```csharp
Expand Down Expand Up @@ -127,7 +124,7 @@ if (animals.TryGet("cat").As<object>().As<Animal>().As<Cat>())
}
```

#### Get a value
### Get a value
**...if it exists**
```csharp
var val = dictionary.TryGet("number");
Expand Down

0 comments on commit d4ae15d

Please sign in to comment.