Skip to content

Instantly share code, notes, and snippets.

View Razzo78's full-sized avatar

Rudy Azzan Razzo78

View GitHub Profile
@Razzo78
Razzo78 / enum_list.cs
Last active September 3, 2020 13:22
C# - Convert an enumeration to a list of values
List<Era> eras = System.Enum
.GetValues(typeof(Era))
.Cast<Era>()
.ToList();
enum Era
{
Paleolitico,
Neolitico,
Mesozoico,
@Razzo78
Razzo78 / SelPco
Last active December 2, 2019 16:03
C#, ReactiveX - Select previous and current observable
var flow = Observable.Range(1, 30);
flow = flow.Scan((current, previous) =>
{
(current + " - " + previous).Dump();
return previous;
});
flow.Subscribe();
@Razzo78
Razzo78 / SelPcn
Last active September 3, 2020 13:23
C#, Linq - How to select previous, current, net value in an array
var flusso = Enumerable.Range(1,30).ToArray();
flusso.TakeWhile((_, pos) => pos <= flusso.Count()).Select((_, pos) => flusso.Skip(pos).Take(3)).Where(w => w.Count() == 3).Dump();
@Razzo78
Razzo78 / forRange.cs
Created May 23, 2019 12:31
C# - Execute function with range. Better than a for cicle!
Func<int, int> triple = x => x * 3;
var range = Enumerable.Range(1, 3);
var triples = range.Select(triple);
@Razzo78
Razzo78 / AssemblyInfoShare.cs
Created May 15, 2019 07:56
C# - Make internal methods visible to other assemblies
//Starting from the source assembly include this attribute to make the internal methods visible to the recipient "AssemblyName"
[assembly:InternalsVisibleTo("AssemblyName")]
@Razzo78
Razzo78 / getReadOnlyList.cs
Last active March 11, 2019 23:29
C# - Create read only list property for collection encapsulation
private readonly IList<string> _listOfNames = new List<string>();
public virtual IReadOnlyList<string> ListOfNames => _listOfNames.ToList();
@Razzo78
Razzo78 / configureAwait.cs
Last active March 11, 2019 14:43
C# - Example of using ConfigureAwait method of Task
static async Task DoSomethingAsync()
{
Debug.WriteLine("B");
Debug.WriteLine(Thread.CurrentThread.ManagedThreadId);
await Task.Delay(TimeSpan.FromSeconds(1)).ConfigureAwait(false);
Debug.WriteLine("C");
Debug.WriteLine(Thread.CurrentThread.ManagedThreadId);
}
private async void Form1_Load(object sender, EventArgs e)
System.Reflection.Assembly assembly = System.Reflection.Assembly.GetExecutingAssembly();
FileVersionInfo fvi = FileVersionInfo.GetVersionInfo(assembly.Location);
string version = fvi.FileVersion;
@Razzo78
Razzo78 / Class_to_Json.cs
Last active December 30, 2018 11:04
C# - Class to Json and Json to class conversion
void Main()
{
var kanban = new KanbanBoard
{
Id = "_todo",
Title = "To Do (drag me)",
Class = "info",
Items = new List<KanbanItem>
{
new KanbanItem{
@Razzo78
Razzo78 / Invoke_required.cs
Last active December 17, 2018 14:57
C# - Update UI control thread-safe
public void ControlInvokeRequired(Control control, Action action)
{
if (control.InvokeRequired) control.Invoke(new MethodInvoker(delegate { action(); }));
}