Контракты кода с интерфейсами: вызов метода пропущен. Компилятор сгенерирует вызов метода, поскольку метод является условным []

Добрый вечер,

Я только начал играть с Microsoft.Contracts (последняя версия) и подключил его поверх примера интерфейса, и сейчас он выглядит так:

namespace iRMA2.Core.Interfaces
{
    using System;
    using System.Collections.Generic;
    using System.ComponentModel.Composition;
    using System.Diagnostics.Contracts;

    /// <summary>
    /// Base Interface declarations for iRMA2 Extensions
    /// </summary>
    [InheritedExport]
    [ContractClass(typeof(IiRMA2ExtensionContract))]
    public interface IiRMA2Extension
    {
        /// <summary>
        /// Gets the name.
        /// </summary>
        /// <value>The name of the Extension.</value>
        string Name { get; }

        /// <summary>
        /// Gets the description.
        /// </summary>
        /// <value>The description.</value>
        string Description { get; }

        /// <summary>
        /// Gets the author of the extension. Please provide complete information to get in touch with author(s) and the corresponding department
        /// </summary>
        /// <value>The author of the extensions.</value>
        string Author { get; }

        /// <summary>
        /// Gets the major version.
        /// </summary>
        /// <value>The major version of the extension.</value>
        int MajorVersion { get; }

        /// <summary>
        /// Gets the minor version.
        /// </summary>
        /// <value>The minor version.</value>
        int MinorVersion { get; }

        /// <summary>
        /// Gets the build number.
        /// </summary>
        /// <value>The build number.</value>
        int BuildNumber { get; }

        /// <summary>
        /// Gets the revision.
        /// </summary>
        /// <value>The revision.</value>
        int Revision { get; }

        /// <summary>
        /// Gets the depends on.
        /// </summary>
        /// <value>The dependencies to other <c>IiRMA2Extension</c> this one has.</value>
        IList<IiRMA2Extension> DependsOn { get; }
    }

    /// <summary>
    /// Contract class for <c>IiRMA2Extension</c>
    /// </summary>
    [ContractClassFor(typeof(IiRMA2Extension))]
    internal sealed class IiRMA2ExtensionContract : IiRMA2Extension
    {
        #region Implementation of IiRMA2Extension

        /// <summary>
        /// Gets or sets the name.
        /// </summary>
        /// <value>The name of the Extension.</value>
        public string Name
        {
            get
            {
                Contract.Ensures(!String.IsNullOrEmpty(Contract.Result<string>()));
                return default(string);
            }

            set
            {
                Contract.Requires(value != null);
            }
        }

        /// <summary>
        /// Gets the description.
        /// </summary>
        /// <value>The description.</value>
        public string Description
        {
            get { throw new NotImplementedException(); }
        }

        /// <summary>
        /// Gets the author of the extension. Please provide complete information to get in touch with author(s) and the corresponding department
        /// </summary>
        /// <value>The author of the extensions.</value>
        public string Author
        {
            get { throw new NotImplementedException(); }
        }

        /// <summary>
        /// Gets the major version.
        /// </summary>
        /// <value>The major version of the extension.</value>
        public int MajorVersion
        {
            get { throw new NotImplementedException(); }
        }

        /// <summary>
        /// Gets the minor version.
        /// </summary>
        /// <value>The minor version.</value>
        public int MinorVersion
        {
            get { throw new NotImplementedException(); }
        }

        /// <summary>
        /// Gets the build number.
        /// </summary>
        /// <value>The build number.</value>
        public int BuildNumber
        {
            get { throw new NotImplementedException(); }
        }

        /// <summary>
        /// Gets the revision.
        /// </summary>
        /// <value>The revision.</value>
        public int Revision
        {
            get { throw new NotImplementedException(); }
        }

        /// <summary>
        /// Gets the Extensions this one depends on.
        /// </summary>
        /// <value>The dependencies to other <c>IiRMA2Extension</c> this one has.</value>
        public IList<IiRMA2Extension> DependsOn
        {
            get
            {
                Contract.Ensures(Contract.Result<IList<IiRMA2Extension>>() != null);
                return default(IList<IiRMA2Extension>);
            }
        }

        #endregion
    }
}

Теперь, почему два объекта Contract.Ensures(...) «размыты» визуально, а во всплывающей подсказке говорится: «Вызов метода пропущен. Компилятор сгенерирует вызов метода, потому что метод является условным или является частичным методом без реализации" и на самом деле выходные данные CodeContracts не учитывают/не показывают их... Что я здесь упускаю и делаю неправильно?

-J


person Jörg Battermann    schedule 12.03.2010    source источник


Ответы (1)


Есть ли у вас соответствующие макросы кодовых контрактов, определенные для этой сборки? Например CONTRACTS_FULL? Отсутствие правильных макросов может привести к исключению методов из компиляции.

person JaredPar    schedule 12.03.2010
comment
@ Йорг Б.: Я думаю, вы используете Resharper. Resharper не знает, что CONTRACTS_FULL будет определен во время компиляции, если вы не поместите его в символы условной компиляции для проекта. Это должно исправить это... но у него есть недостаток, заключающийся в том, что вам нужно будет изменить как эту страницу , так и Code Contracts, если вы измените уровень используемых вами Contracts. - person porges; 19.01.2011
comment
@Porges: да, да. Кроме того, я недавно создал отчет об ошибке для r# по адресу youtrack.jetbrains.net/issue. /RSRP-182553 для R#, чтобы изначально поддерживать контракты кода для его предложений/предупреждений по рефакторингу кода. - person Jörg Battermann; 19.01.2011
comment
404 emberapp.com/joergbattermann/images/code-contracts/sizes/m .png не найден. - person ctrl-alt-delor; 25.11.2013
comment
Изменение ‹DefineConstants›DEBUG;TRACE‹/DefineConstants› в файлах csproj на ‹DefineConstants›DEBUG;TRACE;CONTRACTS_FULL‹/DefineConstants› избавило от проблемы r#. - person Asger Vestbjerg; 23.05.2016