Example #1
0
        private void GenerateSetKeyValueDirect()
        {
            var method = _result.DefineMethod("SetKeyValueDirect", MethodAttr,
                                              null, new Type[] { objectType, objectType });

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

            if (_info.KeyMembers.Length == 1)
            {
                var h = _info.KeyMembers[0];
                processor.LoadArg(1).Cast(_model);
                processor.LoadArg(2);
                var fh = _info.KeyMembers[0];
                if (fh.MemberType == typeof(long))
                {
                    processor.Call(convertToInt64);
                }
                else if (fh.MemberType == typeof(int))
                {
                    processor.Call(convertToInt32);
                }
                else if (fh.MemberType == typeof(Guid))
                {
                    processor.Unbox(h.MemberType);
                }
                else
                {
                    processor.Cast(h.MemberType);
                }
                processor.SetMember(h);
            }

            processor.Return();
        }
Example #2
0
        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 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();
		}
Example #4
0
        private void GenerateLoadSimpleValues(bool byIndex)
        {
            var name   = byIndex ? "LoadSimpleValuesByIndex" : "LoadSimpleValuesByName";
            var method = _result.DefineMethod(name, MethodAttr,
                                              null, new Type[] { objectType, iDataReaderType });

            _result.DefineMethodOverride(method, byIndex
                ? handlerBaseLoadSimpleValuesByIndex
                : handlerBaseLoadSimpleValuesByName);
            var processor = new ILBuilder(method.GetILGenerator());

            // User u = (User)o;
            processor.DeclareLocal(_model);
            processor.LoadArg(1).Cast(_model).SetLoc(0);
            // set values
            int n = 0;

            foreach (var f in _info.SimpleMembers)
            {
                processor.LoadLoc(0);
                if (f.Is.AllowNull)
                {
                    processor.LoadArg(0);
                }
                processor.LoadArg(2);
                if (byIndex)
                {
                    processor.LoadInt(n);
                }
                else
                {
                    processor.LoadArg(2).LoadString(f.Name).CallVirtual(dataReaderGetOrdinal);
                }
                var mi1 = DataReaderEmitHelper.GetMethodInfo(f.MemberType);
                if (f.Is.AllowNull || mi1 == null)
                {
                    processor.CallVirtual(dataReaderMethodInt);
                    if (f.Is.AllowNull)
                    {
                        SetSecendArgForGetNullable(f, processor);
                        processor.Call(handlerBaseTypeGetNullable);
                    }
                    // cast or unbox
                    processor.CastOrUnbox(f.MemberType);
                }
                else
                {
                    processor.CallVirtual(mi1);
                }
                processor.SetMember(f);
                n++;
            }

            processor.Return();
        }