public bool HasAssemblyAttribute(string name) { _assemblyImport.GetAssemblyFromScope(out uint assemblyScope); IMetaDataImport2 import2 = (IMetaDataImport2)_assemblyImport; IntPtr valuePtr = IntPtr.Zero; import2.GetCustomAttributeByName(assemblyScope, name, out valuePtr, out uint valueLen); return(valueLen != 0); }
public bool HasAssemblyAttribute(string name) { uint num; this._assemblyImport.GetAssemblyFromScope(out num); IMetaDataImport2 import = (IMetaDataImport2)this._assemblyImport; IntPtr zero = IntPtr.Zero; uint pcbData = 0; import.GetCustomAttributeByName(num, name.ToCharArray(), out zero, out pcbData); return(pcbData != 0); }
// Token: 0x06000E18 RID: 3608 RVA: 0x00037CB0 File Offset: 0x00035EB0 public bool HasAssemblyAttribute(string name) { uint mdTokenObj; this._assemblyImport.GetAssemblyFromScope(out mdTokenObj); IMetaDataImport2 metaDataImport = (IMetaDataImport2)this._assemblyImport; IntPtr zero = IntPtr.Zero; uint num = 0u; metaDataImport.GetCustomAttributeByName(mdTokenObj, name, out zero, out num); return(num > 0u); }
/// <summary> /// Get the framework name from the assembly. /// </summary> private FrameworkName GetFrameworkName() { FrameworkName frameworkAttribute = null; try { IMetaDataImport2 import2 = (IMetaDataImport2)_assemblyImport; IntPtr data = IntPtr.Zero; UInt32 valueLen = 0; string frameworkNameAttribute = null; UInt32 assemblyScope; _assemblyImport.GetAssemblyFromScope(out assemblyScope); int hr = import2.GetCustomAttributeByName(assemblyScope, s_targetFrameworkAttribute, out data, out valueLen); // get the AssemblyTitle if (hr == NativeMethodsShared.S_OK) { // if an AssemblyTitle exists, parse the contents of the blob if (NativeMethods.TryReadMetadataString(_sourceFile, data, valueLen, out frameworkNameAttribute)) { if (!String.IsNullOrEmpty(frameworkNameAttribute)) { frameworkAttribute = new FrameworkName(frameworkNameAttribute); } } } } catch (Exception e) { if (ExceptionHandling.IsCriticalException(e)) { throw; } } return(frameworkAttribute); }
/// <summary> /// Get the framework name from the assembly. /// </summary> private FrameworkName GetFrameworkName() { // Disabling use of System.Reflection in case of MONO, because // Assembly.GetCustomAttributes* for an attribute which belongs // to an assembly that mono cannot find, causes a crash! // Instead, opt for using PEReader and friends to get that info #if FEATURE_ASSEMBLY_LOADFROM && !MONO if (!NativeMethodsShared.IsWindows) { if (String.Equals(Environment.GetEnvironmentVariable("MONO29679"), "1", StringComparison.OrdinalIgnoreCase)) { // Getting custom attributes in CoreFx contract assemblies is busted // https://bugzilla.xamarin.com/show_bug.cgi?id=29679 return(null); } CustomAttributeData attr = null; foreach (CustomAttributeData a in _assembly.GetCustomAttributesData()) { try { if (a.AttributeType.Equals(typeof(TargetFrameworkAttribute))) { attr = a; break; } } catch { } } string name = null; if (attr != null) { name = (string)attr.ConstructorArguments[0].Value; } return(name == null ? null : new FrameworkName(name)); } FrameworkName frameworkAttribute = null; try { IMetaDataImport2 import2 = (IMetaDataImport2)_assemblyImport; IntPtr data = IntPtr.Zero; UInt32 valueLen = 0; string frameworkNameAttribute = null; UInt32 assemblyScope; _assemblyImport.GetAssemblyFromScope(out assemblyScope); int hr = import2.GetCustomAttributeByName(assemblyScope, s_targetFrameworkAttribute, out data, out valueLen); // get the AssemblyTitle if (hr == NativeMethodsShared.S_OK) { // if an AssemblyTitle exists, parse the contents of the blob if (NativeMethods.TryReadMetadataString(_sourceFile, data, valueLen, out frameworkNameAttribute)) { if (!String.IsNullOrEmpty(frameworkNameAttribute)) { frameworkAttribute = new FrameworkName(frameworkNameAttribute); } } } } catch (Exception e) { if (ExceptionHandling.IsCriticalException(e)) { throw; } } return(frameworkAttribute); #else CorePopulateMetadata(); return(_frameworkName); #endif }
/// <summary> /// Get the framework name from the assembly. /// </summary> private FrameworkName GetFrameworkName() { // Disabling use of System.Reflection in case of MONO, because // Assembly.GetCustomAttributes* for an attribute which belongs // to an assembly that mono cannot find, causes a crash! // Instead, opt for using PEReader and friends to get that info #if FEATURE_ASSEMBLY_LOADFROM && !MONO if (!NativeMethodsShared.IsWindows) { if (String.Equals(Environment.GetEnvironmentVariable("MONO29679"), "1", StringComparison.OrdinalIgnoreCase)) { // Getting custom attributes in CoreFx contract assemblies is busted // https://bugzilla.xamarin.com/show_bug.cgi?id=29679 return(null); } CustomAttributeData attr = null; foreach (CustomAttributeData a in _assembly.GetCustomAttributesData()) { try { if (a.AttributeType.Equals(typeof(TargetFrameworkAttribute))) { attr = a; break; } } catch { } } string name = null; if (attr != null) { name = (string)attr.ConstructorArguments[0].Value; } return(name == null ? null : new FrameworkName(name)); } FrameworkName frameworkAttribute = null; try { IMetaDataImport2 import2 = (IMetaDataImport2)_assemblyImport; IntPtr data = IntPtr.Zero; UInt32 valueLen = 0; string frameworkNameAttribute = null; UInt32 assemblyScope; _assemblyImport.GetAssemblyFromScope(out assemblyScope); int hr = import2.GetCustomAttributeByName(assemblyScope, s_targetFrameworkAttribute, out data, out valueLen); // get the AssemblyTitle if (hr == NativeMethodsShared.S_OK) { // if an AssemblyTitle exists, parse the contents of the blob if (NativeMethods.TryReadMetadataString(_sourceFile, data, valueLen, out frameworkNameAttribute)) { if (!String.IsNullOrEmpty(frameworkNameAttribute)) { frameworkAttribute = new FrameworkName(frameworkNameAttribute); } } } } catch (Exception e) { if (ExceptionHandling.IsCriticalException(e)) { throw; } } return(frameworkAttribute); #else using (var stream = File.OpenRead(_sourceFile)) using (var peFile = new PEReader(stream)) { var metadataReader = peFile.GetMetadataReader(); var attrs = metadataReader.GetAssemblyDefinition().GetCustomAttributes() .Select(ah => metadataReader.GetCustomAttribute(ah)); foreach (var attr in attrs) { var ctorHandle = attr.Constructor; if (ctorHandle.Kind != HandleKind.MemberReference) { continue; } var container = metadataReader.GetMemberReference((MemberReferenceHandle)ctorHandle).Parent; var name = metadataReader.GetTypeReference((TypeReferenceHandle)container).Name; if (!string.Equals(metadataReader.GetString(name), "TargetFrameworkAttribute")) { continue; } var arguments = GetFixedStringArguments(metadataReader, attr); if (arguments.Count == 1) { return(new FrameworkName(arguments[0])); } } } return(null); #endif }