/// <summary> /// Resolves a static resource of the specified name on the specified resource /// <see cref="Type"/>. /// </summary> /// <typeparam name="T">The <see cref="Type"/> of the resource that will be resolved. /// </typeparam> /// <param name="resourceType">The <see cref="Type"/> to search for the resource that will /// be resolved.</param> /// <param name="resourceName">The name of the resource that will be resolved.</param> /// <returns>The value of the resource that was resolved.</returns> /// <exception cref="ArgumentNullException"><paramref name="resourceType"/>, or /// <paramref name="resourceName"/> is <see langword="null"/>.</exception> /// <exception cref="ArgumentException"><paramref name="resourceName"/> is empty. /// </exception> /// <exception cref="InvalidOperationException">The specified resource was not found. /// </exception> /// <exception cref="InvalidCastException">The value of the resolved resource could not be /// cast to the type specified by <typeparamref name="T"/>.</exception> public static T ResolveResource <T>(Type resourceType, string resourceName) { ParameterValidation.IsNotNull(resourceType, nameof(resourceType)); ParameterValidation.IsNotNull(resourceName, nameof(resourceName)); ParameterValidation.IsNotEmpty(resourceName, nameof(resourceName)); var propertyInfo = resourceType.GetProperty( resourceName, BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic); if (propertyInfo == null) { throw new InvalidOperationException("Specified resource not found."); } return((T)propertyInfo.GetValue(null)); }
/// <summary> /// Initializes a new instance of the <see cref="Iso3166Country" /> class with the /// specified ISO 3166-1 alpha-2 country code. /// </summary> /// <param name="countryCode">The ISO 3166-1 alpha-2 country code.</param> /// <exception cref="ArgumentNullException"><paramref name="countryCode"/> is /// <see langword="null"/>.</exception> /// <exception cref="ArgumentException"><paramref name="countryCode"/> is an invalid ISO /// 3166-1 alpha-2 country code. /// supplied.</exception> public Iso3166Country(string countryCode) { ParameterValidation.IsNotNull(countryCode, nameof(countryCode)); this.CountryCode = countryCode.ToUpperInvariant(); string countryName; if (countryCode.Length != 2 || !Iso3166Helper.CountryCodeMappingsInternal .TryGetValue(this.CountryCode, out countryName)) { throw new ArgumentException( "Value must be a valid ISO 3166-1 alpha-2 country code.", nameof(countryCode)); } this.CountryName = countryName; // Use Lazy for its exception caching so countries that don't have region info available // don't throw an exception here in the constructor. this.regionInfo = new Lazy <RegionInfo>(() => new RegionInfo(this.CountryCode)); }