private static void AddNewHierarchicalCodelistRefSubmissionResult(
            SubmitStructureResponseType returnType, IStructureReference structureReference, Exception exception)
        {
            SubmissionResultType result = GetNewSubmissionResultType(returnType, exception);
            var submittedStructure = new SubmittedStructureType();
            result.SubmittedStructure = submittedStructure;
            var refType = new HierarchicalCodelistRefType();
            submittedStructure.HierarchicalCodelistRef = refType;

            IMaintainableRefObject mRef = structureReference.MaintainableReference;
            refType.AgencyID = mRef.AgencyId;
            refType.HierarchicalCodelistID = mRef.MaintainableId;
            if (ObjectUtil.ValidString(structureReference.MaintainableUrn))
            {
                refType.URN = structureReference.MaintainableUrn;
            }

            string value = mRef.Version;
            if (!string.IsNullOrWhiteSpace(value))
            {
                refType.Version = mRef.Version;
            }
        }
        /// <summary>
        /// Sets the attributes of <paramref name="refType"/>
        /// </summary>
        /// <param name="refType">
        /// The reference type
        /// </param>
        /// <param name="crossReference">
        /// The cross-reference
        /// </param>
        private static void SetHclRefAttributes(HierarchicalCodelistRefType refType, IStructureReference crossReference)
        {
            IMaintainableRefObject maintainableReference = crossReference.MaintainableReference;
            string value = maintainableReference.AgencyId;
            if (!string.IsNullOrWhiteSpace(value))
            {
                refType.AgencyID = maintainableReference.AgencyId;
            }

            string value1 = maintainableReference.MaintainableId;
            if (!string.IsNullOrWhiteSpace(value1))
            {
                refType.HierarchicalCodelistID = maintainableReference.MaintainableId;
            }

            if (ObjectUtil.ValidString(crossReference.TargetUrn))
            {
                refType.URN = crossReference.TargetUrn;
            }

            string str3 = maintainableReference.Version;
            if (!string.IsNullOrWhiteSpace(str3))
            {
                refType.Version = maintainableReference.Version;
            }
        }
        /// <summary>
        /// The process codelist map.
        /// </summary>
        /// <param name="structureSetType">
        /// The structure set type.
        /// </param>
        /// <param name="buildFrom">
        /// The build from.
        /// </param>
        private void ProcessCodelistMap(StructureSetType structureSetType, IItemSchemeMapObject buildFrom)
        {
            var codelistMap = new CodelistMapType();
            structureSetType.CodelistMap = codelistMap;

            string str0 = buildFrom.Id;
            if (!string.IsNullOrWhiteSpace(str0))
            {
                codelistMap.id = buildFrom.Id;
            }

            IList<ITextTypeWrapper> names = buildFrom.Names;
            if (ObjectUtil.ValidCollection(names))
            {
                codelistMap.Name = this.GetTextType(names);
            }

            IList<ITextTypeWrapper> descriptions = buildFrom.Descriptions;
            if (ObjectUtil.ValidCollection(descriptions))
            {
                codelistMap.Description = this.GetTextType(descriptions);
            }

            if (buildFrom.SourceRef != null)
            {
                if (buildFrom.SourceRef.TargetReference.EnumType == SdmxStructureEnumType.CodeList)
                {
                    var refType = new CodelistRefType();
                    codelistMap.CodelistRef = refType;
                    SetCodelistRefAttributes(refType, buildFrom.SourceRef);
                }
                else if (buildFrom.SourceRef.TargetReference.EnumType == SdmxStructureEnumType.HierarchicalCodelist)
                {
                    var refType0 = new HierarchicalCodelistRefType();
                    codelistMap.HierarchicalCodelistRef = refType0;
                    SetHclRefAttributes(refType0, buildFrom.SourceRef);
                }
            }

            if (buildFrom.TargetRef != null)
            {
                if (buildFrom.TargetRef.TargetReference.EnumType == SdmxStructureEnumType.CodeList)
                {
                    var refType1 = new CodelistRefType();
                    codelistMap.TargetCodelistRef = refType1;
                    SetCodelistRefAttributes(refType1, buildFrom.TargetRef);
                }
                else if (buildFrom.TargetRef.TargetReference.EnumType == SdmxStructureEnumType.HierarchicalCodelist)
                {
                    var refType2 = new HierarchicalCodelistRefType();
                    codelistMap.TargetHierarchicalCodelistRef = refType2;
                    SetHclRefAttributes(refType2, buildFrom.TargetRef);
                }
            }

            IList<IItemMap> itemMapBeans = buildFrom.Items;
            if (ObjectUtil.ValidCollection(itemMapBeans))
            {
                /* foreach */
                foreach (IItemMap itemMapBean in itemMapBeans)
                {
                    var codeMaptype = new CodeMapType();
                    codelistMap.CodeMap.Add(codeMaptype);
                    string value1 = itemMapBean.SourceId;
                    if (!string.IsNullOrWhiteSpace(value1))
                    {
                        codeMaptype.MapCodeRef = itemMapBean.SourceId;
                    }

                    string value = itemMapBean.TargetId;
                    if (!string.IsNullOrWhiteSpace(value))
                    {
                        codeMaptype.MapTargetCodeRef = itemMapBean.TargetId;
                    }
                }
            }

            if (this.HasAnnotations(buildFrom))
            {
                codelistMap.Annotations = this.GetAnnotationsType(buildFrom);
            }
        }
        /// <summary>
        /// Process related structures.
        /// </summary>
        /// <param name="structureSetType">
        /// The structure set type.
        /// </param>
        /// <param name="buildFrom">
        /// The build from.
        /// </param>
        private static void ProcessRelatedStructures(StructureSetType structureSetType, IStructureSetObject buildFrom)
        {
            if (buildFrom.RelatedStructures != null)
            {
                var relatedStructuresType = new RelatedStructuresType();
                structureSetType.RelatedStructures = relatedStructuresType;
                IRelatedStructures relatedStructures = buildFrom.RelatedStructures;

                // KEY FAMILY REF
                foreach (ICrossReference xref in relatedStructures.DataStructureRef)
                {
                    var keyFamilyRefType = new KeyFamilyRefType();
                    relatedStructuresType.KeyFamilyRef.Add(keyFamilyRefType);
                    SetDataStructureRefAttributes(keyFamilyRefType, xref);
                }

                // METADATA STRUCTURE REF
                foreach (ICrossReference ref0 in relatedStructures.MetadataStructureRef)
                {
                    var refType = new MetadataStructureRefType();
                    relatedStructuresType.MetadataStructureRef.Add(refType);
                    SetMetadataStructureRefAttributes(refType, ref0);
                }

                // CONCEPT SCHEME REF
                foreach (ICrossReference ref1 in relatedStructures.ConceptSchemeRef)
                {
                    var refType2 = new ConceptSchemeRefType();
                    relatedStructuresType.ConceptSchemeRef.Add(refType2);
                    SetConceptSchemeRefAttributes(refType2, ref1);
                }

                // CATEGORY SCHEME REF
                foreach (ICrossReference ref3 in relatedStructures.CategorySchemeRef)
                {
                    var refType4 = new CategorySchemeRefType();
                    relatedStructuresType.CategorySchemeRef.Add(refType4);
                    SetCategorySchemeRefAttributes(refType4, ref3);
                }

                // ORGANISATION SCHEME REF
                foreach (ICrossReference ref5 in relatedStructures.OrgSchemeRef)
                {
                    var refType6 = new OrganisationSchemeRefType();
                    relatedStructuresType.OrganisationSchemeRef.Add(refType6);
                    SetOrganisationSchemeRefAttributes(refType6, ref5);
                }

                // HCL REF
                foreach (ICrossReference ref7 in relatedStructures.HierCodelistRef)
                {
                    var refType8 = new HierarchicalCodelistRefType();
                    relatedStructuresType.HierarchicalCodelistRef.Add(refType8);
                    SetHclRefAttributes(refType8, ref7);
                }
            }
        }