public AssemblyCultureAttributeTest() { //create a dynamic assembly with the required attribute //and check for the validity dynAsmName.Name = "TestAssembly"; dynAssembly = Thread.GetDomain().DefineDynamicAssembly( dynAsmName, AssemblyBuilderAccess.Run ); // Set the required Attribute of the assembly. Type attribute = typeof(AssemblyCultureAttribute); ConstructorInfo ctrInfo = attribute.GetConstructor( new Type [] { typeof(string) } ); CustomAttributeBuilder attrBuilder = new CustomAttributeBuilder(ctrInfo, new object [1] { "India" }); dynAssembly.SetCustomAttribute(attrBuilder); object [] attributes = dynAssembly.GetCustomAttributes(true); attr = attributes [0] as AssemblyCultureAttribute; }
public static void AssemblyCultureAttributeTests() { var attr1 = new AssemblyCultureAttribute(null); Assert.Null(attr1.Culture); var attr2 = new AssemblyCultureAttribute("Czech"); Assert.Equal("Czech", attr2.Culture); }
private void Get_AllVariables(Assembly a) { AssemblyTitleAttribute titleAttr = null; AssemblyDescriptionAttribute descAttr = null; AssemblyCopyrightAttribute copyAttr = null; AssemblyProductAttribute prodAttr = null; AssemblyTrademarkAttribute tradeAttr = null; AssemblyCultureAttribute cultureAttr = null; AssemblyVersionAttribute versionAttr = null; AssemblyCompanyAttribute companyAttr = null; try { titleAttr = a.GetCustomAttribute <AssemblyTitleAttribute>() ?? new AssemblyTitleAttribute("No assembly title"); descAttr = a.GetCustomAttribute <AssemblyDescriptionAttribute>() ?? new AssemblyDescriptionAttribute("No description"); copyAttr = a.GetCustomAttribute <AssemblyCopyrightAttribute>() ?? new AssemblyCopyrightAttribute("No copyright"); prodAttr = a.GetCustomAttribute <AssemblyProductAttribute>() ?? new AssemblyProductAttribute("No product information"); tradeAttr = a.GetCustomAttribute <AssemblyTrademarkAttribute>() ?? new AssemblyTrademarkAttribute(string.Empty); // Trademark was in older .Net 3.5 apps but has not made its way into .Net Core cultureAttr = a.GetCustomAttribute <AssemblyCultureAttribute>() ?? new AssemblyCultureAttribute("en-US"); versionAttr = a.GetCustomAttribute <AssemblyVersionAttribute>() ?? new AssemblyVersionAttribute("0.0.0.0"); companyAttr = a.GetCustomAttribute <AssemblyCompanyAttribute>() ?? new AssemblyCompanyAttribute("No company specified"); this._title = titleAttr.Title; this._description = descAttr.Description; this._copywrite = copyAttr.Copyright; this._product = prodAttr.Product; this._trademark = tradeAttr.Trademark; this._culture = cultureAttr.Culture; this._appCultureInfo = new CultureInfo(this._culture); this._version = versionAttr.Version; this._AppVersion = new Version(this._version); this._company = companyAttr.Company; } catch (Exception ex) { // Oh dear ... this._title = "An error happened trying to get the application information."; this._description = string.Format("{0}. {1}", ex.GetType().ToString(), ex.Message); } finally { a = null; descAttr = null; copyAttr = null; prodAttr = null; tradeAttr = null; cultureAttr = null; versionAttr = null; companyAttr = null; descAttr = null; titleAttr = null; } }
/// <summary> /// Gets the culture of the specified assembly. /// </summary> /// <remarks> /// <para> /// To retrieve the culture of the specified assembly, we first try to /// read a <see cref="System.Reflection.AssemblyCultureAttribute"/> if present. /// </para> /// <para> /// If not, we rely on the parsing of the specified assembly display name /// (<see cref="ReflectionExtensions.GetProperties"/>). /// </para> /// <para> /// We assume that a call to <see cref="System.Reflection.Assembly.ToString"/> should give us /// back a result similar to: <c>Delta.CertXplorerV3.resources, Version=3.0.0.0, Culture=fr, PublicKeyToken=null</c>. /// </para> /// </remarks> /// <param name="assembly">The assembly.</param> /// <returns></returns> public static CultureInfo GetCulture(this Assembly assembly) { if (assembly == null) { throw new ArgumentNullException("assembly"); } // Search for the CultureAttribute object[] attributes = assembly.GetCustomAttributes(typeof(AssemblyCultureAttribute), false); var cultureString = string.Empty; if (attributes.Length > 0) { AssemblyCultureAttribute cultureAttribute = (AssemblyCultureAttribute)attributes[0]; cultureString = cultureAttribute.Culture; } else // This doesn't mean the assembly has no culture { // At this step, we determine the culture by parsing the assembly name. var elements = GetProperties(assembly); if (elements.ContainsKey("Culture")) { cultureString = elements["Culture"]; } } if (!string.IsNullOrEmpty(cultureString)) { if (cultureString == "neutral") { return(CultureInfo.InvariantCulture); } try { var culture = new CultureInfo(cultureString); return(culture); } catch (Exception ex) // not a culture info { var debugEx = ex; return(CultureInfo.InvariantCulture); } } else { return(CultureInfo.InvariantCulture); } }
static void Main(string[] args) { System.Reflection.AssemblyCultureAttribute a = new AssemblyCultureAttribute(""); Console.WriteLine("Attribute: " + a); Console.WriteLine("Start"); Forms.Init(); var mainPage = new MainPage(); UI.Publish("/", mainPage.GetOouiElement()); Console.WriteLine("End"); }
public void CtorTest() { var a = new AssemblyCultureAttribute("en"); Assert.AreEqual("en", a.Culture); }
public void Ctor_String(string culture) { var attribute = new AssemblyCultureAttribute(culture); Assert.Equal(culture, attribute.Culture); }