Tuesday 20 December 2011

Nullable types, lifted operators and ReSharper

Recently I investigated why ReSharper marks some pieces of my project code as invalid however compiler does not throw any errors.

Finally I narrowed down the problem.

class Program
    {
        static void Main(string[] args)
        {
            int? i = 10;

            A a = i;
        }

        class A
        {
            A(int i)
            {
                Value = i;
            }

            public int Value { get; private set; }

            public static implicit operator A(int i)
            {
                return new A(i);
            }
       }
    }

ReSharper highlights an error on line 7. However as you can imagine on a runtime corresponding implicit operator is called.
I investigated this behaviour and found that actually it is according to the C# spec

Nullable conversions and lifted conversions permit predefined and user-defin ed conversions that operate on non-nullable value types also to be used with nullable forms of those types. Likewise, lifted operators permit predefined and user-defined operators that work for non-nullable value types also to work for nullable forms of those types.
For every predefined conversion from a non-nullable value type S to a non-nullable value type T , a predefined nullable conversion automatically exists from S? to T?. This nullable conversion is a null propagating form of the underlying conversion: It converts a null source value directly to a null target value, but otherwise performs the underlying non-nullable co nversion. Nullable conversions are furthermore provided from S to T? and from S? to T , the latter as an explicit conversion that throws an exception if the source value is null.

So finally I know that it is a ReSharper bug and I will report it on their bug-tracker system.

Potentially it is a good question for juniors on interviews :)

UPD: Raised bug on ReSharper bug tracker
http://youtrack.jetbrains.net/issue/RSRP-287221?projectKey=RSRP&query=lifted

Test SyntaxHighlight

Finally made SyntaxHighliter working on the blogger.
Good instructions http://pjdurrant.blogspot.com/2011/11/blog-code-syntax-highlighting.html

public class FinallySyntaxHighlighterIsWorking
{
    public void React()
    {
        Console.WriteLine("Hoorah!!!");
    }
}

Wednesday 17 August 2011

Видео по паттернам

Открыл для себя просто отличнейшие скринкасты от конторы Pluralsight.

Особенно понравились по ReSharper
http://rutracker.org/forum/viewtopic.php?t=3478847

Software Practices
(особенно классно по паттернам)
http://rutracker.org/forum/viewtopic.php?t=3470810

ASP.NET MVC 3
http://rutracker.org/forum/viewtopic.php?t=3535583

Monday 30 May 2011

Firefox и картинки в ссылках

Тупая "фича" firefox: подчёркивать картинки img внутри ссылки a, при наведении. Поведение абсолютно неожиданное, и неудобное.
В ослике ничего такого и близко нет.

Простого фикса не нашлось.
Пришлось засунуть текст внутри ссылки в отдельный div (не span, чтобы подпись была ПОД картинкой, а не справа).
a:hover { text-decoration : none}
a:hover div { text-decoration : underline }

Уродски, но работает.
Никакие другие нагугленные способы, не помогли.
В частности всякие типа border : none

Поисковая система для иконок

Нашёл прикольный сервис для поиска иконок
http://findicons.com/

Быстро и удобно находятся иконки по тематике, тегам и т.д.