Example #1
0
 /// <summary>
 /// Sets up a property (IEnumerable)
 /// </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 SetupIEnumerableProperty(IMethodBuilder Method, Type BaseType, Reflection.Emit.BaseClasses.VariableBase ReturnValue, IProperty Property, IMapping Mapping)
 {
     Utilities.Reflection.Emit.FieldBuilder Field = Fields.Find(x => x.Name == Property.DerivedFieldName);
     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);
         {
             //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);
         }
         If2.EndIf();
         Utilities.Reflection.Emit.Commands.If If3 = Method.If(Field, Comparison.Equal, null);
         {
             Field.Assign(Method.NewObj(typeof(List <>).MakeGenericType(Property.Type).GetConstructor(Type.EmptyTypes)));
         }
         If3.EndIf();
     }
     If1.EndIf();
     ReturnValue.Assign(Field);
 }
 public void GetDefinition()
 {
     Utilities.Reflection.Emit.Assembly     Assembly = new Utilities.Reflection.Emit.Assembly("TestAssembly");
     Utilities.Reflection.Emit.TypeBuilder  TestType = Assembly.CreateType("TestType");
     Utilities.Reflection.Emit.FieldBuilder Field    = TestType.CreateField("Field1", typeof(int));
     Assert.NotEmpty(Field.GetDefinition());
 }
        public void Save()
        {
            Utilities.Reflection.Emit.Assembly     Assembly = new Utilities.Reflection.Emit.Assembly("TestAssembly");
            Utilities.Reflection.Emit.TypeBuilder  TestType = Assembly.CreateType("TestType");
            Utilities.Reflection.Emit.FieldBuilder Field    = TestType.CreateField("Field1", typeof(int));
            IMethodBuilder Method = TestType.CreateMethod("TestMethod");

            Field.Save(Method.Generator);
        }
        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 #5
0
        public void Load()
        {
            Utilities.Reflection.Emit.Assembly     Assembly = new Utilities.Reflection.Emit.Assembly("TestAssembly");
            Utilities.Reflection.Emit.TypeBuilder  TestType = Assembly.CreateType("TestType");
            Utilities.Reflection.Emit.FieldBuilder Field    = TestType.CreateField("Field1", typeof(int));
            IMethodBuilder Method = TestType.CreateMethod("TestMethod");

            Assert.DoesNotThrow <Exception>(() => Field.Load(Method.Generator));
        }
Example #6
0
        public void Assign()
        {
            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));
            Assert.DoesNotThrow(() => Field.Assign(12));
        }
 public void Create()
 {
     Utilities.Reflection.Emit.Assembly     Assembly = new Utilities.Reflection.Emit.Assembly("TestAssembly");
     Utilities.Reflection.Emit.TypeBuilder  TestType = Assembly.CreateType("TestType");
     Utilities.Reflection.Emit.FieldBuilder Field    = TestType.CreateField("Field1", typeof(int));
     Assert.NotNull(Field);
     Assert.Equal(typeof(int), Field.DataType);
     Assert.Equal("Field1", Field.Name);
     Assert.Equal(FieldAttributes.Public, Field.Attributes);
     Assert.NotNull(Field.Builder);
 }
Example #8
0
 public void SetupStartMethod(Reflection.Emit.Interfaces.IMethodBuilder Method, Type BaseType)
 {
     Method.SetCurrentMethod();
     if (ClassMappings.ContainsKey(BaseType) &&
         Method.Name.StartsWith("set_"))
     {
         foreach (IMapping Mapping in ClassMappings[BaseType])
         {
             string    PropertyName = Method.Name.Replace("set_", "");
             IProperty Property     = Mapping.Properties.Find(x => x.Name == PropertyName);
             if (Property != null)
             {
                 Utilities.Reflection.Emit.FieldBuilder Field = Fields.Find(x => x.Name == Property.DerivedFieldName);
                 if (Field != null)
                 {
                     Field.Assign(Method.Parameters[1]);
                 }
                 return;
             }
         }
     }
 }