Пример #1
0
 /// <summary>
 /// Sets up the fields needed to store the data for lazy loading
 /// </summary>
 /// <param name="TypeBuilder"></param>
 private void SetupFields(Reflection.Emit.TypeBuilder TypeBuilder)
 {
     if (ClassMappings.ContainsKey(TypeBuilder.BaseClass))
     {
         foreach (IMapping Mapping in ClassMappings[TypeBuilder.BaseClass])
         {
             foreach (IProperty Property in Mapping.Properties)
             {
                 if (Property is IManyToOne || Property is IMap)
                 {
                     if (Fields.FirstOrDefault(x => x.Name == Property.DerivedFieldName) == null)
                     {
                         Fields.Add(TypeBuilder.CreateField(Property.DerivedFieldName, Property.Type));
                     }
                 }
                 else if (Property is IIEnumerableManyToOne || Property is IManyToMany)
                 {
                     if (Fields.FirstOrDefault(x => x.Name == Property.DerivedFieldName) == null)
                     {
                         Fields.Add(TypeBuilder.CreateField(Property.DerivedFieldName, typeof(IEnumerable <>).MakeGenericType(Property.Type)));
                     }
                 }
                 else if (Property is IListManyToOne || Property is IListManyToMany)
                 {
                     if (Fields.FirstOrDefault(x => x.Name == Property.DerivedFieldName) == null)
                     {
                         Fields.Add(TypeBuilder.CreateField(Property.DerivedFieldName, typeof(List <>).MakeGenericType(Property.Type)));
                     }
                 }
             }
         }
     }
 }
Пример #2
0
 public void SetupInterfaces(Reflection.Emit.TypeBuilder TypeBuilder)
 {
     Fields       = new List <Reflection.Emit.FieldBuilder>();
     SessionField = CreateProperty(TypeBuilder, "Session0", typeof(Session));
     CreateConstructor(TypeBuilder);
     SetupFields(TypeBuilder);
 }
Пример #3
0
 /// <summary>
 /// Creates the default constructor
 /// </summary>
 /// <param name="TypeBuilder">Type builder</param>
 private void CreateConstructor(Reflection.Emit.TypeBuilder TypeBuilder)
 {
     IMethodBuilder Constructor = TypeBuilder.CreateConstructor();
     {
         Constructor.SetCurrentMethod();
         Constructor.This.Call(TypeBuilder.BaseClass.GetConstructor(Type.EmptyTypes));
         Constructor.Return();
     }
 }
Пример #4
0
 /// <summary>
 /// Creates a default property
 /// </summary>
 /// <param name="TypeBuilder">Type builder</param>
 /// <param name="Name">Name of the property</param>
 /// <param name="PropertyType">Property type</param>
 /// <returns>The property builder</returns>
 private IPropertyBuilder CreateProperty(Reflection.Emit.TypeBuilder TypeBuilder, string Name, Type PropertyType)
 {
     return(TypeBuilder.CreateDefaultProperty(Name, PropertyType, PropertyAttributes.SpecialName,
                                              MethodAttributes.Virtual | MethodAttributes.HideBySig | MethodAttributes.SpecialName | MethodAttributes.Public,
                                              MethodAttributes.Virtual | MethodAttributes.HideBySig | MethodAttributes.SpecialName | MethodAttributes.Public));
 }