public void Call()
        {
            Utilities.Reflection.Emit.Assembly    Assembly = new Utilities.Reflection.Emit.Assembly("TestAssembly");
            Utilities.Reflection.Emit.TypeBuilder TestType = Assembly.CreateType("TestType");
            IMethodBuilder Method = TestType.CreateMethod("TestMethod");

            Utilities.Reflection.Emit.FieldBuilder Field = TestType.CreateField("Field1", typeof(int));
            Field.Call("ToString");
        }
Example #2
0
 /// <summary>
 /// Sets up a property (List)
 /// </summary>
 /// <param name="Method">Method builder</param>
 /// <param name="BaseType">Base type for the object</param>
 /// <param name="ReturnValue">Return value</param>
 /// <param name="Property">Property info</param>
 /// <param name="Mapping">Mapping info</param>
 private void SetupListProperty(IMethodBuilder Method, Type BaseType, VariableBase ReturnValue, IProperty Property, IMapping Mapping)
 {
     Utilities.Reflection.Emit.FieldBuilder Field       = Fields.Find(x => x.Name == Property.DerivedFieldName);
     Utilities.Reflection.Emit.FieldBuilder FieldLoaded = Fields.Find(x => x.Name == Property.DerivedFieldName + "_Loaded");
     Utilities.Reflection.Emit.Commands.If  If1         = Method.If((VariableBase)SessionField, Comparison.NotEqual, null);
     {
         Utilities.Reflection.Emit.Commands.If If2 = Method.If(Field, Comparison.Equal, null);
         {
             Utilities.Reflection.Emit.Commands.If If3 = Method.If(FieldLoaded, Comparison.Equal, Method.CreateConstant(false));
             {
                 //Load data
                 VariableBase IDValue      = Method.This.Call(BaseType.GetProperty(Mapping.IDProperty.Name).GetGetMethod());
                 VariableBase IDParameter  = Method.NewObj(typeof(EqualParameter <>).MakeGenericType(Mapping.IDProperty.Type), new object[] { IDValue, "ID", "@" });
                 VariableBase PropertyList = Method.NewObj(typeof(List <IParameter>));
                 PropertyList.Call("Add", new object[] { IDParameter });
                 MethodInfo LoadPropertiesMethod = typeof(Session).GetMethod("LoadListProperties");
                 LoadPropertiesMethod = LoadPropertiesMethod.MakeGenericMethod(new Type[] { BaseType, Field.DataType.GetGenericArguments()[0] });
                 VariableBase ReturnVal = ((VariableBase)SessionField).Call(LoadPropertiesMethod, new object[] { Method.This, Property.Name, PropertyList.Call("ToArray") });
                 Field.Assign(ReturnVal);
                 FieldLoaded.Assign(true);
             }
             If3.EndIf();
         }
         If2.EndIf();
         PropertyInfo CountProperty = Field.DataType.GetProperty("Count");
         Utilities.Reflection.Emit.Commands.If If4 = Method.If(Field.Call(CountProperty.GetGetMethod()), Comparison.Equal, Method.CreateConstant(0));
         {
             Utilities.Reflection.Emit.Commands.If If3 = Method.If(FieldLoaded, Comparison.Equal, Method.CreateConstant(false));
             {
                 //Load data
                 VariableBase IDValue      = Method.This.Call(BaseType.GetProperty(Mapping.IDProperty.Name).GetGetMethod());
                 VariableBase IDParameter  = Method.NewObj(typeof(EqualParameter <>).MakeGenericType(Mapping.IDProperty.Type), new object[] { IDValue, "ID", "@" });
                 VariableBase PropertyList = Method.NewObj(typeof(List <IParameter>));
                 PropertyList.Call("Add", new object[] { IDParameter });
                 MethodInfo LoadPropertiesMethod = typeof(Session).GetMethod("LoadProperties");
                 LoadPropertiesMethod = LoadPropertiesMethod.MakeGenericMethod(new Type[] { BaseType, Field.DataType.GetGenericArguments()[0] });
                 VariableBase ReturnVal = ((VariableBase)SessionField).Call(LoadPropertiesMethod, new object[] { Method.This, Property.Name, PropertyList.Call("ToArray") });
                 Field.Assign(ReturnVal);
                 FieldLoaded.Assign(true);
             }
             If3.EndIf();
         }
         If4.EndIf();
         Utilities.Reflection.Emit.Commands.If If5 = Method.If(Field, Comparison.Equal, null);
         {
             Field.Assign(Method.NewObj(typeof(List <>).MakeGenericType(Property.Type).GetConstructor(Type.EmptyTypes)));
         }
         If5.EndIf();
     }
     If1.EndIf();
     ReturnValue.Assign(Field);
 }