<Compile Include="src\CompilerServices\MemberReference.cs" />
<Compile Include="src\CompilerServices\Bindings.cs" />
<Compile Include="src\StyleReader.cs" />
- <Compile Include="src\IMLStream.cs" />
<Compile Include="src\GraphicObjects\DirectoryView.cs" />
- <Compile Include="src\IMLInstantiatorBuilder.cs" />
<Compile Include="src\Instantiator.cs" />
+ <Compile Include="src\IMLReader.cs" />
+ <Compile Include="src\ItemTemplate.cs" />
</ItemGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Xml" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Drawing" />
- <Reference Include="cairo-sharp"/>
- <Reference Include="gdk-sharp"/>
- <Reference Include="gio-sharp"/>
- <Reference Include="glib-sharp"/>
+ <Reference Include="cairo-sharp">
+ <Package>gtk-sharp-3.0</Package>
+ </Reference>
+ <Reference Include="gdk-sharp">
+ <Package>gtk-sharp-2.0</Package>
+ </Reference>
+ <Reference Include="gio-sharp">
+ <Package>gio-sharp-3.0</Package>
+ </Reference>
+ <Reference Include="glib-sharp">
+ <Package>glib-sharp-3.0</Package>
+ </Reference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
}
Border {
Foreground = White;
+}
+ProgressBar {
+ Foreground = vgradient|0:BlueCrayola|0.5:SkyBlue|1:BlueCrayola;
}
\ No newline at end of file
this.KeyDown += KeyboardKeyDown1;
- testFiles = new string [] { @"Interfaces/Divers/welcome.crow" };
- testFiles = testFiles.Concat (Directory.GetFiles (@"Interfaces/basicTests", "*.crow")).ToArray ();
+ //testFiles = new string [] { @"Interfaces/Divers/welcome.crow" };
+ testFiles = Directory.GetFiles (@"Interfaces/basicTests", "*.crow");
testFiles = testFiles.Concat (Directory.GetFiles (@"Interfaces/Container", "*.crow")).ToArray ();
testFiles = testFiles.Concat (Directory.GetFiles (@"Interfaces/GraphicObject", "*.crow")).ToArray ();
testFiles = testFiles.Concat (Directory.GetFiles (@"Interfaces/Group", "*.crow")).ToArray ();
}
void Tv_SelectedItemChanged (object sender, SelectionChangeEventArgs e)
{
- FileInfo fi = e.NewValue as FileInfo;
- if (fi == null)
- return;
- if (fi.Extension == ".crow" || fi.Extension == ".goml") {
- IMLStream imls = new IMLStream (fi.FullName);
- lock (CrowInterface.UpdateMutex) {
- (CrowInterface.FindByName ("crowContainer") as Container).SetChild
- (imls.Instance);
- CurSources = imls.Source;
- }
- }
+// FileInfo fi = e.NewValue as FileInfo;
+// if (fi == null)
+// return;
+// if (fi.Extension == ".crow" || fi.Extension == ".goml") {
+// IMLStream imls = new IMLStream (fi.FullName);
+// lock (CrowInterface.UpdateMutex) {
+// (CrowInterface.FindByName ("crowContainer") as Container).SetChild
+// (imls.Instance);
+// CurSources = imls.Source;
+// }
+// }
}
void onButClick(object send, MouseButtonEventArgs e)
{
<?xml version="1.0"?>
<VerticalStack Fit="true" VerticalAlignment="Top" Background="0.7,0.7,0.7,0.5"
+ MouseEnter="{Background=Blue}"
+ MouseLeave="{Background=Onyx}"
Margin="10" CornerRadius="10">
- <Label Font="20" Text="Press <F3> to cycle into the examples"/>
+ <Label Font="20" Text="Press <F3> to cycle into the examples"
+ MouseEnter="{Background=Red}"
+ MouseLeave="{Background=Transparent}"
+ />
<Label Font="20" Text="Those are basic tests used to validate changes"/>
</VerticalStack>
\ No newline at end of file
<?xml version="1.0"?>
-<CheckBox/>
\ No newline at end of file
+<Expandable >
+
+</Expandable>
<?xml version="1.0"?>
<HorizontalStack Fit="true">
<VerticalStack Fit="true" Name="vsFps" Spacing="10" >
- <ProgressBar CornerRadius="5" Background="DimGray" Margin="1" Maximum="1000" Value="{fps}" Width="200" Height="15"/>
- <HorizontalStack Fit="true">
+<!-- <ProgressBar CornerRadius="5" Background="DimGray" Margin="1" Maximum="1000" Value="{fps}" Width="200" Height="15"/>
+ <HorizontalStack Fit="true">-->
<Label Text="Memory:" Width="50" TextAlignment="Right"/>
<Label Text="{memory}" Font="droid,12" TextAlignment="Center"
Background="vgradient|0:BlueCrayola|1:Black"/>
if (ItemTemplates == null)
ItemTemplates = new Dictionary<string, ItemTemplate> ();
if (!ItemTemplates.ContainsKey ("default"))
- ItemTemplates["default"] = new ItemTemplate (ItemTemplate);
+ ItemTemplates ["default"] = Interface.GetItemTemplate (ItemTemplate);
for (int i = 1; i <= (data.Count / itemPerPage) + 1; i++) {
if (cancelLoading)
return;
GraphicObject g = null;
- ItemTemplate itemStream = null;
+ ItemTemplate iTemp = null;
Type dataType = data [i].GetType ();
if (ItemTemplates.ContainsKey (dataType.FullName))
- itemStream = ItemTemplates [dataType.FullName];
+ iTemp = ItemTemplates [dataType.FullName];
else
- itemStream = ItemTemplates ["default"];
+ iTemp = ItemTemplates ["default"];
lock (Interface.CurrentInterface.LayoutMutex) {
- g = itemStream.Instance;
+ g = iTemp.CreateInstance();
page.AddChild (g);
g.DataSource = data [i];
}
}else
g.MouseClick += itemClick;
- if (itemStream.Expand != null && g is Expandable) {
- (g as Expandable).Expand += itemStream.Expand;
+ if (iTemp.Expand != null && g is Expandable) {
+ (g as Expandable).Expand += iTemp.Expand;
}
//g.LogicalParent = this;
}
namespace Crow
{
- [Serializable]
+
public class ProgressBar : NumericControl
{
#region CTOR
}
#region GraphicObject overrides
- [XmlAttributeAttribute()][DefaultValue("vgradient|0:BlueCrayola|0,5:SkyBlue|1:BlueCrayola")]
- public override Fill Foreground {
- get { return base.Foreground; }
- set { base.Foreground = value; }
- }
-
protected override void onDraw (Context gr)
{
base.onDraw (gr);
string _template;
string _itemTemplate;
- public Dictionary<string, ItemTemplate> ItemTemplates;
+ public Dictionary<string, ItemTemplate> ItemTemplates = new Dictionary<string, Crow.ItemTemplate>();//TODO: dont instantiate if not used
+ //but then i should test if null in msil gen
[XmlAttributeAttribute][DefaultValue(null)]
public string Template {
[XmlAttributeAttribute][DefaultValue("#Crow.Templates.ItemTemplate.goml")]
public string ItemTemplate {
get { return _itemTemplate; }
- set {
+ set {
if (value == _itemTemplate)
return;
xr.Read (); //read first child
xr.Read (); //skip root node
- while (!xr.EOF) {
+ while (!xr.EOF) {
if (!xr.IsStartElement ()) {
xr.Read ();
continue;
if (ItemTemplates == null)
ItemTemplates = new Dictionary<string, ItemTemplate> ();
- //TODO:check encoding
- ItemTemplates[dataType] = new ItemTemplate (Encoding.UTF8.GetBytes(itemTmp));
+
+ using (IMLReader iTmp = new IMLReader (null, itemTmp)) {
+ ItemTemplates [dataType] =
+ new ItemTemplate (iTmp.RootType, iTmp.GetLoader ());
+ }
if (!string.IsNullOrEmpty (datas))
ItemTemplates [dataType].CreateExpandDelegate(this, dataType, datas);
//if no template found, load default one
if (this.child == null)
loadTemplate ();
-
+
//normal xml read
using (XmlReader xr = new XmlTextReader (tmp, XmlNodeType.Element, null)) {
xr.Read ();
using System.Reflection;
using System.Reflection.Emit;
using System.Linq;
+using System.Collections.Generic;
namespace Crow
{
public class IMLReader : XmlTextReader
{
+ Interface.LoaderInvoker loader = null;
+
public string ImlPath;
public Stream ImlStream;
public Type RootType = null;
: base(stream)
{
ImlStream = stream;
- readRootType();
- InitEmitter();
- BuildInstanciator(RootType);
- Read();//close tag
+ createInstantiator ();
}
+ /// <summary>
+ /// Used to parse xmlFrament with same code generator linked
+ /// If ilGen=null, a new Code Generator will be created.
+ /// </summary>
public IMLReader (ILGenerator ilGen, string xmlFragment)
: base(xmlFragment, XmlNodeType.Element,null){
il = ilGen;
+
+ if (il != null)
+ return;
+
+ createInstantiator();
}
#endregion
+ void createInstantiator(){
+ readRootType();
+ InitEmitter();
+ emitLoader(RootType);
+ Read();//close tag
+ }
/// <summary>
/// Finalize instatiator MSIL and return LoaderInvoker delegate
/// </summary>
- public Instantiator GetInstanciator(){
- il.Emit(OpCodes.Ret);
+ public Interface.LoaderInvoker GetLoader(){
+ if (loader != null)
+ return loader;
- return new Instantiator (RootType,
- (Interface.LoaderInvoker)dm.CreateDelegate (typeof(Interface.LoaderInvoker)));
+ il.Emit(OpCodes.Ret);
+ loader = (Interface.LoaderInvoker)dm.CreateDelegate (typeof(Interface.LoaderInvoker));
+ return loader;
}
-
/// <summary>
/// Inits il generator, RootType must have been read first
/// </summary>
il.Emit (OpCodes.Ldarg_0);
il.Emit (OpCodes.Stloc_0);
}
- void BuildInstanciator(Type crowType){
+ void emitLoader(Type crowType){
string tmpXml = ReadOuterXml ();
il.Emit (OpCodes.Ldloc_0);//save current go onto the stack if child has to be added
//if its a template, first read template elements
using (IMLReader reader = new IMLReader (il, tmpXml)) {
- string template = reader.GetAttribute ("Template");
+ string templatePath = reader.GetAttribute ("Template");
+ //string itemTemplatePath = reader.GetAttribute ("ItemTemplate");
bool inlineTemplate = false;
- if (string.IsNullOrEmpty (template)) {
+ if (string.IsNullOrEmpty (templatePath)) {
reader.Read ();
while (reader.Read ()) {
readChildren (reader, crowType);
continue;
- }else if (reader.Name == "ItemTemplate") {
+ } else if (reader.Name == "ItemTemplate") {
reader.Skip ();
- // string dataType = "default", datas = "", itemTmp;
- // while (reader.MoveToNextAttribute ()) {
- // if (reader.Name == "DataType")
- // dataType = reader.Value;
- // else if (reader.Name == "Data")
- // datas = reader.Value;
- // }
- //
- // reader.Read();
- // itemTmp = .ReadInnerXml ();
- //
- // if (ItemTemplates == null)
- // ItemTemplates = new Dictionary<string, ItemTemplate> ();
- // //TODO:check encoding
- // ItemTemplates[dataType] = new ItemTemplate (Encoding.UTF8.GetBytes(itemTmp));
- // if (!string.IsNullOrEmpty (datas))
- // ItemTemplates [dataType].CreateExpandDelegate(this, dataType, datas);
+ continue;
+
+ string dataType = "default", datas = "", path = "";
+ while (reader.MoveToNextAttribute ()) {
+ if (reader.Name == "DataType")
+ dataType = reader.Value;
+ else if (reader.Name == "Data")
+ datas = reader.Value;
+ else if (reader.Name == "Path")
+ path = reader.Value;
+ }
+
+ using (IMLReader iTmp = new IMLReader (null, reader.ReadInnerXml ())) {
+ string uid = Guid.NewGuid ().ToString ();
+ Interface.Instantiators [uid] =
+ new ItemTemplate (iTmp.RootType, iTmp.GetLoader ());
+ reader.il.Emit (OpCodes.Ldstr, dataType);
+ reader.il.Emit (OpCodes.Ldstr, uid);
+ reader.il.Emit (OpCodes.Callvirt,
+ typeof(Interface).GetMethod ("GetItemTemplate"));
+ reader.il.Emit (OpCodes.Callvirt,
+ typeof(Dictionary<string, ItemTemplate>).GetMethod ("Add",
+ new Type[] { typeof(string), typeof(ItemTemplate) }));
+ }
+// if (!string.IsNullOrEmpty (datas))
+// ItemTemplates [dataType].CreateExpandDelegate(this, dataType, datas);
continue;
}
- }
- if (!inlineTemplate) {
- DefaultTemplate dt = (DefaultTemplate)crowType.GetCustomAttributes (typeof(DefaultTemplate), true).FirstOrDefault();
- template = dt.Path;
+
+ if (!inlineTemplate) {
+ DefaultTemplate dt = (DefaultTemplate)crowType.GetCustomAttributes (typeof(DefaultTemplate), true).FirstOrDefault ();
+ templatePath = dt.Path;
+ }
}
}
if (!inlineTemplate) {
reader.il.Emit (OpCodes.Ldloc_0);//Load this templateControl ref
- reader.il.Emit (OpCodes.Ldstr, template); //Load template path string
+ reader.il.Emit (OpCodes.Ldstr, templatePath); //Load template path string
reader.il.Emit (OpCodes.Callvirt,//call Interface.Load(path)
typeof(Interface).GetMethod ("Load", BindingFlags.Static | BindingFlags.Public));
}
reader.il.Emit(OpCodes.Newobj, t.GetConstructors () [0]);
reader.il.Emit (OpCodes.Stloc_0);//child is now loc_0
- reader.BuildInstanciator(t);
+ reader.emitLoader(t);
reader.il.Emit (OpCodes.Ldloc_0);//load child on stack for parenting
reader.il.Emit (OpCodes.Callvirt, miAddChild);
+++ /dev/null
-//
-// IMLStream.cs
-//
-// Author:
-// Jean-Philippe Bruyère <jp.bruyere@hotmail.com>
-//
-// Copyright (c) 2016 jp
-//
-// This program is free software: you can redistribute it and/or modify
-// it under the terms of the GNU General Public License as published by
-// the Free Software Foundation, either version 3 of the License, or
-// (at your option) any later version.
-//
-// This program is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License
-// along with this program. If not, see <http://www.gnu.org/licenses/>.
-using System;
-using System.IO;
-using System.Reflection;
-using System.Reflection.Emit;
-using System.Threading;
-using System.Xml.Serialization;
-using System.Xml;
-using System.Collections.Generic;
-using System.Diagnostics;
-
-namespace Crow
-{
- public class IMLStream : MemoryStream {
- public string Path;
- public Type RootType;
- public IMLStream(string path) : base (){
- Path = path;
- using (Stream stream = Interface.GetStreamFromPath (path))
- stream.CopyTo (this);
- //RootType = Interface.GetTopContainerOfXMLStream (this);
- }
- public IMLStream(Byte[] b) : base (b){
- //RootType = Interface.GetTopContainerOfXMLStream (this);
- }
- /// <summary>
- /// Create a graphicObject instance from the this XML stream.
- /// </summary>
- public GraphicObject Instance {
- get {
- System.Globalization.CultureInfo savedCulture = Thread.CurrentThread.CurrentCulture;
- Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo.InvariantCulture;
-
- Seek (0, SeekOrigin.Begin);
- GraphicObject tmp = null;//Interface.Load (this, this.RootType);
-
- Thread.CurrentThread.CurrentCulture = savedCulture;
- return tmp;
- }
- }
- /// <summary>
- /// Gets the xml source code as a string
- /// </summary>
- public string Source {
- get {
- Seek (0, SeekOrigin.Begin);
- using (StreamReader sr = new StreamReader(this))
- return sr.ReadToEnd();
- }
- }
- }
- public class ItemTemplate : IMLStream {
- public EventHandler Expand;
-
- public ItemTemplate(string path)
- : base(path){}
- public ItemTemplate(Byte[] b)
- : base(b){}
-
- public void CreateExpandDelegate (TemplatedControl host, string strDataType, string method){
- Type dataType = Type.GetType(strDataType);
- Type hostType = typeof(TemplatedControl);//not sure is the best place to put the dyn method
- Type evtType = typeof(EventHandler);
- Type listBoxType = typeof(ListBox);
-
- MethodInfo evtInvoke = evtType.GetMethod ("Invoke");
- ParameterInfo [] evtParams = evtInvoke.GetParameters ();
- Type handlerArgsType = evtParams [1].ParameterType;
-
- Type [] args = { typeof (object), typeof (object), handlerArgsType };
- DynamicMethod dm = new DynamicMethod ("dyn_expand_" + method,
- typeof (void),
- args,
- hostType);
-
-
- #region IL generation
- ILGenerator il = dm.GetILGenerator (256);
- il.DeclareLocal(typeof(GraphicObject));
-
- il.Emit (OpCodes.Ldarg_1);
-
- MethodInfo miFindByName = typeof(GraphicObject).GetMethod("FindByName");
- il.Emit(OpCodes.Ldstr, "List");
- il.Emit (OpCodes.Callvirt, miFindByName);
- il.Emit (OpCodes.Stloc_0);
-
- FieldInfo fiTemplates = typeof(TemplatedControl).GetField("ItemTemplates");
- il.Emit (OpCodes.Ldloc_0);
- il.Emit (OpCodes.Ldarg_0);
- il.Emit (OpCodes.Ldfld, fiTemplates);
- il.Emit (OpCodes.Stfld, fiTemplates);
-
- il.Emit (OpCodes.Ldloc_0);
- il.Emit (OpCodes.Ldarg_1);
- il.Emit (OpCodes.Callvirt, typeof(GraphicObject).GetProperty("DataSource").GetGetMethod ());
-
- MethodInfo miGetDatas = dataType.GetMethod (method, new Type[] {});
- il.Emit (OpCodes.Callvirt, miGetDatas);
-
- il.Emit (OpCodes.Callvirt, listBoxType.GetProperty("Data").GetSetMethod ());
-
- il.Emit (OpCodes.Ret);
-
- #endregion
-
- Expand = (EventHandler)dm.CreateDelegate (evtType, host);
- }
- }
-}
-
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
using System;
+using System.Threading;
namespace Crow
{
public class Instantiator
{
- Type RootType;
- Interface.LoaderInvoker Loader;
- public Instantiator (Type _root, Interface.LoaderInvoker loader)
+ public Type RootType;
+ Interface.LoaderInvoker loader;
+
+ #region CTOR
+ public Instantiator (string path){
+ System.Globalization.CultureInfo savedCulture = Thread.CurrentThread.CurrentCulture;
+ Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo.InvariantCulture;
+
+ #if DEBUG_LOAD
+ Stopwatch loadingTime = new Stopwatch ();
+ loadingTime.Start ();
+ #endif
+ try {
+ using (IMLReader itr = new IMLReader (path)){
+ loader = itr.GetLoader ();
+ RootType = itr.RootType;
+ }
+ } catch (Exception ex) {
+ throw new Exception ("Error loading <" + path + ">:", ex);
+ }
+
+ #if DEBUG_LOAD
+ loadingTime.Stop ();
+ Debug.WriteLine ("IML Instantiator creation '{2}' : {0} ticks, {1} ms",
+ loadingTime.ElapsedTicks, loadingTime.ElapsedMilliseconds, path);
+ #endif
+
+ Thread.CurrentThread.CurrentCulture = savedCulture;
+ }
+ public Instantiator (Type _root, Interface.LoaderInvoker _loader)
{
RootType = _root;
- Loader = loader;
+ loader = _loader;
}
+ #endregion
+
public GraphicObject CreateInstance(){
GraphicObject tmp = (GraphicObject)Activator.CreateInstance(RootType);
- Loader (tmp);
+ loader (tmp);
return tmp;
}
}
using System.Xml;
using System.Xml.Serialization;
using Cairo;
+using System.Globalization;
namespace Crow
{
}
public Interface(){
Interface.CurrentInterface = this;
+ CultureInfo.DefaultThreadCurrentCulture = System.Globalization.CultureInfo.InvariantCulture;
}
#endregion
System.Globalization.CultureInfo savedCulture = Thread.CurrentThread.CurrentCulture;
Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo.InvariantCulture;
- GraphicObject tmp = null;
try {
- if (!Instantiators.ContainsKey(path))
- BuildInstaciator(path);
- tmp = Instantiators [path].CreateInstance ();
-
+ return GetInstantiator (path).CreateInstance ();
} catch (Exception ex) {
throw new Exception ("Error loading <" + path + ">:", ex);
}
Thread.CurrentThread.CurrentCulture = savedCulture;
-
- return tmp;
}
- public static void BuildInstaciator (string path)
- {
- System.Globalization.CultureInfo savedCulture = Thread.CurrentThread.CurrentCulture;
- Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo.InvariantCulture;
-
- #if DEBUG_LOAD
- Stopwatch loadingTime = new Stopwatch ();
- loadingTime.Start ();
- #endif
-
- try {
- using (IMLReader itr = new IMLReader (path)){
- Instantiators[path] = itr.GetInstanciator();
- }
- } catch (Exception ex) {
- throw new Exception ("Error loading <" + path + ">:", ex);
- }
-
- #if DEBUG_LOAD
- loadingTime.Stop ();
- Debug.WriteLine ("IML Loading '{2}' : {0} ticks, {1} ms",
- loadingTime.ElapsedTicks, loadingTime.ElapsedMilliseconds, path);
- #endif
-
- Thread.CurrentThread.CurrentCulture = savedCulture;
+ /// <summary>
+ /// fetch it from cache or create it
+ /// </summary>
+ public static Instantiator GetInstantiator(string path){
+ if (!Instantiators.ContainsKey(path))
+ Instantiators [path] = new Instantiator(path);
+ return Instantiators [path];
+ }
+ public static ItemTemplate GetItemTemplate(string path){
+ if (!Instantiators.ContainsKey(path))
+ Instantiators [path] = new ItemTemplate(path);
+ return Instantiators [path] as ItemTemplate;
}
-
public GraphicObject LoadInterface (string path)
{
lock (UpdateMutex) {
--- /dev/null
+//
+// IMLStream.cs
+//
+// Author:
+// Jean-Philippe Bruyère <jp.bruyere@hotmail.com>
+//
+// Copyright (c) 2016 jp
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program. If not, see <http://www.gnu.org/licenses/>.
+using System;
+using System.IO;
+using System.Reflection;
+using System.Reflection.Emit;
+using System.Threading;
+using System.Xml.Serialization;
+using System.Xml;
+using System.Collections.Generic;
+using System.Diagnostics;
+
+namespace Crow
+{
+ public class ItemTemplate : Instantiator {
+ public EventHandler Expand;
+
+ #region CTOR
+ public ItemTemplate(string path)
+ : base(path) {
+ }
+ public ItemTemplate (Type _root, Interface.LoaderInvoker _loader)
+ :base(_root, _loader)
+ {
+ }
+ #endregion
+
+ public void CreateExpandDelegate (TemplatedControl host, string strDataType, string method){
+ Type dataType = Type.GetType(strDataType);
+ Type hostType = typeof(TemplatedControl);//not sure is the best place to put the dyn method
+ Type evtType = typeof(EventHandler);
+ Type listBoxType = typeof(ListBox);
+
+ MethodInfo evtInvoke = evtType.GetMethod ("Invoke");
+ ParameterInfo [] evtParams = evtInvoke.GetParameters ();
+ Type handlerArgsType = evtParams [1].ParameterType;
+
+ Type [] args = { typeof (object), typeof (object), handlerArgsType };
+ DynamicMethod dm = new DynamicMethod ("dyn_expand_" + method,
+ typeof (void),
+ args,
+ hostType);
+
+
+ #region IL generation
+ ILGenerator il = dm.GetILGenerator (256);
+ il.DeclareLocal(typeof(GraphicObject));
+
+ il.Emit (OpCodes.Ldarg_1);
+
+ MethodInfo miFindByName = typeof(GraphicObject).GetMethod("FindByName");
+ il.Emit(OpCodes.Ldstr, "List");
+ il.Emit (OpCodes.Callvirt, miFindByName);
+ il.Emit (OpCodes.Stloc_0);
+
+ FieldInfo fiTemplates = typeof(TemplatedControl).GetField("ItemTemplates");
+ il.Emit (OpCodes.Ldloc_0);
+ il.Emit (OpCodes.Ldarg_0);
+ il.Emit (OpCodes.Ldfld, fiTemplates);
+ il.Emit (OpCodes.Stfld, fiTemplates);
+
+ il.Emit (OpCodes.Ldloc_0);
+ il.Emit (OpCodes.Ldarg_1);
+ il.Emit (OpCodes.Callvirt, typeof(GraphicObject).GetProperty("DataSource").GetGetMethod ());
+
+ MethodInfo miGetDatas = dataType.GetMethod (method, new Type[] {});
+ il.Emit (OpCodes.Callvirt, miGetDatas);
+
+ il.Emit (OpCodes.Callvirt, listBoxType.GetProperty("Data").GetSetMethod ());
+
+ il.Emit (OpCodes.Ret);
+
+ #endregion
+
+ Expand = (EventHandler)dm.CreateDelegate (evtType, host);
+ }
+ }
+}
+