public virtual void GoTo(Label label) { if (mv != null) { mv.GoTo(label); } }
protected void ImplementSetRelation(RelationMember[] relationMembers, FieldInstance[] f_relations) { MethodInstance template_m_setRelation = new MethodInstance(null, typeof(RootCacheValue), typeof(void), "SetRelation", typeof(int), typeof(IObjRef[])); IMethodVisitor mv = VisitMethod(template_m_setRelation); Label l_finish = mv.NewLabel(); for (int relationIndex = 0, size = f_relations.Length; relationIndex < size; relationIndex++) { FieldInstance f_relation = f_relations[relationIndex]; Label l_notEqual = mv.NewLabel(); mv.LoadArg(0); mv.Push(relationIndex); mv.IfCmp(typeof(int), CompareOperator.NE, l_notEqual); mv.PutThisField(f_relation, delegate(IMethodVisitor mg) { mg.LoadArg(1); }); mv.GoTo(l_finish); mv.Mark(l_notEqual); } mv.ThrowException(typeof(ArgumentException), "Given relationIndex not known"); mv.Mark(l_finish); mv.ReturnValue(); mv.EndMethod(); }
protected void ImplementSetValue(IPropertyInfo[] propertyPath) { IMethodVisitor mv = VisitMethod(template_m_setValue); IPropertyInfo lastProperty = propertyPath[propertyPath.Length - 1]; if (lastProperty is MethodPropertyInfo && ((MethodPropertyInfo)lastProperty).Setter == null) { throw new Exception("Property not writable: " + lastProperty.EntityType.FullName + "." + lastProperty.Name); } mv.LoadArg(0); Type typeOfArgumentOnStack = typeof(Object); for (int a = 0, size = propertyPath.Length - 1; a < size; a++) { typeOfArgumentOnStack = InvokeGetProperty(mv, propertyPath[a], typeOfArgumentOnStack); } if (!lastProperty.DeclaringType.Equals(typeOfArgumentOnStack)) { mv.CheckCast(lastProperty.DeclaringType); } mv.LoadArg(1); Type lastPropertyType = lastProperty.PropertyType; if (lastProperty.PropertyType.IsPrimitive) { Type pType = lastProperty.PropertyType; Label l_valueIsNonNull = mv.NewLabel(); Label l_valueIsValid = mv.NewLabel(); mv.IfNonNull(l_valueIsNonNull); mv.PushNullOrZero(pType); mv.GoTo(l_valueIsValid); mv.Mark(l_valueIsNonNull); mv.LoadArg(1); mv.Unbox(pType); mv.Mark(l_valueIsValid); } else { mv.CheckCast(lastPropertyType); } InvokeSetProperty(mv, lastProperty); mv.ReturnValue(); mv.EndMethod(); }
protected void ImplementSetPrimitives(Member[] primitiveMembers, FieldInstance[] f_primitives, FieldInstance[] f_nullFlags) { MethodInstance template_m_setPrimitives = new MethodInstance(null, typeof(RootCacheValue), typeof(void), "SetPrimitives", typeof(Object[])); IMethodVisitor mv = VisitMethod(template_m_setPrimitives); LocalVariableInfo loc_item = mv.NewLocal(objType); for (int primitiveIndex = 0, size = f_primitives.Length; primitiveIndex < size; primitiveIndex++) { FieldInstance f_primitive = f_primitives[primitiveIndex]; FieldInstance f_nullFlag = f_nullFlags[primitiveIndex]; Member member = primitiveMembers[primitiveIndex]; Type originalType = member.RealType; Script script_loadArrayValue = new Script(delegate(IMethodVisitor mg) { mg.LoadArg(0); mg.Push(primitiveIndex); mg.ArrayLoad(objType); }); Label l_finish = mv.NewLabel(); if (f_nullFlag == null) { if (!originalType.IsValueType) { mv.PutThisField(f_primitive, script_loadArrayValue); continue; } script_loadArrayValue(mv); mv.StoreLocal(loc_item); mv.LoadLocal(loc_item); mv.IfNull(l_finish); mv.PutThisField(f_primitive, new Script(delegate(IMethodVisitor mg) { mg.LoadLocal(loc_item); mg.Unbox(f_primitive.Type.Type); })); mv.Mark(l_finish); continue; } Label l_itemIsNull = mv.NewLabel(); script_loadArrayValue(mv); mv.StoreLocal(loc_item); mv.LoadLocal(loc_item); mv.IfNull(l_itemIsNull); mv.PutThisField(f_primitive, delegate(IMethodVisitor mg) { mg.LoadLocal(loc_item); mg.Unbox(f_primitive.Type.Type); }); if (f_nullFlag != null) { // field is a nullable numeric value in the entity, but a native numeric value in our RCV mv.PutThisField(f_nullFlag, delegate(IMethodVisitor mg) { mg.Push(false); }); } mv.GoTo(l_finish); mv.Mark(l_itemIsNull); if (f_nullFlag != null) { // field is a nullable numeric value in the entity, but a native numeric value in our RCV mv.PutThisField(f_nullFlag, delegate(IMethodVisitor mg) { mg.Push(true); }); } else { mv.PutThisField(f_primitive, delegate(IMethodVisitor mg) { mg.PushNullOrZero(f_primitive.Type.Type); }); } mv.Mark(l_finish); } mv.ReturnValue(); mv.EndMethod(); }