Skip to content

Instantly share code, notes, and snippets.

Avatar

Alexander Shvedov controlflow

View GitHub Profile
View gist:9103821
sealed class ArrayPart : Part
{
readonly int myArrayLength;
readonly object[] myArray;
int myItemIndex;
public ArrayPart(int arrayLength)
{
myArray = new object[arrayLength];
myArrayLength = arrayLength;
@controlflow
controlflow / gist:9996665
Last active Aug 29, 2015
Possible C# primary constructors design
View gist:9996665
class Person : EntityBase {
// ~familiar syntax, no problems with xml doc, can omit body, can omit public?
public constructor(int id, string name, int age) : base(id);
readonly string _mrName = "Mr. " + name;
public string Name { get; } = name;
public int Age { get; } = age;
}
@controlflow
controlflow / gist:11d6360ea827164aaa1e
Last active Aug 29, 2015
C# 6.0 declaration expressions
View gist:11d6360ea827164aaa1e
// CA "To declaration statement"
{
var t = F(out var x);
// =>
int x;
var t = F(out x);
}
@controlflow
controlflow / gist:de10836191593eee1744
Created Sep 20, 2014
Null propagation playground
View gist:de10836191593eee1744
convert "Null-conditional invocation" {
if (x != null) { // also 'cond && x != null'
x.M();
}
} into {
x?.M();
}
convert "Null-conditional invocation (inverted)" {
@controlflow
controlflow / gist:4d4c7f0c5527dc055d07
Last active Aug 29, 2015
Simple pure BF interpreter
View gist:4d4c7f0c5527dc055d07
import Data.Char(ord, chr)
data Tape = Tape [Int] Int [Int]
deriving Show
getTape :: [Int] -> Tape
getTape (x:xs) = Tape [] x xs
getTape [] = Tape [] 0 []
modify :: (Int -> Int) -> Tape -> Tape
@controlflow
controlflow / gist:b67376a4b7fda8a3be37
Created Sep 30, 2014
Simple BF interpreter in Haskell
View gist:b67376a4b7fda8a3be37
import Data.Char(ord, chr)
data Tape = Tape [Int] Int [Int]
deriving Show
getTape :: [Int] -> Tape
getTape (x:xs) = Tape [] x xs
getTape [] = Tape [] 0 []
modify :: (Int -> Int) -> Tape -> Tape
View gist:be428287b7e08c306559
[DebuggerDisplay("Person(Name={" + nameof(Name) + ",nq}, Age={" + nameof(Age) + ",nq})")]
// vs.
[DebuggerDisplay($"Person(Name={{{ nameof(Name) },nq}}, Age={{{ nameof(Age) },nq})")]
class Person {
public string Name { get; }
public int Age { get; }
public Person(string name, int age) {
this.Name = name;
this.Age = age;
@controlflow
controlflow / ReflectionTypeVisitor.cs
Last active Aug 29, 2015
Simple System.Type visitor to traverse and replace types
View ReflectionTypeVisitor.cs
using System;
using JetBrains.Annotations;
namespace Smth {
[PublicAPI]
public abstract class ReflectionTypeVisitor<T> {
public virtual T VisitSimpleType(Type type) => default(T);
public virtual T VisitConstructedType([NotNull] Type typeDefinition, [NotNull] Type[] typeArguments) => default(T);
public virtual T VisitTypeParameterType([NotNull] Type typeParameter) => default(T);
public virtual T VisitArrayType([NotNull] Type arrayType) => default(T);
View AggregatedPropertyDescriptor.cs
using System;
using System.Collections.Generic;
using System.ComponentModel;
using JetBrains.Annotations;
namespace JetBrains.VsIntegration.ProjectModel.PropertiesExtender
{
public sealed class AggregatedPropertyDescriptor : PropertyDescriptor
{
[NotNull] private readonly IList<PropertyDescriptor> myPropertyDescriptors;
View ProvidesContext.cs
class Foo {
[ProvidesContext] IPredefinedType _predefinedTypes = ...;
void DoSomething(ITreeNode node) {
if (Check(node)) {
var expressionType = node.GetExpressionType();
if (expressionType.Equals(node.GetPredefinedType().Bool) {
// ^^^^^^^^^^^^^^^^^^^^^^^^
// Use aleady provided 'IPredefinedType' value from '_predefinedTypes' field
}