Skip to content

Instantly share code, notes, and snippets.

@marbel82
marbel82 / ienumerable_urnoll_recursive_structure.md
Last active June 30, 2020 07:54
How to unroll a recursive structure and return as IEnumerable

NSubstitute - łatwiejsze mockowanie

0) Example code

Mamy daną klasę Calculator, która umożliwia operację dodawania Add(). W trakcie dodawania aktualny stan akumulatora jest drukowany za pomocą interfejsu IPrinter.

public interface IPrinter
{
 void Print(string text);
@marbel82
marbel82 / can_i_implement_traits_in_CS8.md
Last active March 9, 2020 09:27
Can I implement Traits with C#8?

Can I implement Traits with C#8?

    public interface IInterface1
    {
        public void WhoAmI()
        {
            Trace.WriteLine("I am IInterface1");
        }
    }
@marbel82
marbel82 / DataContextChanged_CreateHandlerForAssigningVToVM.cs
Created March 4, 2020 13:26
Replacement of DataContextChanged handler defined locally for generic
public class CarViewModel
{
public ICarView View { get; set; }
}
//============================================================
// Before
public class CarView : UserControl, ICarView
@marbel82
marbel82 / WPF_DataGrid_Cancel_row_edition.md
Last active March 5, 2020 10:23
WPF DataGrid: Show CancelEdit button when row is in edit mode + Cancel row edition
@marbel82
marbel82 / 7zip_has_better_compression.md
Created August 7, 2018 13:22
7zip has better compression

Tested folder size:

4,680 GB (38581 files)

Application After Time Speed
7zip / Ultra[➀][asterisk] 122 MB 16:00 min 5 MB/s need 10GB RAM
7zip / Normal 184 MB 3:20 min 24 MB/s need 1GB RAM
7zip / Fastest 379 MB 0:50 min 94 MB/s
@marbel82
marbel82 / EnumGetValuesCastBenchmark.md
Last active August 18, 2022 13:18
When we iterate on the Enum values, why it is faster when we explicitly cast type?

This post refers to:

  • [Simple test of Enum.GetValues() with casting type and without][my_prev_enum_simple]
  • stackoverflow.com: [How do I iterate over an enum?][stack_comm_enum_bdn]
  • [bartoszkp/EnumGetValuesTest.cs][bartoszkp_enum]

When we iterate on the Enum values, why it is faster when we explicitly cast type?

@marbel82
marbel82 / EnumGetValuesCastTest.md
Last active August 18, 2022 13:18
Simple test of Enum.GetValues() with casting type and without

Simple test of Enum.GetValues() with casting type and without

It was some time ago. I wondered why some people explicitly cast the type of value returned by the Enum.GetValues() function. I did some tests.

Unfortunately, the functions are so short that StopWatch is inaccurate. Therefore, I call them in a large loop and then divide the time by the number of repetitions.

public class C {
    enum Sizes
	{