[System] Tweak socket test
[mono-project.git] / mono / tests / bug-1147.cs
blob9190c9b888a584ed3fef8ccb78b3fcd8dd1caf92
1 using System;
2 using System.Collections.Generic;
4 namespace Program {
5 public class AxControlEventArgs<T> : EventArgs where T : WindowlessControl
7 public T Control { get; private set; }
9 public AxControlEventArgs(T control) {
10 Control = control;
13 public class AxControlEventArgs : AxControlEventArgs<WindowlessControl> {
14 public AxControlEventArgs(WindowlessControl c) : base(c) { }
17 public class AlignPadLayoutPanel : AlignPadLayoutPanel<WindowlessControl> {
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);
27 private void Content_Resize(object sender, EventArgs e) { }
30 public class GroupBox : AlignPadLayoutPanel { } //NOT OK
31 //public class GroupBox : AlignPadLayoutPanel<WindowlessControl> {} //OK
33 public class Program {
34 public static readonly AttachedProperty<string> EDITING_TEXT = new
35 AttachedProperty<string>(null);
37 static void Main(string[] args) {
38 Console.WriteLine("Program 6");
40 var gr = new GroupBox();
42 //gr.InsertControl(0, new WindowlessControl()); //OK
44 /* need this block(A) this to crash */
45 var item = new WindowlessControl();
47 new AlignPadLayoutPanel<WindowlessControl>().InsertControl(0,
48 item); //OK if removed
50 item.SetAttachedProperty(EDITING_TEXT, "label.Text");
51 /*end block(A)*/
53 gr.InsertControl(0, new WindowlessControl()); //NOT OK
55 var wc = new WindowlessControl();
56 wc.SetAttachedProperty(EDITING_TEXT, "label.Text");
57 var str = wc.GetAttachedProperty(EDITING_TEXT);
59 Console.WriteLine("DONE");
63 public class WindowlessControl {
64 internal readonly Dictionary<object, object> _AttachedProperties = new
65 Dictionary<object, object>();
67 public void SetAttachedProperty<T>(AttachedProperty<T> prop, T val) {
68 Console.WriteLine("SetAttachedProperty 1");
69 _AttachedProperties[prop] = val;
70 Console.WriteLine("SetAttachedProperty 2");
73 public T GetAttachedProperty<T>(AttachedProperty<T> prop) {
74 Console.WriteLine("GET AttachedProperty");
75 return (T)(_AttachedProperties[prop] ?? prop.DefaultValue);
78 public event EventHandler Resize;
80 public void InsertControl(int index, WindowlessControl control) {
81 OnControlAdded(new AxControlEventArgs(control));
84 protected virtual void OnControlAdded(AxControlEventArgs e) { }
87 public struct AttachedProperty<T> {
88 public T DefaultValue { get; private set; }
90 public AttachedProperty(T defaultValue) : this() {
91 DefaultValue = defaultValue;