public DynamicMethod CreateInitalizeCollectionMethod(Type proxyType) { if (this._collectionProperties.Count <= 0) { return((DynamicMethod)null); } DynamicMethod dynamicMethod = IPocoImplementor.CreateDynamicMethod(proxyType.Name + "_InitializeEntityCollections", typeof(IEntityWrapper), new Type[1] { typeof(IEntityWrapper) }); ILGenerator ilGenerator = dynamicMethod.GetILGenerator(); ilGenerator.DeclareLocal(proxyType); ilGenerator.DeclareLocal(typeof(RelationshipManager)); ilGenerator.Emit(OpCodes.Ldarg_0); ilGenerator.Emit(OpCodes.Callvirt, IPocoImplementor.GetEntityMethod); ilGenerator.Emit(OpCodes.Castclass, proxyType); ilGenerator.Emit(OpCodes.Stloc_0); ilGenerator.Emit(OpCodes.Ldloc_0); ilGenerator.Emit(OpCodes.Callvirt, IPocoImplementor.GetRelationshipManagerMethod); ilGenerator.Emit(OpCodes.Stloc_1); foreach (KeyValuePair <NavigationProperty, PropertyInfo> collectionProperty in this._collectionProperties) { MethodInfo meth = IPocoImplementor.GetRelatedCollectionMethod.MakeGenericMethod(EntityUtil.GetCollectionElementType(collectionProperty.Value.PropertyType)); ilGenerator.Emit(OpCodes.Ldloc_0); ilGenerator.Emit(OpCodes.Ldloc_1); ilGenerator.Emit(OpCodes.Ldstr, collectionProperty.Key.RelationshipType.FullName); ilGenerator.Emit(OpCodes.Ldstr, collectionProperty.Key.ToEndMember.Name); ilGenerator.Emit(OpCodes.Callvirt, meth); ilGenerator.Emit(OpCodes.Callvirt, collectionProperty.Value.Setter()); } ilGenerator.Emit(OpCodes.Ldarg_0); ilGenerator.Emit(OpCodes.Ret); return(dynamicMethod); }
public ProxyTypeBuilder(ClrEntityType ospaceEntityType) { _ospaceEntityType = ospaceEntityType; _baseImplementor = new BaseProxyImplementor(); _ipocoImplementor = new IPocoImplementor(ospaceEntityType); _lazyLoadImplementor = new LazyLoadImplementor(ospaceEntityType); _dataContractImplementor = new DataContractImplementor(ospaceEntityType); _iserializableImplementor = new SerializableImplementor(ospaceEntityType); }