void PackageContract(XContract contract) { if (contractList == null) { contractList = new List <XContract>(2); } contractList.Add(contract); }
/// <summary> /// Creates a new package for getter and setter accessors. Does not use the inheritedFrom string, that information is stored on individual contracts. /// </summary> public XAccessorContract(IMetadataHost host, XAccessorKind kind, XContract[] contracts, DocTracker docTracker) : base(host, null, null, docTracker) { Contract.Requires(docTracker != null); Contract.Requires(contracts != null); Contract.Requires(contracts.Length > 0); Contract.Requires(Contract.ForAll(contracts, c => c != null)); this.kind = kind; this.contracts = contracts; }
void PackageContract(XContract contract) { if (contractList == null) contractList = new List<XContract>(2); contractList.Add(contract); }
/// <summary> /// Attempts to gather the contracts the packager collected into an array. /// </summary> /// <returns> /// Returns false and sets the <paramref name="contractArray"/> to null if and only if no contracts /// have been packaged. Otherwise it returns true and stores the packaged contracts in <paramref name="contractArray"/>. /// </returns> /// <remarks>This doesn't do any packaging, this only retrieves contracts that have been packaged. Use PackageMethodContracts or /// PackageTypeContracts to package contracts.</remarks> //[Pure] public bool TryGetContracts(out XContract[] contractArray) { Contract.Ensures(!Contract.Result<bool>() || Contract.ValueAtReturn(out contractArray).Length > 0); if (this.contractList != null) { var oldCount = this.contractList.Count; contractArray = this.contractList.ToArray(); return true; } contractArray = null; return false; }
/// <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); }