public IRelationshipBuilder <TParentBuilder> SetData(IToOneResourceLinkage toOneResourceLinkage) { if (toOneResourceLinkage == null || toOneResourceLinkage.HasValue == false) { this.SetDataNullOrEmpty(); return(this); } var rel = this.Rel; var resourceType = this.ResourceType; var relationship = resourceType.GetRelationshipInfo(rel); var toCardinality = relationship.ToCardinality; var toClrType = relationship.ToClrType; var toResourceType = this.ServiceModel.GetResourceType(toClrType); switch (toCardinality) { case RelationshipCardinality.ToOne: { var toApiResourceIdentifier = toOneResourceLinkage.CreateApiResourceIdentifier(toResourceType); foreach (var domReadWriteRelationship in this.DomReadWriteRelationshipCollection) { domReadWriteRelationship.SetDomData(toApiResourceIdentifier, toClrType); } break; } case RelationshipCardinality.ToMany: { var clrResourceTypeName = resourceType.ClrType.Name; var detail = InfrastructureErrorStrings.DocumentBuildExceptionDetailBuildToOneRelationshipResourceLinkageCardinalityMismatch .FormatWith(clrResourceTypeName, rel); throw new DocumentBuildException(detail); } default: { var detail = InfrastructureErrorStrings.InternalErrorExceptionDetailUnknownEnumerationValue .FormatWith(typeof(RelationshipCardinality).Name, toCardinality); throw new InternalErrorException(detail); } } return(this); }
internal void SetDataInternal(IToOneResourceLinkage toOneResourceLinkage) { if (toOneResourceLinkage == null || toOneResourceLinkage.HasValue == false) { this.SetDataNullOrEmpty(); return; } var rel = this.Rel; var resourceType = this.ResourceType; var relationship = resourceType.GetRelationshipInfo(rel); var toCardinality = relationship.ToCardinality; var toClrType = relationship.ToClrType; var toResourceType = this.ServiceModel.GetResourceType(toClrType); switch (toCardinality) { case RelationshipCardinality.ToOne: { // ReSharper disable once PossibleNullReferenceException var toApiResourceIdentifier = toOneResourceLinkage.CreateApiResourceIdentifier(toResourceType); this.DomReadWriteRelationship.SetDomData(toApiResourceIdentifier, toClrType); } break; case RelationshipCardinality.ToMany: { var clrResourceTypeName = resourceType.ClrType.Name; var detail = InfrastructureErrorStrings.DocumentBuildExceptionDetailBuildToOneRelationshipResourceLinkageCardinalityMismatch .FormatWith(clrResourceTypeName, rel); throw new DocumentBuildException(detail); } default: { var detail = InfrastructureErrorStrings.InternalErrorExceptionDetailUnknownEnumerationValue .FormatWith(typeof(RelationshipCardinality).Name, toCardinality); throw new InternalErrorException(detail); } } }