Exemplo n.º 1
0
    /// <summary>
    /// Extracts method contracts for the accessors and packages them under the property itself.
    /// </summary>
    public override void Visit(IPropertyDefinition propertyDefinition) {
      Contract.Assert(propertyDefinition != null);

      string propertyId = MemberHelper.GetMemberSignature(propertyDefinition, NameFormattingOptions.DocumentationId);
      docTracker.WriteLine(propertyId);

      int contractsCounter = 0;

      XAccessorContract getterContracts = null;
      if (propertyDefinition.Getter != null) {
        var getterMethod = propertyDefinition.Getter.ResolvedMethod;
        Contract.Assume(getterMethod != null);
        bool isPure = IsPure(getterMethod); //TODO: Remove, this should be handled on the packager side.
        ContractPackager packager = new ContractPackager(host, docTracker);
        packager.PackageMethodContracts(getterMethod, isPure);
        XContract[] getterContractArray;
        if (packager.TryGetContracts(out getterContractArray)) {
          contractsCounter += getterContractArray.Length;
          docTracker.AddMemberInfo(getterContractArray.Length, MemberKind.Getter);
          getterContracts = new XAccessorContract(this.host, XAccessorKind.Getter, getterContractArray, docTracker);
        }
      }

      XAccessorContract setterContracts = null;
      if (propertyDefinition.Setter != null) {
        var setterMethod = propertyDefinition.Setter.ResolvedMethod;
        Contract.Assume(setterMethod != null);
        bool isPure = IsPure(setterMethod); //TODO: Remove, this should be handled on the packager side.
        ContractPackager packager = new ContractPackager(host, docTracker);
        packager.PackageMethodContracts(setterMethod, isPure);
        XContract[] setterContractArray;
        if (packager.TryGetContracts(out setterContractArray)) {
          contractsCounter += setterContractArray.Length;
          docTracker.AddMemberInfo(setterContractArray.Length, MemberKind.Setter);
          setterContracts = new XAccessorContract(this.host, XAccessorKind.Setter, setterContractArray, docTracker);
        }
      }

      XContract[] accessorContracts = null;
      if (getterContracts != null && setterContracts != null)
        accessorContracts = new XContract[2] { getterContracts, setterContracts };
      else if (getterContracts != null)
        accessorContracts = new XContract[1] { getterContracts };
      else if (setterContracts != null)
        accessorContracts = new XContract[1] { setterContracts };

      if (accessorContracts != null) {
        contracts.Add(new KeyValuePair<string, XContract[]>(propertyId, accessorContracts));
      }

      docTracker.AddMemberInfo(contractsCounter, MemberKind.Property);

      //base.TraverseChildren(propertyDefinition);
    }
        /// <summary>
        /// Extracts method contracts for the accessors and packages them under the property itself.
        /// </summary>
        public override void Visit(IPropertyDefinition propertyDefinition)
        {
            Contract.Assert(propertyDefinition != null);

            string propertyId = MemberHelper.GetMemberSignature(propertyDefinition, NameFormattingOptions.DocumentationId);

            docTracker.WriteLine(propertyId);

            int contractsCounter = 0;

            XAccessorContract getterContracts = null;

            if (propertyDefinition.Getter != null)
            {
                var getterMethod = propertyDefinition.Getter.ResolvedMethod;
                Contract.Assume(getterMethod != null);
                bool             isPure   = IsPure(getterMethod); //TODO: Remove, this should be handled on the packager side.
                ContractPackager packager = new ContractPackager(host, docTracker);
                packager.PackageMethodContracts(getterMethod, isPure);
                XContract[] getterContractArray;
                if (packager.TryGetContracts(out getterContractArray))
                {
                    contractsCounter += getterContractArray.Length;
                    docTracker.AddMemberInfo(getterContractArray.Length, MemberKind.Getter);
                    getterContracts = new XAccessorContract(this.host, XAccessorKind.Getter, getterContractArray, docTracker);
                }
            }

            XAccessorContract setterContracts = null;

            if (propertyDefinition.Setter != null)
            {
                var setterMethod = propertyDefinition.Setter.ResolvedMethod;
                Contract.Assume(setterMethod != null);
                bool             isPure   = IsPure(setterMethod); //TODO: Remove, this should be handled on the packager side.
                ContractPackager packager = new ContractPackager(host, docTracker);
                packager.PackageMethodContracts(setterMethod, isPure);
                XContract[] setterContractArray;
                if (packager.TryGetContracts(out setterContractArray))
                {
                    contractsCounter += setterContractArray.Length;
                    docTracker.AddMemberInfo(setterContractArray.Length, MemberKind.Setter);
                    setterContracts = new XAccessorContract(this.host, XAccessorKind.Setter, setterContractArray, docTracker);
                }
            }

            XContract[] accessorContracts = null;
            if (getterContracts != null && setterContracts != null)
            {
                accessorContracts = new XContract[2] {
                    getterContracts, setterContracts
                }
            }
            ;
            else if (getterContracts != null)
            {
                accessorContracts = new XContract[1] {
                    getterContracts
                }
            }
            ;
            else if (setterContracts != null)
            {
                accessorContracts = new XContract[1] {
                    setterContracts
                }
            }
            ;

            if (accessorContracts != null)
            {
                contracts.Add(new KeyValuePair <string, XContract[]>(propertyId, accessorContracts));
            }

            docTracker.AddMemberInfo(contractsCounter, MemberKind.Property);

            //base.TraverseChildren(propertyDefinition);
        }