この質問は正しく質問していないかもしれませんが、矛盾する名前とクラスが難しくなっている可能性があります。私はコードをリファクタリングしながらコードメトリクスを追跡する小さなツールを作りたいと思っています。結果は、逆シリアル化しようとしているファイルに出力されます。ここに指標のスニペットがあります。私は私が私のType
に入れLinqPadに依存できることを知っていたType
に着いたときXmlを別のタイプにデシリアライズ
<CodeMetricsReport Version="11">
<Targets>
<Target Name="C:\Git\coab\GoldBox.Logging\bin\Debug\GoldBox.Logging.dll">
<Modules>
<Module Name="GoldBox.Logging.dll" AssemblyVersion="1.0.5978.28510">
<Metrics>
<Metric Name="MaintainabilityIndex" Value="88" />
<Metric Name="CyclomaticComplexity" Value="30" />
<Metric Name="ClassCoupling" Value="13" />
<Metric Name="DepthOfInheritance" Value="1" />
<Metric Name="LinesOfCode" Value="51" />
</Metrics>
<Namespaces>
<Namespace Name="GoldBox.Logging">
<Metrics>
<Metric Name="MaintainabilityIndex" Value="88" />
<Metric Name="CyclomaticComplexity" Value="30" />
<Metric Name="ClassCoupling" Value="13" />
<Metric Name="DepthOfInheritance" Value="1" />
<Metric Name="LinesOfCode" Value="51" />
</Metrics>
<Types>
<Type Name="Config">
<Metrics>
<Metric Name="MaintainabilityIndex" Value="89" />
<Metric Name="CyclomaticComplexity" Value="9" />
<Metric Name="ClassCoupling" Value="5" />
<Metric Name="DepthOfInheritance" Value="1" />
<Metric Name="LinesOfCode" Value="15" />
</Metrics>
<Members>
<Member Name="BasePath.get() : string" File="C:\Git\coab\GoldBox.Logging\Config.cs" Line="8">
<Metrics>
<Metric Name="MaintainabilityIndex" Value="98" />
<Metric Name="CyclomaticComplexity" Value="1" />
<Metric Name="ClassCoupling" Value="0" />
<Metric Name="LinesOfCode" Value="1" />
</Metrics>
</Member>
<Member Name="BasePath.set(string) : void" File="C:\Git\coab\GoldBox.Logging\Config.cs" Line="8">
<Metrics>
<Metric Name="MaintainabilityIndex" Value="95" />
<Metric Name="CyclomaticComplexity" Value="1" />
<Metric Name="ClassCoupling" Value="0" />
<Metric Name="LinesOfCode" Value="1" />
</Metrics>
</Member>
<Member Name="LogPath.get() : string" File="C:\Git\coab\GoldBox.Logging\Config.cs" Line="9">
<Metrics>
<Metric Name="MaintainabilityIndex" Value="98" />
<Metric Name="CyclomaticComplexity" Value="1" />
<Metric Name="ClassCoupling" Value="0" />
<Metric Name="LinesOfCode" Value="1" />
</Metrics>
</Member>
<Member Name="LogPath.set(string) : void" File="C:\Git\coab\GoldBox.Logging\Config.cs" Line="9">
<Metrics>
<Metric Name="MaintainabilityIndex" Value="95" />
<Metric Name="CyclomaticComplexity" Value="1" />
<Metric Name="ClassCoupling" Value="0" />
<Metric Name="LinesOfCode" Value="1" />
</Metrics>
</Member>
<Member Name="SavePath.get() : string" File="C:\Git\coab\GoldBox.Logging\Config.cs" Line="10">
<Metrics>
<Metric Name="MaintainabilityIndex" Value="98" />
<Metric Name="CyclomaticComplexity" Value="1" />
<Metric Name="ClassCoupling" Value="0" />
<Metric Name="LinesOfCode" Value="1" />
</Metrics>
</Member>
<Member Name="SavePath.set(string) : void" File="C:\Git\coab\GoldBox.Logging\Config.cs" Line="10">
<Metrics>
<Metric Name="MaintainabilityIndex" Value="95" />
<Metric Name="CyclomaticComplexity" Value="1" />
<Metric Name="ClassCoupling" Value="0" />
<Metric Name="LinesOfCode" Value="1" />
</Metrics>
</Member>
<Member Name="Setup() : void" File="C:\Git\coab\GoldBox.Logging\Config.cs" Line="13">
<Metrics>
<Metric Name="MaintainabilityIndex" Value="67" />
<Metric Name="CyclomaticComplexity" Value="1" />
<Metric Name="ClassCoupling" Value="3" />
<Metric Name="LinesOfCode" Value="7" />
</Metrics>
</Member>
<Member Name="CreateIfNeeded(string) : void" File="C:\Git\coab\GoldBox.Logging\Config.cs" Line="25">
<Metrics>
<Metric Name="MaintainabilityIndex" Value="84" />
<Metric Name="CyclomaticComplexity" Value="2" />
<Metric Name="ClassCoupling" Value="1" />
<Metric Name="LinesOfCode" Value="2" />
</Metrics>
</Member>
</Members>
</Type>
</Types>
</Namespace>
</Namespaces>
</Module>
</Modules>
</Target>
</Targets>
</CodeMetricsReport>
私は
void Main()
{
var xml = XElement.Load(@"C:\Git\coab\MetricResults\[email protected] 2016-05-15 05_27_14.mrx");
XmlSerializer serializer = new XmlSerializer(typeof(Target));
xml.Dump();
xml.Descendants("Target")
.Select(e=>(Target)serializer.Deserialize(e.CreateReader()))
.Dump();
}
public class Target
{
[XmlAttribute]
public string Name {get;set;}
public List<Module> Modules {get;set;}
}
public class Module
{
[XmlAttribute]
public string Name {get;set;}
[XmlAttribute]
public string AssemblyVersion {get;set;}
public List<Metric> Metrics {get;set;}
public List<Namespace> Namespaces {get;set;}
}
public class Namespace
{
[XmlAttribute]
public string Name {get;set;}
public List<Metric> Metrics {get;set;}
public List<Type> Types {get;set;}
}
public class Type
{
[XmlAttribute]
public string Name {get;set;}
public List<Metric> Metrics {get;set;}
}
public class Metric
{
[XmlAttribute]
public string Name {get;set;}
[XmlAttribute]
public string Value {get;set;}
}
でダウン私の方法を働いていた(申し訳ありませんが、それは私がそれを作ることができるほど小さいです)独自の名前空間とコードが機能します。しかし、私が書いたコードでは、それがType
であることを望んでいませんが、私はむしろMetricType
になります。をNamespace
のMetricType
に変更すると、結果はゼロに戻ります。だから問題はどうすればNamespace
を代わりにこのように見えるのですか?
public class Namespace
{
[XmlAttribute]
public string Name {get;set;}
public List<Metric> Metrics {get;set;}
public List<MetricType> Types {get;set;}
}
public class MetricType
{
[XmlAttribute]
public string Name {get;set;}
public List<Metric> Metrics {get;set;}
}
Xml___Attributeの束を見て、それが 'XmlArray'または' XmlArrayItem'を見ませんでした。どうもありがとうございました。 LINQとSelectを使用してこれを回避しようとしましたが、閉鎖の目的でこれを試すことができます –