Skip to content

Instantly share code, notes, and snippets.

View jpenniman's full-sized avatar

Jason Penniman jpenniman

View GitHub Profile
@jpenniman
jpenniman / no-yield.cs
Created August 7, 2022 14:25
IEnumerable return yield
public IEnumerable<Person> GetPeople()
{
var list = new List<Person>();
// database connection/command logic removed for brevity
while (reader.Read())
{
var person = MapPerson(reader);
list.Add(person);
}
return list;
string term = "Acme";
int skip = 0;
int take = 100;
IVendorLookup lookup = new VendorLookup();
PagedVendorLookupResult pageOfResults = await lookup.FindByCompanyNameStartingWithAsyc(term, skip, take);
pageOfResults.TotalCount.Should().Be(1);
pageOfResults.VendorLookupResults[0].CompanyName.Should().Be("Acme Supply");
@jpenniman
jpenniman / IOptions.cs
Last active May 12, 2022 21:15
Configuration Reloading
var config = new ConfigurationBuilder()
.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)
.Build();
var container = new ServiceCollection()
.AddOptions()
.Configure<Foo>(config.GetSection("Foo"))
.BuildServiceProvider();
var options = container.GetRequiredService<IOptions<Foo>>();
float f1 = 123.453123f;
double d1 = 123.453123;
decimal m1 = 123.453123m;
Console.WriteLine(f1 * 100.0f);
Console.WriteLine(d1 * 100.0);
Console.WriteLine(m1 * 100.0m);
//12345.3125
//12345.312300000001
static class Program
{
static void Main()
{
Console.WriteLine("Hello");
}
}