File tree Expand file tree Collapse file tree
Docfx.DataContracts.Common
Docfx.Dotnet/ManagedReference/Models Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -91,9 +91,11 @@ private static bool IsSupported()
9191 switch ( fullName )
9292 {
9393 case "Docfx.Build.Engine.XRefMap" :
94- case "Docfx.DataContracts.ManagedReference.PageViewModel" :
9594 return true ;
9695
96+ case "Docfx.DataContracts.ManagedReference.PageViewModel" :
97+ return true ; // TODO: Need to support ExtensionData
98+
9799 // Intermediate types for tests. it's expected to be removed later (And return true by default).
98100 case "Docfx.Plugins.MarkdownServiceProperties" :
99101 return true ;
Original file line number Diff line number Diff line change 11// Licensed to the .NET Foundation under one or more agreements.
22// The .NET Foundation licenses this file to you under the MIT license.
33
4+ using System . Reflection ;
5+ using System . Text . Json ;
6+ using Docfx . Common ;
47using Newtonsoft . Json . Linq ;
58
69namespace Docfx . DataContracts . Common ;
@@ -18,6 +21,23 @@ public static T Convert<T>(object obj)
1821 {
1922 return jToken . ToObject < T > ( ) ;
2023 }
24+
25+
26+ var type = typeof ( T ) ;
27+
28+ // Try to convert `List<object>` to T (`ObjectToInferredTypesConverter`)
29+ // Currently `ObjectToInferredTypesConverter` convert item to List<object>. So it need to convert type.
30+ if ( obj is List < object > list
31+ && type . GetTypeInfo ( ) . IsGenericType
32+ && type . GetGenericTypeDefinition ( ) == typeof ( List < > ) )
33+ {
34+ // TODO: performance optimization.
35+ var json = JsonUtility . Serialize ( list ) ;
36+ var result = JsonUtility . Deserialize < T > ( new StringReader ( json ) ) ;
37+ return result ;
38+ }
39+
40+
2141 throw new InvalidCastException ( ) ;
2242 }
2343}
Original file line number Diff line number Diff line change @@ -86,17 +86,27 @@ public class ReferenceViewModel
8686 [ YamlIgnore ]
8787 [ Newtonsoft . Json . JsonExtensionData ]
8888 [ System . Text . Json . Serialization . JsonExtensionData ]
89+ [ System . Text . Json . Serialization . JsonInclude ]
8990 [ UniqueIdentityReferenceIgnore ]
9091 [ MarkdownContentIgnore ]
91- public CompositeDictionary AdditionalJson =>
92- CompositeDictionary
92+ public CompositeDictionary AdditionalJson
93+ {
94+ get
95+ {
96+ return CompositeDictionary
9397 . CreateBuilder ( )
9498 . Add ( Constants . ExtensionMemberPrefix . Name , NameInDevLangs , JTokenConverter . Convert < string > )
9599 . Add ( Constants . ExtensionMemberPrefix . NameWithType , NameWithTypeInDevLangs , JTokenConverter . Convert < string > )
96100 . Add ( Constants . ExtensionMemberPrefix . FullName , FullNameInDevLangs , JTokenConverter . Convert < string > )
97101 . Add ( Constants . ExtensionMemberPrefix . Spec , Specs , JTokenConverter . Convert < List < SpecViewModel > > )
98102 . Add ( string . Empty , Additional )
99103 . Create ( ) ;
104+ }
105+ private init
106+ {
107+ // init or getter is required for deserialize data with System.Text.Json.
108+ }
109+ }
100110
101111 public ReferenceViewModel Clone ( )
102112 {
Original file line number Diff line number Diff line change @@ -378,14 +378,24 @@ public string FullNameForVB
378378 [ YamlIgnore ]
379379 [ Newtonsoft . Json . JsonExtensionData ]
380380 [ System . Text . Json . Serialization . JsonExtensionData ]
381+ [ System . Text . Json . Serialization . JsonInclude ]
381382 [ UniqueIdentityReferenceIgnore ]
382383 [ MarkdownContentIgnore ]
383- public IDictionary < string , object > ExtensionData =>
384- CompositeDictionary
384+ public IDictionary < string , object > ExtensionData
385+ {
386+ get
387+ {
388+ return CompositeDictionary
385389 . CreateBuilder ( )
386390 . Add ( Constants . ExtensionMemberPrefix . Name , Names , JTokenConverter . Convert < string > )
387391 . Add ( Constants . ExtensionMemberPrefix . NameWithType , NamesWithType , JTokenConverter . Convert < string > )
388392 . Add ( Constants . ExtensionMemberPrefix . FullName , FullNames , JTokenConverter . Convert < string > )
389393 . Add ( string . Empty , Metadata )
390394 . Create ( ) ;
395+ }
396+ private init
397+ {
398+ // init or getter is required for deserialize data with System.Text.Json.
399+ }
400+ }
391401}
Original file line number Diff line number Diff line change @@ -89,11 +89,21 @@ public string ContentForVB
8989 [ YamlIgnore ]
9090 [ Newtonsoft . Json . JsonExtensionData ]
9191 [ System . Text . Json . Serialization . JsonExtensionData ]
92+ [ System . Text . Json . Serialization . JsonInclude ]
9293 [ UniqueIdentityReferenceIgnore ]
9394 [ MarkdownContentIgnore ]
94- public IDictionary < string , object > ExtensionData =>
95- CompositeDictionary
95+ public IDictionary < string , object > ExtensionData
96+ {
97+ get
98+ {
99+ return CompositeDictionary
96100 . CreateBuilder ( )
97101 . Add ( Constants . ExtensionMemberPrefix . Content , Contents , JTokenConverter . Convert < string > )
98102 . Create ( ) ;
103+ }
104+ private init
105+ {
106+ // init or getter is required for deserialize data with System.Text.Json.
107+ }
108+ }
99109}
You can’t perform that action at this time.
0 commit comments