コード例 #1
0
        // 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);
        }
コード例 #3
0
 // 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);
 }
コード例 #6
0
        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;
                }
            }
        }
コード例 #7
0
 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;
 }
コード例 #8
0
 public Builder Clear()
 {
     result = new PhoneMetadataCollection();
     return this;
 }
コード例 #9
0
            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;
            }
コード例 #10
0
 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));
 }