System.Reflection.Assembly.Assembly.GetName C# (CSharp) Method

GetName() public method

public GetName ( ) : AssemblyName
return AssemblyName
		public virtual AssemblyName GetName ()
		{
			return GetName (false);
		}

Same methods

Assembly.Assembly::GetName ( Boolean copiedName ) : AssemblyName

Usage Example

        internal static IEnumerable<KeyValuePair<string, object>> EnumerateMetadata(Assembly assembly)
        {
            ComponentName cname = ComponentName.FromAssemblyName(assembly.GetName());

            var data = assembly.GetCustomAttributesData();
            TargetFrameworkAttribute targetAttr = null;
            AssemblyConfigurationAttribute configAttr = null;
            AssemblyFileVersionAttribute fileAttr = null;

            foreach (var m in data) {
                var decl = m.Constructor.DeclaringType;
                if (decl == typeof(TargetFrameworkAttribute))
                    targetAttr = new TargetFrameworkAttribute((string) m.ConstructorArguments[0].Value);

                else if (decl == typeof(AssemblyConfigurationAttribute))
                    configAttr = new AssemblyConfigurationAttribute((string) m.ConstructorArguments[0].Value);

                else if (decl == typeof(AssemblyFileVersionAttribute))
                    fileAttr = new AssemblyFileVersionAttribute((string) m.ConstructorArguments[0].Value);
            }

            FrameworkName target = GetFrameworkName(assembly, targetAttr);
            string config = GetConfiguration(configAttr);
            string platform = GetPlatform(assembly);
            Version version = assembly.GetName().Version;

            ICustomAttributeProvider attributes;

            if (assembly.ReflectionOnly)
                attributes = new ReflectOnlyAssemblyAttributeProvider(assembly);
            else
                attributes = assembly;

            Uri myBase = null;
            Uri url = null;
            Uri license = null;

            var baseAttribute = CustomAttributeProvider.GetCustomAttribute<BaseAttribute>(attributes, false);
            if (baseAttribute != null) {
                myBase = baseAttribute.Source;
            }

            var licenseAttribute = CustomAttributeProvider.GetCustomAttribute<LicenseAttribute>(attributes, false);
            if (licenseAttribute != null) {
                license = licenseAttribute.Uri;
            }

            var ua = CustomAttributeProvider.GetCustomAttribute<UrlAttribute>(attributes, false);
            if (ua != null) {
                url = ua.Url;
            }

            return Properties.FromValue(new {
                                            name = cname.Name,
                                            configuration = config,
                                            assemblyName = cname,
                                            platform = platform,
                                            targetFramework = target,
                                            @base = myBase,
                                            license = license,
                                            url = url,
                                            version = version, });
        }