[tests] Test loading references from LoadFrom and LoadFile contexts
[mono-project.git] / mono / tests / appdomain2.cs
blobe970a5364e3a96beb243083b02ba7195a6629a20
1 using System;
2 using System.IO;
3 using System.Security.Policy;
4 using System.Threading;
5 using System.Runtime.Serialization;
7 class Container {
9 [Serializable]
10 public struct c2 : ISerializable {
11 public int a;
12 public string s1;
14 private c2 (SerializationInfo info, StreamingContext context) {
15 a = info.GetInt32("a");
16 s1 = info.GetString("s1");
19 public void GetObjectData (SerializationInfo info, StreamingContext context) {
20 info.AddValue ("a", a);
21 if (s1 != null)
22 info.AddValue ("s1", s1);
23 else
24 info.AddValue ("s1", "(null)");
28 [Serializable]
29 public class c1 {
30 public int a = 1;
31 public int b = 2;
32 public string s1 = "TEST1";
33 [NonSerialized] public string s2 = "TEST2";
34 public c2 e1;
37 static int Main ()
39 Console.WriteLine ("Friendly name: " + AppDomain.CurrentDomain.FriendlyName);
41 AppDomainSetup setup = new AppDomainSetup ();
42 setup.ApplicationBase = Directory.GetCurrentDirectory ();
44 AppDomain newDomain = AppDomain.CreateDomain ("NewDomain", null, setup);
46 c1 a1 = new c1 ();
47 a1.e1.a = 3;
48 a1.e1.s1 = "SS";
50 newDomain.SetData ("TEST", a1);
52 c1 r1 = (c1)newDomain.GetData ("TEST");
54 if (r1.a != 1 || r1.b !=2)
55 return 1;
57 if (r1.s1 != "TEST1")
58 return 2;
60 if (r1.s2 != null)
61 return 3;
63 if (r1.e1.a != 3)
64 return 4;
66 if (r1.e1.s1 != "SS")
67 return 5;
69 Console.WriteLine("test-ok");
71 return 0;