From eaf9427b66257bbaf8d9182544ee0b25504808b6 Mon Sep 17 00:00:00 2001 From: hjhun <36876573+hjhun@users.noreply.github.com> Date: Tue, 8 Aug 2023 13:48:09 +0900 Subject: [PATCH] [NUI.Gadget] Add a new method to load assembly (#5456) The Load() method is added to load the assembly of the NUIGadget. Signed-off-by: Hwankyu Jhun --- src/Tizen.NUI.Gadget/Tizen.NUI/NUIGadgetManager.cs | 60 +++++++++++++++++++--- 1 file changed, 52 insertions(+), 8 deletions(-) diff --git a/src/Tizen.NUI.Gadget/Tizen.NUI/NUIGadgetManager.cs b/src/Tizen.NUI.Gadget/Tizen.NUI/NUIGadgetManager.cs index af302ba..f5986e3 100755 --- a/src/Tizen.NUI.Gadget/Tizen.NUI/NUIGadgetManager.cs +++ b/src/Tizen.NUI.Gadget/Tizen.NUI/NUIGadgetManager.cs @@ -118,28 +118,49 @@ namespace Tizen.NUI } } + private static NUIGadgetInfo Find(string resourceType) + { + if (!_gadgetInfos.TryGetValue(resourceType, out NUIGadgetInfo info)) + { + throw new ArgumentException("Failed to find NUIGadgetInfo. resource type: " + resourceType); + } + + return info; + } + /// - /// Adds a NUIGadget to a NUIGadgetManager. + /// Loads an assembly of the NUIGadget. /// /// The resource type of the NUIGadget package. - /// The class name of the NUIGadget. - /// The NUIGadget object. /// Thrown when failed because of a invalid argument. /// Thrown when failed because of an invalid operation. /// 10 - public static NUIGadget Add(string resourceType, string className) + public static void Load(string resourceType) { - if (string.IsNullOrEmpty(resourceType) || string.IsNullOrEmpty(className)) + if (string.IsNullOrEmpty(resourceType)) { throw new ArgumentException("Invalid argument"); } - if (!_gadgetInfos.TryGetValue(resourceType, out NUIGadgetInfo info)) + NUIGadgetInfo info = Find(resourceType); + try { - throw new ArgumentException("Failed to find NUIGadgetInfo. resource type: " + resourceType); + Load(info); } + catch (FileLoadException e) + { + throw new InvalidOperationException(e.Message); + } + } - try + private static void Load(NUIGadgetInfo info) + { + if (info == null) + { + throw new ArgumentException("Invalid argument"); + } + + lock (info) { if (info.Assembly == null) { @@ -148,6 +169,29 @@ namespace Tizen.NUI Log.Warn("NUIGadgetAssembly.Load(): " + info.ResourcePath + info.ExecutableFile + " --"); } } + } + + /// + /// Adds a NUIGadget to the NUIGadgetManager. + /// + /// The resource type of the NUIGadget package. + /// The class name of the NUIGadget. + /// The NUIGadget object. + /// Thrown when failed because of a invalid argument. + /// Thrown when failed because of an invalid operation. + /// 10 + public static NUIGadget Add(string resourceType, string className) + { + if (string.IsNullOrEmpty(resourceType) || string.IsNullOrEmpty(className)) + { + throw new ArgumentException("Invalid argument"); + } + + NUIGadgetInfo info = Find(resourceType); + try + { + Load(info); + } catch (FileLoadException e) { throw new InvalidOperationException(e.Message); -- 2.7.4