55using System ;
66using System . Collections . Generic ;
77using System . Reflection ;
8+ using System . Text . Json ;
9+ using ShadowPluginLoader . WinUI . Helpers ;
810
911namespace ShadowPluginLoader . WinUI ;
1012
@@ -50,11 +52,6 @@ public abstract record AbstractPluginMetaData : IPluginMetaData
5052 [ Meta ( Required = false , AsString = true ) ]
5153 public VersionRange SdkVersion { get ; init ; } = null ! ;
5254
53- /// <summary>
54- /// <inheritdoc cref="IPluginMetaData.MainPlugin"/>
55- /// </summary>
56- [ Meta ( Exclude = true ) ]
57- public PluginEntryPointType MainPlugin { get ; private set ; } = null ! ;
5855
5956 /// <summary>
6057 /// <inheritdoc cref="IPluginMetaData.Priority"/>
@@ -68,62 +65,33 @@ public abstract record AbstractPluginMetaData : IPluginMetaData
6865 [ Meta ( Exclude = true , AsString = true ) ]
6966 public PluginDependency [ ] Dependencies { get ; init ; } = [ ] ;
7067
71- /// <summary>
72- /// <inheritdoc cref="IPluginMetaData.EntryPoints"/>
73- /// </summary>
74- [ Meta ( Exclude = true ) ]
75- public PluginEntryPoint [ ] EntryPoints { get ; init ; } = [ ] ;
7668
7769 /// <summary>
7870 ///
7971 /// </summary>
8072 private static readonly Type TargetTypeList = typeof ( PluginEntryPointType [ ] ) ;
8173
8274 /// <summary>
83- /// LoadEntryPoint
75+ /// <inheritdoc cref="IPluginMetaData.Raw"/>
8476 /// </summary>
77+ [ Meta ( Exclude = true ) ]
78+ public JsonElement Raw { get ; private set ; }
79+
80+ /// <summary>
81+ ///
82+ /// </summary>
83+ /// <param name="content"></param>
84+ /// <typeparam name="TMeta"></typeparam>
8585 /// <returns></returns>
86- public void LoadEntryPoint ( PropertyPath [ ] propertyPaths , Assembly assembly )
86+ public static TMeta ? ToMeta < TMeta > ( string content ) where TMeta : AbstractPluginMetaData
8787 {
88- foreach ( var path in propertyPaths )
89- {
90- object ? current = this ;
91- for ( var i = 0 ; i < path . Path . Count - 1 ; i ++ )
92- {
93- var prop = path . Path [ i ] ;
94- var next = prop . GetValue ( current ) ;
95- if ( next == null )
96- {
97- next = Activator . CreateInstance ( prop . PropertyType ) ;
98- prop . SetValue ( current , next ) ;
99- }
100- current = next ;
101- }
102-
103- var targetProp = path . TargetProperty ;
104- var isList = targetProp . PropertyType == TargetTypeList ;
105-
106- if ( isList )
107- {
108- List < PluginEntryPointType > entryPoints = [ ] ;
109- foreach ( var entryPoint in EntryPoints )
110- {
111- if ( entryPoint . Name == targetProp . Name && assembly . GetType ( entryPoint . Type ) is { } type )
112- entryPoints . Add ( new PluginEntryPointType ( type ) ) ;
113- }
114- targetProp . SetValue ( current , entryPoints . ToArray ( ) ) ;
115- }
116- else
117- {
118- PluginEntryPointType ? entryPoint = null ;
119- foreach ( var ep in EntryPoints )
120- {
121- if ( ep . Name != targetProp . Name || assembly . GetType ( ep . Type ) is not { } type ) continue ;
122- entryPoint = new PluginEntryPointType ( type ) ;
123- break ;
124- }
125- targetProp . SetValue ( current , entryPoint ) ;
126- }
127- }
88+ using var doc = JsonDocument . Parse ( content ) ;
89+ var root = doc . RootElement ;
90+
91+ var meta = root . Deserialize < TMeta > ( MetaDataHelper . Options ) ;
92+ if ( meta != null ) meta . Raw = root . Clone ( ) ;
93+ return meta ;
12894 }
95+
96+
12997}
0 commit comments