USDMとメソッドを関連づける
USDM表記法を用いて要求仕様を記述し、横にトレーサビリティマトリクスを作るんだけど、このトレーサビリティマトリクスを自動生成したいと考えたとき、C#なら属性があるじゃない!!!とおもったのでさっくり実装。
using System; using System.Text; using System.Reflection; namespace UsdmAttributeTest { [AttributeUsage(AttributeTargets.Method, AllowMultiple = true)] class UsdmAttribute : Attribute { public readonly string name; public UsdmAttribute(string name) { this.name = name; } } class Constants { public const string Sample_01sp01 = "Sample-01.01"; public const string Sample_01sp02 = "Sample-01.02"; } class Sample { [UsdmAttribute(Constants.Sample_01sp01)] [UsdmAttribute(Constants.Sample_01sp02)] public void Method1_1(string s) { } [UsdmAttribute(Constants.Sample_01sp01)] public void Method1_2(string s, string t) { } } class Sample2 { [UsdmAttribute(Constants.Sample_01sp01)] public void Method2_1(string s) { } } class Program { static void Main(string[] args) { Assembly asm = Assembly.GetExecutingAssembly(); foreach (Type t in asm.GetTypes()) { foreach (System.Reflection.MethodInfo mi in t.GetMethods()) { foreach (Object tmp in mi.GetCustomAttributes(false)) { UsdmAttribute ua = tmp as UsdmAttribute; if (ua != null) { Console.WriteLine("{0}.{1}{2}\t{3}", mi.ReflectedType, mi.Name, GetParameterText(mi), ua.name); } } } } } static string GetParameterText(MethodInfo mi) { StringBuilder b = new StringBuilder(); ParameterInfo[] pArray = mi.GetParameters(); if (pArray.Length == 0) { return "()"; } foreach (ParameterInfo p in pArray) { b.Append(", " + p.ParameterType); } return "(" + b.ToString().Remove(0, 2) + ")"; } } }
まあトレーサビリティマトリクスはいろんな成果物と紐づけていいんだけど、一義的にはソースでしょうよと。