[NUI] Change GetDefaultWindow() to static func (#900)
[platform/core/csapi/tizenfx.git] / src / Tizen.NUI / src / public / Xaml / MarkupExtensions / ArrayExtension.cs
1 using System;
2 using System.Collections;
3 using System.Collections.Generic;
4 using System.ComponentModel;
5 using Tizen.NUI.Binding;
6
7 namespace Tizen.NUI.Xaml
8 {
9     /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
10     [EditorBrowsable(EditorBrowsableState.Never)]
11     [ContentProperty("Items")]
12     [AcceptEmptyServiceProvider]
13     public class ArrayExtension : IMarkupExtension<Array>
14     {
15         /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
16         [EditorBrowsable(EditorBrowsableState.Never)]
17         public ArrayExtension()
18         {
19             Items = new List<object>();
20         }
21
22         /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
23         [EditorBrowsable(EditorBrowsableState.Never)]
24         public IList Items { get; }
25
26         /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
27         [EditorBrowsable(EditorBrowsableState.Never)]
28         public Type Type { get; set; }
29
30         /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
31         [EditorBrowsable(EditorBrowsableState.Never)]
32         public Array ProvideValue(IServiceProvider serviceProvider)
33         {
34             if (Type == null)
35                 throw new InvalidOperationException("Type argument mandatory for x:Array extension");
36
37             if (Items == null)
38                 return null;
39
40             var array = Array.CreateInstance(Type, Items.Count);
41             for (var i = 0; i < Items.Count; i++)
42                 ((IList)array)[i] = Items[i];
43
44             return array;
45         }
46
47         object IMarkupExtension.ProvideValue(IServiceProvider serviceProvider)
48         {
49             return (this as IMarkupExtension<Array>).ProvideValue(serviceProvider);
50         }
51     }
52 }