コード例 #1
0
        private void GenerateSetValuesDirect(ILBuilder processor, Func <MemberHandler, bool> cb1, Func <MemberHandler, bool> cb2)
        {
            // User u = (User)o;
            processor.DeclareLocal(_model);
            processor.LoadArg(2).Cast(_model).SetLoc(0);
            // set values
            int n = 0;

            foreach (var f in _info.Members)
            {
                if (!f.Is.DbGenerate && !f.Is.HasOne && !f.Is.HasMany && !f.Is.HasAndBelongsToMany)
                {
                    if (!cb1(f))
                    {
                        processor.LoadArg(1).LoadArg(0).LoadInt(n);
                        if (cb2(f))
                        {
                            processor.LoadInt(f.Is.Count ? 1 : 2)
                            .Call(handlerBaseTypeNewSpKeyValueDirect);
                        }
                        else
                        {
                            processor.LoadLoc(0);
                            processor.GetMember(f);
                            if (f.Is.BelongsTo)
                            {
                                processor.CallVirtual(f.MemberType.GetMethod("get_ForeignKey"));
                            }
                            else if (f.Is.LazyLoad)
                            {
                                var it = f.MemberType.GetGenericArguments()[0];
                                processor.CallVirtual(f.MemberType.GetMethod("get_Value"));
                                processor.Box(it);
                            }
                            else
                            {
                                processor.Box(f.MemberType);
                            }
                            processor.Call(handlerBaseTypeNewKeyValue);
                        }
                        processor.CallVirtual(keyOpValueListAdd);
                    }
                    n++;
                }
            }
        }
コード例 #2
0
        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();
        }
コード例 #3
0
        private void GenerateSetValuesForPartialUpdate(ILBuilder processor)
        {
            // User u = (User)o;
            processor.DeclareLocal(_model);
            processor.LoadArg(2).Cast(_model).SetLoc(0);
            // set values
            int n = 0;

            foreach (var f in _info.Members)
            {
                if (!f.Is.DbGenerate && !f.Is.HasOne && !f.Is.HasMany && !f.Is.HasAndBelongsToMany)
                {
                    if (!f.Is.Key && (f.Is.UpdatedOn || f.Is.SavedOn || !f.Is.CreatedOn || f.Is.Count))
                    {
                        if (f.Is.UpdatedOn || f.Is.SavedOn || f.Is.Count)
                        {
                            processor.LoadArg(1).LoadArg(0).LoadInt(n)
                            .LoadInt(f.Is.Count ? 1 : 2)
                            .Call(handlerBaseTypeNewSpKeyValueDirect).CallVirtual(keyOpValueListAdd);
                        }
                        else
                        {
                            processor.LoadArg(0).LoadArg(1).LoadLoc(0).LoadString(f.Name).LoadInt(n).LoadLoc(0);
                            processor.GetMember(f);
                            if (f.Is.BelongsTo)
                            {
                                processor.CallVirtual(f.MemberType.GetMethod("get_ForeignKey"));
                            }
                            else if (f.Is.LazyLoad)
                            {
                                var it = f.MemberType.GetGenericArguments()[0];
                                processor.CallVirtual(f.MemberType.GetMethod("get_Value"));
                                processor.Box(it);
                            }
                            else
                            {
                                processor.Box(f.MemberType);
                            }
                            processor.Call(handlerBaseTypeAddKeyValue);
                        }
                    }
                    n++;
                }
            }
        }
コード例 #4
0
        private void GenerateGetKeyValuesDirect()
        {
            var method = _result.DefineMethod("GetKeyValuesDirect", MethodAttr,
                                              null, new Type[] { dictionaryStringObjectType, objectType });

            _result.DefineMethodOverride(method, handlerBaseGetKeyValuesDirect);
            var processor = new ILBuilder(method.GetILGenerator());

            // User u = (User)o;
            processor.DeclareLocal(_model);
            processor.LoadArg(2).Cast(_model).SetLoc(0);
            // set values
            foreach (var f in _info.KeyMembers)
            {
                processor.LoadArg(1).LoadString(f.Name).LoadLoc(0);
                processor.GetMember(f);
                processor.Box(f.MemberType).CallVirtual(dictionaryStringObjectAdd);
            }

            processor.Return();
        }
コード例 #5
0
        private void GenerateGetKeyValueDirect()
        {
            var method = _result.DefineMethod("GetKeyValueDirect", MethodAttr,
                                              objectType, new Type[] { objectType });

            _result.DefineMethodOverride(method, handlerBaseGetKeyValueDirect);
            var processor = new ILBuilder(method.GetILGenerator());

            if (_info.KeyMembers.Length == 1)
            {
                var h = _info.KeyMembers[0];
                processor.LoadArg(1).Cast(_model);
                processor.GetMember(h);
                processor.Box(h.MemberType);
            }
            else
            {
                processor.LoadNull();
            }

            processor.Return();
        }
コード例 #6
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();
        }
コード例 #7
0
		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();
		}