using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
namespace WebQuestion
{
interface IListInterface
{
ArrayList Items { get; set; }
}
class ListClass : MarshalByRefObject, IListInterface
{
private ArrayList items = new ArrayList{0,1,2,3,4,5};
public ArrayList Items
{
get
{
return items;
}
set
{
items = value;
}
}
}
class Program
{
static void Main(string[] args)
{
AppDomain ad = AppDomain.CreateDomain("OtherAppDomain");
IListInterface byRef = (IListInterface)ad.CreateInstanceAndUnwrap(Assembly.GetExecutingAssembly().FullName, "WebQuestion.ListClass");
foreach (object obj in byRef.Items)
{
Console.WriteLine(obj);
}
Console.WriteLine("Item Count before Add(): " + byRef.Items.Count); //Items.Count == 6
byRef.Items.Add("Item at index 6");
Console.WriteLine("Item Count after Add(): " + byRef.Items.Count); //Items.Count == 6, still
try
{
Console.WriteLine("Getting item at Items[6]...");
Console.WriteLine(byRef.Items[6]); //throw exception
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
}
}
}
|