[runtime] Remove all NACL support. It was unmaintained for a long time. (#4955)
[mono.git] / mono / tests / bug-1147.cs
1 using System;
2 using System.Collections.Generic;
3
4 namespace Program {
5     public class AxControlEventArgs<T> : EventArgs where T : WindowlessControl
6 {
7         public T Control { get; private set; }
8
9         public AxControlEventArgs(T control) {
10             Control = control;
11         }
12     }
13     public class AxControlEventArgs : AxControlEventArgs<WindowlessControl> {
14         public AxControlEventArgs(WindowlessControl c) : base(c) { }
15     }
16
17     public class AlignPadLayoutPanel : AlignPadLayoutPanel<WindowlessControl> {
18 }
19
20     public class AlignPadLayoutPanel<T> : WindowlessControl where T :
21 WindowlessControl {
22         protected override void OnControlAdded(AxControlEventArgs e) {
23             e.Control.Resize += Content_Resize; //OK if removed
24             base.OnControlAdded(e);
25         }
26
27         private void Content_Resize(object sender, EventArgs e) { }
28     }
29
30     public class GroupBox : AlignPadLayoutPanel { } //NOT OK
31     //public class GroupBox : AlignPadLayoutPanel<WindowlessControl> {} //OK
32
33     public class Program {
34         public static readonly AttachedProperty<string> EDITING_TEXT = new
35 AttachedProperty<string>(null);
36
37         static void Main(string[] args) {
38             Console.WriteLine("Program 6");
39
40             var gr = new GroupBox();
41
42             //gr.InsertControl(0, new WindowlessControl()); //OK
43
44             /* need this block(A) this to crash */
45             var item = new WindowlessControl();
46
47             new AlignPadLayoutPanel<WindowlessControl>().InsertControl(0,
48 item); //OK if removed 
49
50             item.SetAttachedProperty(EDITING_TEXT, "label.Text");
51             /*end block(A)*/
52
53             gr.InsertControl(0, new WindowlessControl()); //NOT OK            
54
55             var wc = new WindowlessControl();
56             wc.SetAttachedProperty(EDITING_TEXT, "label.Text");
57             var str = wc.GetAttachedProperty(EDITING_TEXT);
58
59             Console.WriteLine("DONE");
60         }
61     }
62
63     public class WindowlessControl {
64         internal readonly Dictionary<object, object> _AttachedProperties = new
65 Dictionary<object, object>();
66
67         public void SetAttachedProperty<T>(AttachedProperty<T> prop, T val) {
68             Console.WriteLine("SetAttachedProperty 1");
69             _AttachedProperties[prop] = val;
70             Console.WriteLine("SetAttachedProperty 2");
71         }
72
73         public T GetAttachedProperty<T>(AttachedProperty<T> prop) {
74             Console.WriteLine("GET AttachedProperty");
75             return (T)(_AttachedProperties[prop] ?? prop.DefaultValue);
76         }
77
78         public event EventHandler Resize;
79
80         public void InsertControl(int index, WindowlessControl control) {
81             OnControlAdded(new AxControlEventArgs(control));
82         }
83
84         protected virtual void OnControlAdded(AxControlEventArgs e) { }
85     }
86
87     public struct AttachedProperty<T> {
88         public T DefaultValue { get; private set; }
89
90         public AttachedProperty(T defaultValue) : this() {
91             DefaultValue = defaultValue;
92         }
93     }
94 }