1
XDocument内に出現頻度がSerializableClass
であることを検索したいと思います。 SerializableClass
にXmlRoot属性がある場合、typeof(SerializableClass).Name
とは異なる名前になります。このクラスのXmlRoot属性を検索するにはどうすればよいですか?クラスのXmlRootを取得する
XDocument内に出現頻度がSerializableClass
であることを検索したいと思います。 SerializableClass
にXmlRoot属性がある場合、typeof(SerializableClass).Name
とは異なる名前になります。このクラスのXmlRoot属性を検索するにはどうすればよいですか?クラスのXmlRootを取得する
XMLの特定の要素を表すために使用されるクラスの名前を検索することを意味しますか?
これは、私はそれを行う方法です。
/// <summary>
/// Determines and returns the name of the XmlElement that should represent instances of the given type
/// in an XML stream.
/// </summary>
/// <param name="serializedObjectType"></param>
/// <returns></returns>
[SuppressMessage ("Microsoft.Design", "CA1011:ConsiderPassingBaseTypesAsParameters")]
public static string GetRootNodeElementNameForType(Type serializedObjectType)
{
// Determine if the Type contains an XmlRoot Attribute. If so, the XmlRoot attribute should contain
// the name of the element-name for this type.
// Otherwise, the name of the type should 've been used for serializing objects of this type.
XmlRootAttribute theAttrib = Attribute.GetCustomAttribute (serializedObjectType, typeof (XmlRootAttribute)) as XmlRootAttribute;
if(theAttrib != null)
{
if(String.IsNullOrEmpty (theAttrib.ElementName) == false)
{
return theAttrib.ElementName;
}
else
{
return serializedObjectType.Name;
}
}
else
{
return serializedObjectType.Name;
}
}
== falseの?怒り! :D –
あなたの時計が何であれ間違いありません。 :) –