#author("2017-11-05T22:00:24+09:00","default:haikikyou","haikikyou")
#author("2017-11-05T23:22:48+09:00","default:haikikyou","haikikyou")
[[.NET_Framework]]

DLLに埋め込まれたAssemblyVersionを確認するC#のプログラム。エクスプローラのプロパティからは通常確認することができない。

#geshi(c#){{{
using System;
using System.Reflection;
using System.Collections.Generic;
using System.Collections.ObjectModel;

namespace DebugTool
{
    class AssemblyAttributeDumper
    {
        static void Main(string[] args)
        {
            String DLL = args[0];
            Assembly assembly = Assembly.LoadFrom(DLL);
            Console.WriteLine("AssemblyName\n  {0}", assembly.FullName);
            Console.WriteLine("[Attrubutes]");
            // 属性情報を取得する
            foreach (CustomAttributeData attrData in assembly.CustomAttributes)
            try
            {
                Console.WriteLine("  {0}", attrData.AttributeType.Name);
                foreach (CustomAttributeTypedArgument cata in attrData.ConstructorArguments)
                String DLL = args[0];
                Assembly assembly = Assembly.LoadFrom(DLL);
                Console.WriteLine("AssemblyName\n  {0}", assembly.FullName);
                Console.WriteLine("[Attrubutes]");
                // 属性情報を取得する
                foreach (CustomAttributeData attrData in assembly.CustomAttributes)
                {
                    if (cata.Value.GetType() == typeof(ReadOnlyCollection<CustomAttributeTypedArgument>))
                    Console.WriteLine("  {0}", attrData.AttributeType.Name);
                    foreach (CustomAttributeTypedArgument cata in attrData.ConstructorArguments)
                    {
                        Console.WriteLine("    Array of '{0}':", cata.ArgumentType);
                        foreach (CustomAttributeTypedArgument cataElement in
                            (ReadOnlyCollection<CustomAttributeTypedArgument>)cata.Value)
                        if (cata.Value.GetType() == typeof(ReadOnlyCollection<CustomAttributeTypedArgument>))
                        {
                            Console.WriteLine("    Array of '{0}':", cata.ArgumentType);
                            foreach (CustomAttributeTypedArgument cataElement in
                                (ReadOnlyCollection<CustomAttributeTypedArgument>)cata.Value)
                            {
                                Console.WriteLine("    Type: '{0}'  Value: '{1}'",
                                    cataElement.ArgumentType, cataElement.Value);
                            }
                        }
                        else
                        {
                            Console.WriteLine("    Type: '{0}'  Value: '{1}'",
                                cataElement.ArgumentType, cataElement.Value);
                                cata.ArgumentType, cata.Value);
                        }
                    }
                    else
                    {
                        Console.WriteLine("    Type: '{0}'  Value: '{1}'",
                            cata.ArgumentType, cata.Value);
                    }
                }
             }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
                Environment.Exit(1);
            }

        }
    }
}
}}}



トップ   一覧 単語検索 最終更新   ヘルプ   最終更新のRSS
目次
ダブルクリックで閉じるTOP | 閉じる
GO TO TOP