public void Ctor_String_String(string key, string value) { var attribute = new AssemblyMetadataAttribute(key, value); Assert.Equal(key, attribute.Key); Assert.Equal(value, attribute.Value); }
public void CtorTest() { var a = new AssemblyMetadataAttribute("some text", "some other text"); Assert.AreEqual("some text", a.Key); Assert.AreEqual("some other text", a.Value); }
public AssemblyMetadataAttributeTest() { //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(AssemblyMetadataAttribute); ConstructorInfo ctrInfo = attribute.GetConstructor( new Type [] { typeof(string), typeof(string) } ); CustomAttributeBuilder attrBuilder = new CustomAttributeBuilder(ctrInfo, new object [2] { "MyKey", "MyValue" }); dynAssembly.SetCustomAttribute(attrBuilder); object [] attributes = dynAssembly.GetCustomAttributes(true); attr = attributes [0] as AssemblyMetadataAttribute; }
private static (string metadataPath, string metadataIncludeByDefault) ParseMetadataAttribute( AssemblyMetadataAttribute metadataAttribute) { var data = metadataAttribute.Value.Split(MetadataSeparators); if (data.Length != 2 || string.IsNullOrWhiteSpace(data[0]) || string.IsNullOrWhiteSpace(data[1])) { return(default);
public static String GetProjectName() { Assembly assembly = Assembly.GetExecutingAssembly(); Attribute[] attributes = AssemblyMetadataAttribute.GetCustomAttributes(assembly, typeof(AssemblyMetadataAttribute)); var srcAtribute = attributes.FirstOrDefault(x => (x as AssemblyMetadataAttribute).Key == "source"); return(srcAtribute != null ? (srcAtribute as AssemblyMetadataAttribute).Value : String.Empty); }
public static void AssemblyMetadataAttributeTests() { var attr1 = new AssemblyMetadataAttribute(null, null); Assert.Null(attr1.Key); Assert.Null(attr1.Value); var attr2 = new AssemblyMetadataAttribute("My Key", "My Value"); Assert.Equal("My Key", attr2.Key); Assert.Equal("My Value", attr2.Value); }
public override void Write(Vault vault, BinaryWriter bw) { Assembly currentAssembly = Assembly.GetAssembly(typeof(Database)); AssemblyMetadataAttribute metadataAttribute = currentAssembly.GetCustomAttributes <AssemblyMetadataAttribute>().First(m => m.Key == "GitHash"); Strings.Insert(0, "Generated by VaultBoy by heyitsleo"); Strings.Insert(1, $"{metadataAttribute.Value} | {DateTime.Now:s}"); foreach (string s in Strings) { vault.SaveContext.StringOffsets[s] = bw.BaseStream.Position; NullTerminatedString.Write(bw, s); } bw.AlignWriter(0x10); }
private static Assembly LoadFromMetadata(Assembly assembly, AssemblyMetadataAttribute metadataAttribute) { var(metadataPath, metadataIncludeByDefault) = ParseMetadataAttribute(metadataAttribute); if (metadataPath == null || metadataIncludeByDefault == null || !string.Equals(metadataIncludeByDefault, "true", StringComparison.OrdinalIgnoreCase)) { return(null); } var fileName = Path.GetFileName(metadataPath); var filePath = Path.Combine(Path.GetDirectoryName(assembly.Location), fileName); var additionalAssembly = LoadAssembly(filePath); if (additionalAssembly == null) { return(null); } return(additionalAssembly); }
static AssemblyResources() { var asm = Assembly.GetEntryAssembly(); var metadata = asm?.GetCustomAttributes <AssemblyMetadataAttribute>(); AssemblyTitleAttribute titleAttribute = null; try { titleAttribute = asm?.GetCustomAttribute <AssemblyTitleAttribute>(); } finally { Title = titleAttribute?.Title ?? "Paymetheus"; } AssemblyProductAttribute productAttribute = null; try { productAttribute = asm?.GetCustomAttribute <AssemblyProductAttribute>(); } finally { ProductName = productAttribute?.Product ?? "Paymetheus"; } AssemblyMetadataAttribute organizationAttribute = null; try { organizationAttribute = metadata?.FirstOrDefault(a => a.Key == "Organization"); } finally { Organization = organizationAttribute?.Value ?? ""; } }
// CoreCLR: When running under AppX, the following rules apply for resource lookup: // // 1) For Framework assemblies, we always use satellite assembly based lookup. // 2) For non-FX assemblies: // // a) If the assembly lives under PLATFORM_RESOURCE_ROOTS (as specified by the host during AppDomain creation), // then we will use satellite assembly based lookup in assemblies like *.resources.dll. // // b) For any other non-FX assembly, we will use the modern resource manager with the premise that app package // contains the PRI resources. // // .NET Native: If it is framework assembly we'll return true. The reason is in .NetNative we don't merge the // resources to the app PRI file. // The framework assemblies are tagged with attribute [assembly: AssemblyMetadata(".NETFrameworkAssembly", "")] private bool ShouldUseSatelliteAssemblyResourceLookupUnderAppX(Assembly resourcesAssembly) { if (typeof(object).Assembly == resourcesAssembly) { return(true); } #if FEATURE_APPX // Check to see if the assembly is under PLATFORM_RESOURCE_ROOTS. If it is, then we should use satellite assembly lookup for it. string platformResourceRoots = (string)(AppContext.GetData("PLATFORM_RESOURCE_ROOTS")); if ((platformResourceRoots != null) && (platformResourceRoots != string.Empty)) { string resourceAssemblyPath = resourcesAssembly.Location; // Loop through the PLATFORM_RESOURCE_ROOTS and see if the assembly is contained in it. foreach (string pathPlatformResourceRoot in platformResourceRoots.Split(Path.PathSeparator)) { if (resourceAssemblyPath.StartsWith(pathPlatformResourceRoot, StringComparison.CurrentCultureIgnoreCase)) { // Found the resource assembly to be present in one of the PLATFORM_RESOURCE_ROOT, so stop the enumeration loop. return(true); } } } #else // ENABLE_WINRT foreach (var attrib in resourcesAssembly.GetCustomAttributes()) { AssemblyMetadataAttribute meta = attrib as AssemblyMetadataAttribute; if (meta != null && meta.Key.Equals(".NETFrameworkAssembly")) { return(true); } } #endif return(false); }