回答編集履歴
1
見直しキャンペーン中
test
CHANGED
@@ -1,59 +1,30 @@
|
|
1
1
|
[XmlSerializer.UnknownNode イベント (System.Xml.Serialization) | Microsoft Docs](https://docs.microsoft.com/ja-jp/dotnet/api/system.xml.serialization.xmlserializer.unknownnode)
|
2
|
-
|
3
2
|
これはどうでしょう?
|
4
|
-
|
5
3
|
提示の例ではエラーにできました。
|
6
4
|
|
7
|
-
|
8
|
-
|
9
|
-
```
|
5
|
+
```cs
|
10
|
-
|
11
6
|
public class Team
|
12
|
-
|
13
7
|
{
|
14
|
-
|
15
8
|
public List<Person> list;
|
16
9
|
|
17
|
-
|
18
|
-
|
19
10
|
public static Team Load(string filepath)
|
20
|
-
|
21
11
|
{
|
22
|
-
|
23
12
|
try
|
24
|
-
|
25
13
|
{
|
26
|
-
|
27
14
|
var serializer = new XmlSerializer(typeof(Team));
|
28
|
-
|
29
15
|
serializer.UnknownNode += (s, e) => throw new Exception();
|
30
|
-
|
31
16
|
//serializer.UnknownAttribute += (s, e) => throw new Exception();
|
32
|
-
|
33
17
|
//serializer.UnknownElement += (s, e) => throw new Exception();
|
34
18
|
|
35
|
-
|
36
|
-
|
37
19
|
using(var sr = new StreamReader(filepath, new UTF8Encoding(false)))
|
38
|
-
|
39
20
|
{
|
40
|
-
|
41
21
|
return (Team)serializer.Deserialize(sr);
|
42
|
-
|
43
22
|
}
|
44
|
-
|
45
23
|
}
|
46
|
-
|
47
24
|
catch
|
48
|
-
|
49
25
|
{
|
50
|
-
|
51
26
|
return null;
|
52
|
-
|
53
27
|
}
|
54
|
-
|
55
28
|
}
|
56
|
-
|
57
29
|
}
|
58
|
-
|
59
30
|
```
|