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);
 }
Example #2
0
 public void SetupEndMethod(Reflection.Emit.Interfaces.IMethodBuilder Method, Type BaseType, Reflection.Emit.BaseClasses.VariableBase ReturnValue)
 {
     Method.SetCurrentMethod();
     if (ClassMappings.ContainsKey(BaseType) &&
         Method.Name.StartsWith("get_"))
     {
         foreach (IMapping Mapping in ClassMappings[BaseType])
         {
             string    PropertyName = Method.Name.Replace("get_", "");
             IProperty Property     = Mapping.Properties.Find(x => x.Name == PropertyName);
             if (Property != null)
             {
                 if (Property is IManyToOne || Property is IMap)
                 {
                     SetupSingleProperty(Method, BaseType, ReturnValue, Property, Mapping);
                 }
                 else if (Property is IIEnumerableManyToOne || Property is IManyToMany)
                 {
                     SetupIEnumerableProperty(Method, BaseType, ReturnValue, Property, Mapping);
                 }
                 else if (Property is IListManyToMany || Property is IListManyToOne)
                 {
                     SetupListProperty(Method, BaseType, ReturnValue, Property, Mapping);
                 }
                 return;
             }
         }
     }
 }