Click here to Skip to main content
15,887,683 members
Articles / Programming Languages / C#

LiveCode.NET

Rate me:
Please Sign up or sign in to vote.
4.86/5 (55 votes)
6 May 2002Public Domain3 min read 231.6K   2.5K   170  
Compile C# code on-the-fly. Usage in a plug-in / plug-out component model.
using System;
using System.Reflection;

namespace LiveCode.LiveInterface
{

	/// <summary>
	/// The real plug-in interface we use to communicate across app-domains
	/// </summary>
public interface ILiveInterface
	{
		/// <summary> just one sample method to be called across app-domain</summary>
		/// <param name="inpString"> any string the method will modify </param>
		/// <returns> returns the modified string passed in as 'inpString' </returns>
	string ModifyString( string inpString );
	}



	/// <summary>
	/// Factory class to create objects exposing ILiveInterface
	/// </summary>
public class LiveInterfaceFactory : MarshalByRefObject
	{
	private const BindingFlags bfi = BindingFlags.Instance | BindingFlags.Public | BindingFlags.CreateInstance;

	public LiveInterfaceFactory() {}

		/// <summary> Factory method to create an instance of the type whose name is specified,
		/// using the named assembly file and the constructor that best matches the specified parameters. </summary>
		/// <param name="assemblyFile"> The name of a file that contains an assembly where the type named typeName is sought. </param>
		/// <param name="typeName"> The name of the preferred type. </param>
		/// <param name="constructArgs"> An array of arguments that match in number, order, and type the parameters of the constructor to invoke, or null for default constructor. </param>
		/// <returns> The return value is the created object represented as ILiveInterface. </returns>
	public ILiveInterface Create( string assemblyFile, string typeName, object[] constructArgs )
		{
		return (ILiveInterface) Activator.CreateInstanceFrom(
			assemblyFile, typeName, false, bfi, null, constructArgs,
			null, null, null ).Unwrap();
		}

	}
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under A Public Domain dedication


Written By
Web Developer
Switzerland Switzerland
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions