// Build a mapping from a country calling code to the region codes which denote the country/region
        // represented by that country code. In the case of multiple countries sharing a calling code,
        // such as the NANPA countries, the one indicated with "isMainCountryForCode" in the metadata
        // should be first.
        public static Dictionary <int, List <String> > BuildCountryCodeToRegionCodeMap(
            PhoneMetadataCollection metadataCollection)
        {
            Dictionary <int, List <String> > countryCodeToRegionCodeMap =
                new Dictionary <int, List <String> >();

            foreach (PhoneMetadata metadata in metadataCollection.MetadataList)
            {
                String regionCode  = metadata.Id;
                int    countryCode = metadata.CountryCode;
                if (countryCodeToRegionCodeMap.ContainsKey(countryCode))
                {
                    if (metadata.MainCountryForCode)
                    {
                        countryCodeToRegionCodeMap[countryCode].Insert(0, regionCode);
                    }
                    else
                    {
                        countryCodeToRegionCodeMap[countryCode].Add(regionCode);
                    }
                }
                else
                {
                    // For most countries, there will be only one region code for the country calling code.
                    List <String> listWithRegionCode = new List <String>(1);
                    if (regionCode.Length > 0)
                    {
                        listWithRegionCode.Add(regionCode);
                    }
                    countryCodeToRegionCodeMap[countryCode] = listWithRegionCode;
                }
            }
            return(countryCodeToRegionCodeMap);
        }
        // Build a mapping from a country calling code to the region codes which denote the country/region
        // represented by that country code. In the case of multiple countries sharing a calling code,
        // such as the NANPA countries, the one indicated with "isMainCountryForCode" in the metadata
        // should be first.
        public static Dictionary <int, List <string> > BuildCountryCodeToRegionCodeMap(
            PhoneMetadataCollection metadataCollection)
        {
            var countryCodeToRegionCodeMap =
                new Dictionary <int, List <string> >();

            foreach (var metadata in metadataCollection.MetadataList)
            {
                var regionCode  = metadata.Id;
                var countryCode = metadata.CountryCode;
                if (countryCodeToRegionCodeMap.TryGetValue(countryCode, out var list))
                {
                    if (metadata.MainCountryForCode)
                    {
                        list.Insert(0, regionCode);
                    }
                    else
                    {
                        list.Add(regionCode);
                    }
                }
                else
                {
                    // For most countries, there will be only one region code for the country calling code.
                    var listWithRegionCode = new List <string>(1);
                    if (regionCode.Length > 0)
                    {
                        listWithRegionCode.Add(regionCode);
                    }
                    countryCodeToRegionCodeMap[countryCode] = listWithRegionCode;
                }
            }
            return(countryCodeToRegionCodeMap);
        }
 // Build a mapping from a country calling code to the region codes which denote the country/region
 // represented by that country code. In the case of multiple countries sharing a calling code,
 // such as the NANPA countries, the one indicated with "isMainCountryForCode" in the metadata
 // should be first.
 public static Dictionary<int, List<String>> BuildCountryCodeToRegionCodeMap(
     PhoneMetadataCollection metadataCollection)
 {
     Dictionary<int, List<String>> countryCodeToRegionCodeMap =
         new Dictionary<int, List<String>>();
     foreach (PhoneMetadata metadata in metadataCollection.MetadataList)
     {
         String regionCode = metadata.Id;
         int countryCode = metadata.CountryCode;
         if (countryCodeToRegionCodeMap.ContainsKey(countryCode))
         {
             if (metadata.MainCountryForCode)
                 countryCodeToRegionCodeMap[countryCode].Insert(0, regionCode);
             else
                 countryCodeToRegionCodeMap[countryCode].Add(regionCode);
         }
         else
         {
             // For most countries, there will be only one region code for the country calling code.
             List<String> listWithRegionCode = new List<String>(1);
             if(regionCode.Length > 0)
                 listWithRegionCode.Add(regionCode);
             countryCodeToRegionCodeMap[countryCode] = listWithRegionCode;
         }
     }
     return countryCodeToRegionCodeMap;
 }
예제 #4
0
            public PhoneMetadataCollection BuildPartial()
            {
                if (MessageBeingBuilt == null)
                {
                    throw new InvalidOperationException("build() has already been called on this Builder");
                }

                var returnMe = MessageBeingBuilt;

                MessageBeingBuilt = null;
                return(returnMe);
            }
예제 #5
0
 public Builder MergeFrom(PhoneMetadataCollection other)
 {
     if (other == DefaultInstance)
     {
         return(this);
     }
     if (other.metadata.Count != 0)
     {
         MessageBeingBuilt.metadata.AddRange(other.metadata);
     }
     return(this);
 }
        static private void LoadMedataFromFile(int countryCallingCode)
        {
            var fileName = ALTERNATE_FORMATS_FILE_PREFIX + "_" + countryCallingCode.ToString();

            var asm  = typeof(MetadataManager).GetTypeInfo().Assembly;
            var name = asm.GetManifestResourceNames().Where(n => n.EndsWith(fileName)).FirstOrDefault() ?? "missing";

            using (var stream = asm.GetManifestResourceStream(name))
            {
                var meta = PhoneMetadataCollection.ParseFrom(stream);
                foreach (var m in meta.MetadataList)
                {
                    callingCodeToAlternateFormatsMap[m.CountryCode] = m;
                }
            }
        }
 public Builder MergeFrom(PhoneMetadataCollection other)
 {
     if (other == global::PhoneNumbers.PhoneMetadataCollection.DefaultInstance) return this;
     if (other.metadata_.Count != 0) {
        result.metadata_.AddRange(other.metadata_);
     }
     return this;
 }
 public Builder Clear()
 {
     result = new PhoneMetadataCollection();
     return this;
 }
            public PhoneMetadataCollection BuildPartial()
            {
                if (result == null) {
                  throw new global::System.InvalidOperationException("build() has already been called on this Builder");
                }

                PhoneMetadataCollection returnMe = result;
                result = null;
                return returnMe;
            }
 public static Builder CreateBuilder(PhoneMetadataCollection prototype)
 {
     return (Builder) new Builder().MergeFrom(prototype);
 }
예제 #11
0
 public Builder Clear()
 {
     MessageBeingBuilt = new PhoneMetadataCollection();
     return(this);
 }
예제 #12
0
 public static Builder CreateBuilder(PhoneMetadataCollection prototype)
 {
     return(new Builder().MergeFrom(prototype));
 }