public ConstructorBuilder CreateConstructor(TypeBuilder type, Type[] args, ExecBld body) { var cnstr = type.DefineConstructor(MethodAttributes.Public, CallingConventions.Standard, args); body.Build(cnstr.GetILGenerator()); return(cnstr); }
public void AddProperty(TypeBuilder type, PropertyInfo t, ExecBld get, ExecBld set, Type prototype) { var prop = type.DefineProperty(t.Name, PropertyAttributes.None, t.PropertyType, Type.EmptyTypes); var propSettings = MethodAttributes.Virtual; var getMeth = type.DefineMethod("get_" + t.Name, propSettings, t.PropertyType, Type.EmptyTypes); get.Build(getMeth.GetILGenerator()); prop.SetGetMethod(getMeth); type.DefineMethodOverride(getMeth, prototype.GetMethod(getMeth.Name)); var setMeth = type.DefineMethod("set_" + t.Name, propSettings, null, new[] { t.PropertyType }); set.Build(setMeth.GetILGenerator()); prop.SetSetMethod(setMeth); type.DefineMethodOverride(setMeth, prototype.GetMethod(setMeth.Name)); }
public static ExecBld Cast(ExecBld src, Type tSrc, Type tDst) { if (!tSrc.IsSubclassOf(typeof(ValueType)) && tDst.IsSubclassOf(typeof(ValueType))) { return(new ExecBld(new ExecBldItem(OpCodes.Unbox_Any, tDst), src.m_items)); } else if (!tSrc.IsSubclassOf(typeof(ValueType)) && !tDst.IsSubclassOf(typeof(ValueType))) { return(new ExecBld(new ExecBldItem(OpCodes.Castclass, tDst), src.m_items)); } else if (tSrc.IsSubclassOf(typeof(ValueType)) && !tDst.IsSubclassOf(typeof(ValueType))) { return(new ExecBld(new ExecBldItem(OpCodes.Box, tSrc), src.m_items)); } else { return(Cast(Cast(src, tSrc, typeof(object)), typeof(object), tDst)); } }
public PropertyBuilder AddProperty(TypeBuilder type, string propertyName, Type propertyType) { var fieldName = "_" + propertyName; var field = type.DefineField(fieldName, propertyType, FieldAttributes.Private); var prop = type.DefineProperty(propertyName, PropertyAttributes.HasDefault, propertyType, null); var propSettings = MethodAttributes.Public | MethodAttributes.SpecialName | MethodAttributes.HideBySig; var getMeth = type.DefineMethod("get_" + propertyName, propSettings, propertyType, Type.EmptyTypes); var get = ExecBld.Return(ExecBld.GetFld(field, ExecBld.GetThis())); get.Build(getMeth.GetILGenerator()); prop.SetGetMethod(getMeth); var setMeth = type.DefineMethod("set_" + propertyName, propSettings, null, new Type[] { propertyType }); var set = ExecBld.Return(ExecBld.SetFld(field, ExecBld.GetThis(), ExecBld.GetArg(1))); set.Build(setMeth.GetILGenerator()); prop.SetSetMethod(setMeth); return(prop); }
public void CreateMethod(TypeBuilder type, string name, Type returnType, Type[] argType, Type interf, ExecBld body) { var equelMeth = type.DefineMethod(name, MethodAttributes.Virtual, returnType, argType); body.Build(equelMeth.GetILGenerator()); if (interf != null) { type.DefineMethodOverride(equelMeth, interf.GetMethod(name)); } }
public static ExecBld SetProp(PropertyInfo prop, ExecBld src, ExecBld value) { return(new ExecBld(new ExecBldItem(OpCodes.Callvirt, prop.GetSetMethod(true)), src.m_items.Union(value.m_items))); }
public static ExecBld GetProp(PropertyBuilder prop, ExecBld src) { return(new ExecBld(new ExecBldItem(OpCodes.Callvirt, prop.GetGetMethod(true)), src.m_items)); }
public static ExecBld SetFld(FieldBuilder field, ExecBld src, ExecBld value) { return(new ExecBld(new ExecBldItem(OpCodes.Stfld, field), src.m_items.Union(value.m_items))); }
public static ExecBld GetFld(FieldBuilder field, ExecBld src) { return(new ExecBld(new ExecBldItem(OpCodes.Ldfld, field), src.m_items)); }
public static ExecBld Return(ExecBld src) { return(new ExecBld(new ExecBldItem(OpCodes.Ret), src.m_items)); }
public static ExecBld SetItem <T>(ExecBld src, ExecBld index, ExecBld value) { return(new ExecBld(new ExecBldItem(OpCodes.Stelem, typeof(T)), src.m_items.Union(index.m_items).Union(value.m_items))); }
public static ExecBld GetItem <T>(ExecBld src, ExecBld index) { return(new ExecBld(new ExecBldItem(OpCodes.Ldelem, typeof(T)), src.m_items.Union(index.m_items))); }
public static ExecBld SetLoc(int index, ExecBld value) { return(new ExecBld(new ExecBldItem(OpCodes.Stloc, index), value.m_items)); }