Inheritance: AbstractObject_Type
        public static MD_Metadata_Type CreateMetadataExample()
        {
            MD_Metadata_Type m = new MD_Metadata_Type();
            m.fileIdentifier = CharString("12345-67890-aabbcc-ddeeff-ggffhhjj");
            m.language = CharString("nor");
            m.metadataStandardName = CharString("ISO19139");
            m.metadataStandardVersion = CharString("1.0");
            m.hierarchyLevel = new[] { new MD_ScopeCode_PropertyType
                {
                    MD_ScopeCode = new CodeListValue_Type
                        {
                            codeList = "http://www.isotc211.org/2005/resources/codeList.xml#MD_ScopeCode",
                            codeListValue = "dataset"
                        }
                }
            };

            var responsibleParty = new CI_ResponsibleParty_Type()
            {
                individualName = CharString("Hans Hansen"),
                role = new CI_RoleCode_PropertyType()
                {
                    CI_RoleCode = new CodeListValue_Type
                    {
                        codeList = "http://www.isotc211.org/2005/resources/codeList.xml#CI_RoleCode",
                        codeListValue = "resourceProvider"
                    }
                },
                organisationName = CharString("Statens Kartverk"),
                contactInfo = new CI_Contact_PropertyType()
                {
                    CI_Contact = new CI_Contact_Type()
                    {
                        address = new CI_Address_PropertyType()
                        {
                            CI_Address = new CI_Address_Type()
                            {
                                electronicMailAddress = new[] { CharString("*****@*****.**") }
                            }
                        }
                    }
                }
            };

            m.contact = new CI_ResponsibleParty_PropertyType[] { new CI_ResponsibleParty_PropertyType()
                {
                    CI_ResponsibleParty = responsibleParty
                }
            };

            m.dateStamp = new Date_PropertyType() { Item = DateTime.Now };

            var mdDataIdentificationType = new MD_DataIdentification_Type();
            mdDataIdentificationType.pointOfContact = new[] {
                new CI_ResponsibleParty_PropertyType { CI_ResponsibleParty = responsibleParty }
            };
            mdDataIdentificationType.citation = new CI_Citation_PropertyType
            {
                CI_Citation = new CI_Citation_Type
                {
                    title = CharString("Eksempeldatasettet sin tittel."),
                    date = new[] {
                        new CI_Date_PropertyType {
                            CI_Date = new CI_Date_Type {
                                date = new Date_PropertyType {
                                    Item = DateTime.Now.Date.ToString("yyyy-MM-dd")
                                },
                                dateType = new CI_DateTypeCode_PropertyType { CI_DateTypeCode = new CodeListValue_Type
                                    {
                                        codeList = "http://www.isotc211.org/2005/resources/codeList.xml#CI_DateTypeCode",
                                        codeListValue = "creation"
                                    }
                                }
                            }
                        }
                    },
                    alternateTitle = new[] { CharString("Dette er en den alternative tittelen til datasettet som tilbys.") },
                    identifier = new[] { new MD_Identifier_PropertyType
                        {
                            MD_Identifier = new MD_Identifier_Type
                                {
                                    code = CharString("12345-abcdef-67890-ghijkl")
                                }
                        }
                    }
                }
            };
            mdDataIdentificationType.@abstract = CharString("Dette datasettet inneholder ditt og datt. Kan brukes til dette, men må ikke brukes til andre ting som for eksempel dette.");
            mdDataIdentificationType.purpose = CharString("Dette er formålet.");
            mdDataIdentificationType.resourceSpecificUsage = new[]
                {
                    new MD_Usage_PropertyType() {
                        MD_Usage = new MD_Usage_Type()
                        {
                            specificUsage = CharString("Skal bare brukes sånn og sånn"),
                            usageDateTime = new DateTime_PropertyType() { DateTime = DateTime.Now },
                            userContactInfo = new []
                                {
                                    new CI_ResponsibleParty_PropertyType
                                        {
                                            CI_ResponsibleParty = responsibleParty
                                        }
                                },
                            userDeterminedLimitations = CharString("Her kommer det begrensninger på bruk av dataene.")
                        }
                    }
                };
            mdDataIdentificationType.spatialResolution = new MD_Resolution_PropertyType[] { new MD_Resolution_PropertyType()
                {
                    MD_Resolution = new MD_Resolution_Type()
                        {
                            Item = new MD_RepresentativeFraction_PropertyType()
                                {
                                    MD_RepresentativeFraction = new MD_RepresentativeFraction_Type()
                                        {
                                            denominator = new Integer_PropertyType() { Integer = "1000" }
                                        }
                                }
                        }
                }
            };
            mdDataIdentificationType.language = new[] { CharString("nor") };
            mdDataIdentificationType.descriptiveKeywords = new[] {
                new MD_Keywords_PropertyType {
                    MD_Keywords = new MD_Keywords_Type {
                        keyword = new MD_Keyword[]
                        { new MD_Keyword
                           { keyword =  new PT_FreeText_PropertyType
                                {
                                    CharacterString = "Adresser",
                                    PT_FreeText = new PT_FreeText_Type {
                                            id = "ENG",
                                            textGroup = new LocalisedCharacterString_PropertyType[]
                                            {
                                                new LocalisedCharacterString_PropertyType {
                                                    LocalisedCharacterString = new LocalisedCharacterString_Type
                                                    {
                                                    locale = "#ENG",
                                                    Value = "Addresses"
                                                    }
                                                }
                                            }
                                    }
                                }
                            }
                        },
                        thesaurusName = new CI_Citation_PropertyType
                            {
                                CI_Citation = new CI_Citation_Type
                                    {
                                        title = CharString("GEMET - INSPIRE themes, version 1.0"),

                                        date = new [] { new CI_Date_PropertyType
                                            {
                                                CI_Date = new CI_Date_Type
                                                    {
                                                        date = new Date_PropertyType { Item = DateTime.Now },
                                                        dateType = new CI_DateTypeCode_PropertyType
                                                            {
                                                                CI_DateTypeCode = new CodeListValue_Type()
                                                                    {
                                                                        codeList = "http://standards.iso.org/ittf/PubliclyAvailableStandards/ISO_19139_Schemas/resources/Codelist/ML_gmxCodelists.xml#CI_DateTypeCode",
                                                                        codeListValue = "publication"
                                                                    }
                                                            }
                                                    }
                                            }
                                        }
                                    }
                            }
                    }
                }
            };
            mdDataIdentificationType.resourceConstraints = new[]
                {
                    new MD_Constraints_PropertyType
                        {
                            MD_Constraints = new MD_Constraints_Type
                            {

                                 useLimitation = new [] { new PT_FreeText_PropertyType
                                 {
                                    CharacterString = "Gratis å benytte til alle formål.",
                                    PT_FreeText = new PT_FreeText_Type
                                    {
                                            id = "ENG",
                                            textGroup = new LocalisedCharacterString_PropertyType[]
                                            {
                                                new LocalisedCharacterString_PropertyType {
                                                    LocalisedCharacterString = new LocalisedCharacterString_Type
                                                    {
                                                    locale = "#ENG",
                                                    Value = "Free of charge"
                                                    }
                                                }
                                            }
                                    }
                                  }

                                }
                            }
                        },
                    new MD_Constraints_PropertyType
                        {
                            MD_Constraints = new MD_LegalConstraints_Type
                                {
                                    accessConstraints = new MD_RestrictionCode_PropertyType[]
                                    {
                                        new MD_RestrictionCode_PropertyType
                                        {
                                            MD_RestrictionCode = new CodeListValue_Type { codeListValue = "none" , codeList = "http://standards.iso.org/ittf/PubliclyAvailableStandards/ISO_19139_Schemas/resources/codelist/gmxCodelists.xml#MD_RestrictionCode" }
                                        }
                                    },
                                    useConstraints = new MD_RestrictionCode_PropertyType[]
                                    {
                                        new MD_RestrictionCode_PropertyType
                                        {
                                            MD_RestrictionCode = new CodeListValue_Type { codeListValue = "free" , codeList = "http://standards.iso.org/ittf/PubliclyAvailableStandards/ISO_19139_Schemas/resources/codelist/gmxCodelists.xml#MD_RestrictionCode" }
                                        }
                                    },
                                    otherConstraints = new MD_RestrictionOther_PropertyType []
                                    {
                                        new MD_RestrictionOther_PropertyType
                                        {
                                            MD_RestrictionOther =
                                            new PT_FreeText_PropertyType
                                                 {
                                                    CharacterString = "Ingen begrensninger på bruk.",
                                                    PT_FreeText = new PT_FreeText_Type
                                                    {
                                                            id = "ENG",
                                                            textGroup = new LocalisedCharacterString_PropertyType[]
                                                            {
                                                                new LocalisedCharacterString_PropertyType {
                                                                    LocalisedCharacterString = new LocalisedCharacterString_Type
                                                                    {
                                                                    locale = "#ENG",
                                                                    Value = "No restrictions"
                                                                    }
                                                                }
                                                            }
                                                    }
                                                  }
                                            }

                                        , new MD_RestrictionOther_PropertyType
                                        {
                                            MD_RestrictionOther = new Anchor_Type{href="http://test.no",Value="Link"}
                                        },
                                        new MD_RestrictionOther_PropertyType
                                        {
                                            MD_RestrictionOther = CharString("norway digital restricted")
                                        }
                                    }
                                }
                        },
                    new MD_Constraints_PropertyType
                        {
                            MD_Constraints = new MD_SecurityConstraints_Type
                                {
                                    userNote = new CharacterString_PropertyType
                                    {
                                        CharacterString = "Text that describes why it is not freely open"
                                    },
                                    classification = new MD_ClassificationCode_PropertyType
                                        {
                                            MD_ClassificationCode = new CodeListValue_Type
                                                {
                                                    codeList = "http://standards.iso.org/ittf/PubliclyAvailableStandards/ISO_19139_Schemas/resources/codelist/gmxCodelists.xml#MD_ClassificationCode",
                                                    codeListValue = "unclassified"
                                                }
                                        }
                                }
                        }
                };
            mdDataIdentificationType.topicCategory = new[] { new MD_TopicCategoryCode_PropertyType
                {
                    MD_TopicCategoryCode =  MD_TopicCategoryCode_Type.location
                }
            };
            mdDataIdentificationType.extent = new[]
                {
                    new EX_Extent_PropertyType
                        {
                            EX_Extent = new EX_Extent_Type
                                {
                                    geographicElement = new []
                                        {
                                            new EX_GeographicExtent_PropertyType
                                                {
                                                    AbstractEX_GeographicExtent = new EX_GeographicBoundingBox_Type
                                                        {
                                                            westBoundLongitude = new Decimal_PropertyType { Decimal = 2 },
                                                            eastBoundLongitude = new Decimal_PropertyType { Decimal = 33 },
                                                            southBoundLatitude = new Decimal_PropertyType { Decimal = 57 },
                                                            northBoundLatitude = new Decimal_PropertyType { Decimal = 72 }
                                                        }
                                                }
                                        },
                                    temporalElement = new EX_TemporalExtent_PropertyType[]
                                    {
                                        new EX_TemporalExtent_PropertyType
                                        {
                                            EX_TemporalExtent = new EX_TemporalExtent_Type
                                            {
                                                extent = new TM_Primitive_PropertyType
                                                {
                                                      AbstractTimePrimitive = new TimePeriodType()
                                                      {
                                                         id="id_1",

                                                            Item = new TimePositionType()
                                                            {
                                                                Value = "2014-01-01"
                                                            },
                                                            Item1 = new TimePositionType()
                                                            {
                                                                Value = "2020-01-01"
                                                            }
                                                      }
                                                }
                                            }
                                        }
                                    }

                                }
                        }
                };

            mdDataIdentificationType.supplementalInformation = CharString("Dette er den utfyllende informasjonen.");

            m.identificationInfo = new[] {
                new MD_Identification_PropertyType
                    {
                        AbstractMD_Identification = mdDataIdentificationType
                    }
            };

            m.distributionInfo = new MD_Distribution_PropertyType
            {
                MD_Distribution = new MD_Distribution_Type
                {
                    transferOptions = new[]
                                {
                                    new MD_DigitalTransferOptions_PropertyType
                                        {
                                            MD_DigitalTransferOptions = new MD_DigitalTransferOptions_Type
                                                {
                                                    onLine = new[]
                                                        {
                                                            new CI_OnlineResource_PropertyType
                                                                {
                                                                    CI_OnlineResource = new CI_OnlineResource_Type
                                                                        {
                                                                            linkage = new URL_PropertyType
                                                                                {
                                                                                    URL = "http://www.kartverket.no"
                                                                                }
                                                                        }
                                                                }
                                                        }
                                                }
                                        }
                                }
                }
            };

            var dqDataQualityType = new DQ_DataQuality_Type();
            dqDataQualityType.scope = new DQ_Scope_PropertyType
            {
                DQ_Scope = new DQ_Scope_Type
                {
                    level = new MD_ScopeCode_PropertyType
                    {
                        MD_ScopeCode = new CodeListValue_Type
                        {
                            codeList = "http://www.isotc211.org/2005/resources/codeList.xml#MD_ScopeCode",
                            codeListValue = "dataset"
                        }
                    }
                }
            };
            dqDataQualityType.lineage = new LI_Lineage_PropertyType
            {
                LI_Lineage = new LI_Lineage_Type
                {
                    statement = CharString("Her kommer det en tekst om prosesshistorien.")
                }
            };
            dqDataQualityType.report = new[]
                {
                    new DQ_Element_PropertyType
                        {
                            AbstractDQ_Element = new DQ_DomainConsistency_Type
                                {
                                    result = new [] {
                                        new DQ_Result_PropertyType
                                        {
                                            AbstractDQ_Result = new DQ_ConformanceResult_Type
                                                {
                                                    specification = new CI_Citation_PropertyType
                                                        {
                                                            CI_Citation = new CI_Citation_Type
                                                                {
                                                                    title = CharString("COMMISSION REGULATION (EU) No 1089/2010 of 23 November 2010 implementing Directive 2007/2/EC of the European Parliament and of the Council as regards interoperability of spatial data sets and services"),
                                                                    date = new CI_Date_PropertyType[]
                                                                        {
                                                                            new CI_Date_PropertyType
                                                                                {
                                                                                    CI_Date = new CI_Date_Type
                                                                                        {
                                                                                            date = new Date_PropertyType
                                                                                                {
                                                                                                   Item = "2010-12-08"
                                                                                                },
                                                                                            dateType = new CI_DateTypeCode_PropertyType
                                                                                                {
                                                                                                    CI_DateTypeCode = new CodeListValue_Type
                                                                                                        {
                                                                                                            codeList = "http://standards.iso.org/ittf/PubliclyAvailableStandards/ISO_19139_Schemas/resources/Codelist/ML_gmxCodelists.xml#CI_DateTypeCode",
                                                                                                            codeListValue = "publication"
                                                                                                        }
                                                                                                }
                                                                                        }
                                                                                }
                                                                        }
                                                                }
                                                        },
                                                    explanation = CharString("See the referenced specification"),
                                                    pass = new Boolean_PropertyType { Boolean = true }
                                                }
                                        }
                                    }
                                }
                        }
                };

            m.dataQualityInfo = new[] { new DQ_DataQuality_PropertyType { DQ_DataQuality = dqDataQualityType } };

            m.referenceSystemInfo = new MD_ReferenceSystem_PropertyType[]
            {
                new MD_ReferenceSystem_PropertyType
                {
                    MD_ReferenceSystem = new MD_ReferenceSystem_Type
                    {
                        referenceSystemIdentifier = new RS_Identifier_PropertyType
                        {
                            RS_Identifier = new RS_Identifier_Type
                            {
                                code = new CharacterString_PropertyType
                                {
                                    CharacterString = "http://www.opengis.net/def/crs/EPSG/0/25831"
                                },
                                codeSpace = new CharacterString_PropertyType
                                {
                                    CharacterString = "EPSG"
                                }
                            }
                        }
                    }
                }
            };

            return m;
        }
        private CI_ResponsibleParty_Type PopuplateResponsiblePartyFromSimpleContact(CI_ResponsibleParty_Type responsibleParty, SimpleContact contact)
        {
            responsibleParty.individualName = new CharacterString_PropertyType { CharacterString = contact.Name };

            if (!string.IsNullOrWhiteSpace(contact.OrganizationEnglish))
            {
                responsibleParty.organisationName = CreateFreeTextElement(contact.Organization, contact.OrganizationEnglish);
            }
            else
            {
                responsibleParty.organisationName = new CharacterString_PropertyType { CharacterString = contact.Organization };
            }

            if (responsibleParty.contactInfo == null)
            {
                responsibleParty.contactInfo = new CI_Contact_PropertyType
                {
                    CI_Contact = new CI_Contact_Type
                    {
                        address = new CI_Address_PropertyType
                        {
                            CI_Address = new CI_Address_Type()
                        }
                    }
                };
            }
            if (responsibleParty.contactInfo.CI_Contact == null)
            {
                responsibleParty.contactInfo.CI_Contact = new CI_Contact_Type
                {
                    address = new CI_Address_PropertyType
                    {
                        CI_Address = new CI_Address_Type()
                    }
                };
            }
            if (responsibleParty.contactInfo.CI_Contact.address == null)
            {
                responsibleParty.contactInfo.CI_Contact.address = new CI_Address_PropertyType
                {
                    CI_Address = new CI_Address_Type()
                };
            }
            if (responsibleParty.contactInfo.CI_Contact.address.CI_Address == null)
            {
                responsibleParty.contactInfo.CI_Contact.address.CI_Address = new CI_Address_Type();
            }

            responsibleParty.contactInfo.CI_Contact.address.CI_Address.electronicMailAddress = new CharacterString_PropertyType[] {
                    new CharacterString_PropertyType { CharacterString = contact.Email }
                };

            responsibleParty.role = new CI_RoleCode_PropertyType
            {
                CI_RoleCode = new CodeListValue_Type
                {
                    codeList = "http://standards.iso.org/ittf/PubliclyAvailableStandards/ISO_19139_Schemas/resources/Codelist/ML_gmxCodelists.xml#CI_RoleCode",
                    codeListValue = contact.Role
                }
            };
            return responsibleParty;
        }
 private CI_ResponsibleParty_Type CreateResponsiblePartyFromSimpleContact(SimpleContact contact)
 {
     CI_ResponsibleParty_Type responsibleParty = new CI_ResponsibleParty_Type();
     PopuplateResponsiblePartyFromSimpleContact(responsibleParty, contact);
     return responsibleParty;
 }
        private SimpleContact ParseResponsiblePartyToSimpleContact(CI_ResponsibleParty_Type responsibleParty)
        {
            string email = null;
            if (responsibleParty.contactInfo != null && responsibleParty.contactInfo.CI_Contact != null && responsibleParty.contactInfo.CI_Contact.address != null
                && responsibleParty.contactInfo.CI_Contact.address.CI_Address != null
                && responsibleParty.contactInfo.CI_Contact.address.CI_Address.electronicMailAddress != null
                && responsibleParty.contactInfo.CI_Contact.address.CI_Address.electronicMailAddress[0] != null
                && responsibleParty.contactInfo.CI_Contact.address.CI_Address.electronicMailAddress[0].CharacterString != null)
            {
                email = responsibleParty.contactInfo.CI_Contact.address.CI_Address.electronicMailAddress[0].CharacterString;
            }

            string role = null;
            if (responsibleParty.role != null && responsibleParty.role.CI_RoleCode != null)
            {
                role = responsibleParty.role.CI_RoleCode.codeListValue;
            }

            return new SimpleContact
            {
                Name = GetStringOrNull(responsibleParty.individualName),
                Organization = GetStringOrNull(responsibleParty.organisationName),
                OrganizationEnglish = GetEnglishValueFromFreeText(responsibleParty.organisationName),
                Email = email,
                Role = role
            };
        }
        private void CreateOrUpdateContactWithRole(string roleCodeValue, SimpleContact contact)
        {
            CI_ResponsibleParty_Type responsibleParty = GetContactInformationResponsiblePartyWithRole(roleCodeValue);
            if (responsibleParty == null)
            {
                responsibleParty = new CI_ResponsibleParty_Type();

                var newPointOfContactArray = new CI_ResponsibleParty_PropertyType[] {
                        new CI_ResponsibleParty_PropertyType {
                            CI_ResponsibleParty = responsibleParty
                        }
                    };

                var identification = GetIdentificationNotNull();
                if (identification.pointOfContact == null)
                {
                    identification.pointOfContact = newPointOfContactArray;
                }
                else
                {
                    identification.pointOfContact = identification.pointOfContact.Concat(newPointOfContactArray).ToArray();
                }
            }

            PopuplateResponsiblePartyFromSimpleContact(responsibleParty, contact);
        }