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; } } } }
/// <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))); } } } } } }
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; } } } }