private static void GenerateSetValue(Type model, TypeBuilder builder, TinyMember info, Type memberType)
		{
			var method = builder.DefineMethod("SetValue", CtMethodAttr, 
				null, new Type[]{objectType, objectType});
			var processor = new ILBuilder(method.GetILGenerator());

			processor.LoadArg(1).Cast(model).LoadArg(2).CastOrUnbox(memberType);
			processor.SetMember(info);
			processor.Return();
		}
		private static void GenerateGetValue(Type model, TypeBuilder builder, TinyMember info, Type memberType)
		{
			var method = builder.DefineMethod("GetValue", CtMethodAttr, 
				objectType, new Type[]{objectType});
			var processor = new ILBuilder(method.GetILGenerator());

			processor.DeclareLocal(objectType);
			processor.LoadArg(1).Cast(model);
			processor.GetMember(info);
			if (memberType.IsValueType)
			{
				processor.Box(memberType);
			}
			processor.SetLoc(0);
			processor.LoadLoc(0);
			processor.Return();
		}
Example #3
0
        private void GenerateNewMemberWithPrivateSetter(MemberHandler pi, ILBuilder processor, ILBuilder ctorBuilder)
        {
            var dt = typeof(Action <,>).MakeGenericType(_model, pi.MemberType);
            var df = _result.DefineField("$" + pi.MemberInfo.Name, dt, fieldFlag);

            ctorBuilder.LoadArg(0);
            ctorBuilder.LoadToken(dt);
            ctorBuilder.Call(getTypeFromHandle);
            ctorBuilder.LoadLoc(0);
            ctorBuilder.LoadString(pi.MemberInfo.Name);
            ctorBuilder.CallVirtual(getProperty);
            ctorBuilder.LoadInt(1);
            ctorBuilder.CallVirtual(getSetMethod);
            ctorBuilder.Call(createDelegate);
            ctorBuilder.Cast(dt);
            ctorBuilder.SetField(df);

            processor.LoadArg(0);
            processor.LoadField(df);
            processor.LoadArg(1);
            GenerateNewMember(pi, processor);
            var invoke = dt.GetMethod("Invoke");

            processor.CallVirtual(invoke);
        }
Example #4
0
        private void GenerateLoadRelationValues(bool useIndex, bool noLazy)
        {
            int    index      = _info.SimpleMembers.Length;
            string methodName = useIndex ? "LoadRelationValuesByIndex" : "LoadRelationValuesByName";

            if (noLazy)
            {
                methodName = methodName + "NoLazy";
            }

            var method = _result.DefineMethod(methodName, MethodAttr,
                                              null, new Type[] { objectType, iDataReaderType });

            _result.DefineMethodOverride(method, useIndex
                ? (noLazy ? handlerBaseLoadRelationValuesByIndexNoLazy : handlerBaseLoadRelationValuesByIndex)
                : (noLazy ? handlerBaseLoadRelationValuesByNameNoLazy : handlerBaseLoadRelationValuesByName));
            var processor = new ILBuilder(method.GetILGenerator());

            if (_info.RelationMembers.Length > 0)
            {
                // User u = (User)o;
                processor.DeclareLocal(_model);
                processor.LoadArg(1).Cast(_model).SetLoc(0);
                // set values
                foreach (var f in _info.RelationMembers)
                {
                    if (f.Is.LazyLoad)
                    {
                        if (noLazy)
                        {
                            processor.LoadLoc(0);
                            processor.GetMember(f);
                            processor.LoadArg(2);
                            if (useIndex)
                            {
                                processor.LoadInt(index++).CallVirtual(dataReaderMethodInt);
                            }
                            else
                            {
                                processor.LoadString(f.Name).CallVirtual(dataReaderMethodString);
                            }
                            processor.LoadInt(0);
                            processor.CallVirtual(lazyLoadingInterfaceWrite);
                        }
                    }
                    else if (f.Is.BelongsTo)
                    {
                        processor.LoadLoc(0);
                        processor.GetMember(f);
                        processor.LoadArg(2);
                        if (useIndex)
                        {
                            processor.LoadInt(index++).CallVirtual(dataReaderMethodInt);
                        }
                        else
                        {
                            processor.LoadString(f.Name).CallVirtual(dataReaderMethodString);
                        }
                        processor.CallVirtual(belongsToInterfaceSetForeignKey);
                    }
                }
            }

            processor.Return();
        }