Code Monkey home page Code Monkey logo

ap.resharperannotationsdemo's Introduction

AP.ResharperAnnotationsDemo

This is a demo project for Albumprinter BV .Net team.

What does R# offers us in JetBrains.Annotations library?

Type system limitations

C# typesystem is limited in some cases, so we might need a tool to express some extra ideas in code.

  • Null-NotNull attribute

Demo:

[CanBeNull]
public static string CanReturnNull(string parameter)
{
	var rand = new Random();
    return (rand.Next()%2) == 0 ? "string" : null;
}
  • Pure attribute

In computer programming, a function may be described as a pure function if both these statements about the function hold:

  1. The function always evaluates the same result value given the same argument value(s). The function result value cannot depend on any hidden information or state that may change as program execution proceeds or between different executions of the program, nor can it depend on any external input from I/O devices.
  2. Evaluation of the result does not cause any semantically observable side effect or output, such as mutation of mutable objects or output to I/O devices.

(c) Wikipedia

Demo

public class MyInt
{
	private readonly int value;
	public MyInt(int value)
    {
    	this.value = value;
    }

    public int Value
    {
        get { return value; }
    }
        
    [Pure]
    public MyInt Add(int add)
    {
        return new MyInt(Value + add);
    }
}
  • Contracts

[CanBeNull] and [NotNull] does not allow us to express any conditions. So the Method can be either NotNull either CanBeNull. Not both of them.

Demo

public static class ContractTest
{
    [ContractAnnotation("str:null => null;str:notnull=>notnull")]
    public static string Reverse(string str)
    {
        if (str == null) return null;
   		return new string(str.Reverse().ToArray());
    }
}

Usage

  • [PublicApi], [UsedImplisitly] attributes

Demo

Code helpers

  • Resource navigation

Demo

1

  • Custom string formatting

Demo

2

What to read

ap.resharperannotationsdemo's People

Contributors

asizikov avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.