public static FrameworkName GetFrameworkName(Assembly assembly, TargetFrameworkAttribute target)
        {
            if (target == null) {
                Match match = Regex.Match(assembly.ImageRuntimeVersion, @"v(?<Version>\d+(\.\d+)+)");
                Version version = Version.Parse(match.Groups["Version"].Value);
                return new FrameworkName(".NETFramework", version);

            } else {
                return new FrameworkName(target.FrameworkName);

            }
        }
Ejemplo n.º 2
0
 /// <summary>
 /// .NET目标框架的版本属性构造函数
 /// </summary>
 /// <param name="attribute"></param>
 public TargetFramework(TargetFrameworkAttribute attribute) : this(attribute.FrameworkName, attribute.FrameworkDisplayName)
 {
 }
        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, });
        }
 public CodeAttributeDeclaration Convert(TargetFrameworkAttribute attribute)
 {
     return new CodeAttributeDeclaration(new CodeTypeReference(attribute.GetType()), new CodeAttributeArgument(new CodePrimitiveExpression(attribute.FrameworkName)));
 }