[XamlBuild] Add XamlOptimization to use xaml/injection/examl
authorXianbing Teng <xb.teng@samsung.com>
Fri, 11 Mar 2022 03:38:15 +0000 (11:38 +0800)
committerdongsug-song <35130733+dongsug-song@users.noreply.github.com>
Thu, 17 Mar 2022 06:49:34 +0000 (15:49 +0900)
pkg/Tizen.NET.API9/xamlbuild/Tizen.NUI.XamlBuild.targets
src/Tizen.NUI.XamlBuild/src/public/XamlBuild/XamlCTask.cs
src/Tizen.NUI.XamlBuild/src/public/XamlBuild/XamlGTask.cs
src/Tizen.NUI.XamlBuild/src/public/XamlBuild/XamlGenerator.cs

index c9ba6b7..1adb303 100755 (executable)
@@ -26,6 +26,7 @@
                        Language="$(Language)"
                        AssemblyName="$(AssemblyName)"
                        ReferencePath="@(ReferencePath)"
+                       XamlOptimization="$(XamlOptimization)"
             AddXamlCompilationAttribute="True" />
                <ItemGroup>
                        <FileWrites Include="@(_XamlGOutputs)" />
@@ -50,6 +51,7 @@
                        DebugType = "$(DebugType)"
                        NeedDebug = "$(NeedDebug)"
                        UseInjection = "$(NeedInjection)"
+                       XamlOptimization="$(XamlOptimization)"
                        KeepXamlResources = "$(XFKeepXamlResources)" />
                <Touch Files="$(IntermediateOutputPath)XamlC.stamp" AlwaysCreate="True" />
                <ItemGroup>
index b112b62..62cade4 100755 (executable)
@@ -47,6 +47,8 @@ namespace Tizen.NUI.Xaml.Build.Tasks
 
         public bool UseInjection { get; set; }
 
+        public int XamlOptimization { get; set; } = 2;
+
         public IAssemblyResolver DefaultAssemblyResolver { get; set; }
 
         public string Type { get; set; }
@@ -284,10 +286,16 @@ namespace Tizen.NUI.Xaml.Build.Tasks
                             continue;
                         }
 
-                        bool currentRetOfType;
-                        IList<Exception> currentExceptionsOfType;
+                        bool currentRetOfType = false;
+                        IList<Exception> currentExceptionsOfType = null;
 
-                        if (UseInjection)
+                        if(UseInjection) XamlOptimization = 1;
+                        LoggingHelper.LogWarning($"XamlOptimization is {XamlOptimization}.");
+                        if (0 == XamlOptimization)
+                        {//Use Xaml
+                            currentRetOfType = true;
+                        }
+                        else if (1 == XamlOptimization)
                         {
                             currentRetOfType = DoInjection(typeDef, resource, out currentExceptionsOfType);
                         }
index 6813ba4..76c3e1d 100755 (executable)
@@ -36,6 +36,7 @@ namespace Tizen.NUI.Xaml.Build.Tasks
         public string AssemblyName { get; set; }
         public string DependencyPaths { get; set; }
         public string ReferencePath { get; set; }
+        public int XamlOptimization {get; set;} = 2;
         public bool AddXamlCompilationAttribute { get; set; }
         public bool PrintReferenceAssemblies { get; set; }
 
@@ -88,6 +89,7 @@ namespace Tizen.NUI.Xaml.Build.Tasks
 
                 var generator = new XamlGenerator(xamlFile, Language, AssemblyName, outputFile, ReferencePath, Log);
                 generator.AddXamlCompilationAttribute = AddXamlCompilationAttribute;
+                generator.XamlOptimization = XamlOptimization;
                 generator.ReferencePath = ReferencePath;
 
                 try {
index 5dcbbe4..b20c7f0 100755 (executable)
@@ -188,6 +188,7 @@ namespace Tizen.NUI.Xaml.Build.Tasks
         public string RootClrNamespace { get; private set; }
         public string RootType { get; private set; }
         public bool AddXamlCompilationAttribute { get; set; }
+        public int XamlOptimization { get; set; }
         bool GenerateDefaultCtor { get; set; }
         bool HideFromIntellisense { get; set; }
         bool XamlResourceIdOnly { get; set; }
@@ -358,16 +359,26 @@ namespace Tizen.NUI.Xaml.Build.Tasks
             declType.Members.Add(initcomp);
 
             //Create and initialize fields
-            var loadExaml_invoke = new CodeMethodInvokeExpression(
-                new CodeTypeReferenceExpression(new CodeTypeReference($"global::Tizen.NUI.EXaml.EXamlExtensions")),
-                "LoadFromEXamlByRelativePath", new CodeThisReferenceExpression(), 
-                new CodeMethodInvokeExpression()
-                { Method = new CodeMethodReferenceExpression() { MethodName = "GetEXamlPath" } });
-
-            CodeAssignStatement assignEXamlObject = new CodeAssignStatement(
-                    new CodeVariableReferenceExpression("eXamlData"), loadExaml_invoke);
 
-            initcomp.Statements.Add(assignEXamlObject);
+                       if(0 == XamlOptimization)
+                       {
+                initcomp.Statements.Add(new CodeMethodInvokeExpression(
+                    new CodeTypeReferenceExpression(new CodeTypeReference($"global::{typeof(Extensions).FullName}")),
+                    "LoadFromXaml", new CodeThisReferenceExpression(), new CodeTypeOfExpression(declType.Name)));
+                       }
+            else
+                       {
+                var loadExaml_invoke = new CodeMethodInvokeExpression(
+                    new CodeTypeReferenceExpression(new CodeTypeReference($"global::Tizen.NUI.EXaml.EXamlExtensions")),
+                    "LoadFromEXamlByRelativePath", new CodeThisReferenceExpression(),
+                    new CodeMethodInvokeExpression()
+                    { Method = new CodeMethodReferenceExpression() { MethodName = "GetEXamlPath" } });
+
+                CodeAssignStatement assignEXamlObject = new CodeAssignStatement(
+                        new CodeVariableReferenceExpression("eXamlData"), loadExaml_invoke);
+
+                initcomp.Statements.Add(assignEXamlObject);
+                       }
 
             foreach (var namedField in NamedFields) {
                 if(namedField.Type.BaseType.Contains("-"))
@@ -388,27 +399,29 @@ namespace Tizen.NUI.Xaml.Build.Tasks
                 initcomp.Statements.Add(assign);
             }
 
-            declType.Members.Add(new CodeMemberField
-            {
-                Name = "eXamlData",
-                Type = new CodeTypeReference("System.Object"),
-                Attributes = MemberAttributes.Private,
-                CustomAttributes = { GeneratedCodeAttrDecl }
-            });
-
-            var getEXamlPathcomp = new CodeMemberMethod()
-            {
-                Name = "GetEXamlPath",
-                ReturnType = new CodeTypeReference(typeof(string)),
-                CustomAttributes = { GeneratedCodeAttrDecl }
-            };
+                       if(0 != XamlOptimization)
+                       {
+                declType.Members.Add(new CodeMemberField
+                {
+                    Name = "eXamlData",
+                    Type = new CodeTypeReference("System.Object"),
+                    Attributes = MemberAttributes.Private,
+                    CustomAttributes = { GeneratedCodeAttrDecl }
+                });
 
-            getEXamlPathcomp.Statements.Add(new CodeMethodReturnStatement(new CodeDefaultValueExpression(new CodeTypeReference(typeof(string)))));
+                var getEXamlPathcomp = new CodeMemberMethod()
+                {
+                    Name = "GetEXamlPath",
+                    ReturnType = new CodeTypeReference(typeof(string)),
+                    CustomAttributes = { GeneratedCodeAttrDecl }
+                };
 
-            declType.Members.Add(getEXamlPathcomp);
+                getEXamlPathcomp.Statements.Add(new CodeMethodReturnStatement(new CodeDefaultValueExpression(new CodeTypeReference(typeof(string)))));
 
-            GenerateMethodExitXaml(declType);
+                declType.Members.Add(getEXamlPathcomp);
 
+                GenerateMethodExitXaml(declType);
+                       }
         writeAndExit:
             //write the result
             using (var writer = new StreamWriter(outFilePath))