Skip to content

Instantly share code, notes, and snippets.

View controlflow's full-sized avatar

Alexander Shvedov controlflow

View GitHub Profile
protected override IRearrangeable CreateElement(IMultipleDeclarationMember member)
{
IMultipleDeclaration parent = null;
string title = "declaration";
if (member is IFieldDeclaration)
{
parent = MultipleFieldDeclarationNavigator.GetByDeclarator((IFieldDeclaration)member);
title = "field";
}
private static void CheckUnsafeContext([NotNull] IAwaitExpression awaitExpression, [NotNull] IHighlightingConsumer consumer)
{
for (var localFunctionDeclaration = awaitExpression.GetContainingNode<ILocalFunctionDeclaration>();
localFunctionDeclaration != null;
localFunctionDeclaration = localFunctionDeclaration.GetContainingNode<ILocalFunctionDeclaration>())
{
if (localFunctionDeclaration.IsUnsafe)
{
consumer.AddHighlighting(new CannotAwaitInUnsafeContextError(awaitExpression));
return;
IDeclaredElement declaredElement;
PsiLanguageType language;
Func<RenameIdentifierMarker, IDeclaredElementPointer<IDeclaredElement>> elementPointerFactory;
Func<string> newNameGetter;
IDeclaration declaration;
var nameRange = GetNameRangeByChange(change, out declaredElement, out declaration, out language,
out elementPointerFactory, out newNameGetter);
///////////////////////////////////////////////////////////////////////////////////////////////////////
foreach (var referenceExpression in codeBody.ThisAndDescendants<IReferenceExpression>())
{
var resolveResult = referenceExpression.Reference.Resolve();
if (!resolveResult.ResolveErrorType.IsAcceptable) continue;
var declaredElement = resolveResult.Result.DeclaredElement;
var field = declaredElement as IField;
if (field != null)
{
[Pure, ContractAnnotation("null => null")]
public static IArrowExpressionClause GetArrowExpressionClause([CanBeNull] this IExpressionBodyOwnerDeclaration declaration)
{
var functionDeclaration = declaration as ICSharpFunctionDeclaration;
if (functionDeclaration != null) return functionDeclaration.ArrowExpression;
var propertyDeclaration = declaration as IPropertyDeclaration;
if (propertyDeclaration != null) return propertyDeclaration.ArrowExpression;
var indexerDeclaration = declaration as IIndexerDeclaration;
@controlflow
controlflow / foo1.cs
Created December 10, 2016 15:22
throw expression merge
if (x == null)
throw new ArgumentNullException(nameof(x));
return x;
// =>
return x ?? throw new ArgumentNullException(nameof(x));
using System;
class ArgListFun {
static void Main() {
var arg2 = 1;
string arg3;
var arg1 = M(__arglist(123, ref arg2, out arg3));
Console.WriteLine(arg1); // 123
Console.WriteLine(arg2); // 43
public class OldSchoolPerson {
public string Name { get; set; }
public int Age { get; set; }
}
public class ModernPerson {
private string _name;
private int _age;
public ref string Name => ref _name;
// C# specs paragraph 18.4
if (from is IPointerType && to is IPointerType)
{
IType toElementType = ((IPointerType)to).ElementType;
return predefinedType.Void.Equals(toElementType) ||
((IPointerType)from).ElementType.Equals(toElementType);
}
{
"System.Collections.Generic": {
"IReadOnlyList`2": {
"P:Keys": "NotNull",
"P:Values": "NotNull",
"M:TryGetValue(`0,`1@)": [
"Pure",
["ContractAnnotation", "=> true; => false, value: null"],
{ "key": "NotNull" }
],