]> O.S.I.I.S - jp/crow.git/commitdiff
clean code
authorjpbruyere <jp.bruyere@hotmail.com>
Fri, 18 Sep 2015 09:53:01 +0000 (11:53 +0200)
committerjpbruyere <jp.bruyere@hotmail.com>
Fri, 18 Sep 2015 09:53:01 +0000 (11:53 +0200)
src/CompilerServices/CompilerServices.cs

index 1f5df063bcea6a53fb46fa3f848aa60e8436979c..17d36f13b7ce03e606cf3ab85e3587225a3744b9 100644 (file)
@@ -280,32 +280,33 @@ namespace go
                                //MethodInfo infoWriteLine = typeof(System.Diagnostics.Debug).GetMethod("WriteLine", new Type[] { typeof(string) });
                                                        
 
-                               //load target ref onto the stack
-                               FieldInfo fiRefs = typeof(Interface).GetField("References");
-                               il.Emit(OpCodes.Ldsfld, fiRefs);
-                               il.Emit(OpCodes.Ldc_I4, dstIdx);
+                       //load target ref onto the stack
+                       FieldInfo fiRefs = typeof(Interface).GetField("References");
+                       il.Emit(OpCodes.Ldsfld, fiRefs);
+                       il.Emit(OpCodes.Ldc_I4, dstIdx);
 
-                               MethodInfo miGetRef = Interface.References.GetType().GetMethod("get_Item");
-                               il.Emit(OpCodes.Callvirt, miGetRef);
-                               il.Emit(OpCodes.Isinst, dstType);
-
-                               //push new value
-                               il.Emit(OpCodes.Ldarg_1);
-                               FieldInfo fiNewValue = typeof(ValueChangeEventArgs).GetField("NewValue");
-                               il.Emit(OpCodes.Ldfld, fiNewValue);
+                       MethodInfo miGetRef = Interface.References.GetType().GetMethod("get_Item");
+                       il.Emit(OpCodes.Callvirt, miGetRef);
+                       il.Emit(OpCodes.Isinst, dstType);
 
+                       //push new value
+                       il.Emit(OpCodes.Ldarg_1);
+                       FieldInfo fiNewValue = typeof(ValueChangeEventArgs).GetField("NewValue");
+                       il.Emit(OpCodes.Ldfld, fiNewValue);
 
-                               MethodInfo miToStr = typeof(object).GetMethod("ToString",Type.EmptyTypes);
-                               PropertyInfo piTarget = dstType.GetProperty(binding.MemberName);
+                       //Target is expected always to be a Property
+                       PropertyInfo piTarget = dstType.GetProperty(binding.MemberName);
 
-                               Type srcValueType = null;
+                       //type of the source value
+                       Type srcValueType = null;
 
+                       //member info of the source value
                        MemberInfo miSrcVal = miSrc;
+
+                       //this allow memberless binding with only a name passed as MemberName
+                       //the type of the source value is determined by the destination member
                        if (miSrcVal == null)
                                miSrcVal = miDst;
-                               //this allow memberless binding with only a name passed as MemberName
-                               //but the type is determined by the destination member
-                               
 
                        if (miSrcVal.MemberType == MemberTypes.Property)
                                srcValueType = (miSrcVal as PropertyInfo).PropertyType;
@@ -314,18 +315,15 @@ namespace go
                        else
                                throw new Exception("unandled source member type for binding");
                        
-                               if (!srcValueType.IsValueType)
-                                       il.Emit(OpCodes.Castclass, srcValueType);
-                               else if (piTarget.PropertyType != srcValueType)
-                                       il.Emit(OpCodes.Callvirt, GetConvertMethod( piTarget.PropertyType ));
-                               else
-                                       il.Emit(OpCodes.Unbox_Any, piTarget.PropertyType);
-                       //      if (piTarget.PropertyType == typeof(string))
-//                             else if ( srcValueType != piTarget.PropertyType)
-//                                     
+                       if (!srcValueType.IsValueType)
+                               il.Emit(OpCodes.Castclass, srcValueType);
+                       else if (piTarget.PropertyType != srcValueType)
+                               il.Emit(OpCodes.Callvirt, GetConvertMethod( piTarget.PropertyType ));
+                       else
+                               il.Emit(OpCodes.Unbox_Any, piTarget.PropertyType);
                                
-                               il.Emit(OpCodes.Callvirt, piTarget.GetSetMethod());
-                       //}
+                       il.Emit(OpCodes.Callvirt, piTarget.GetSetMethod());
+
                        il.MarkLabel(labFailed);
                        il.Emit(OpCodes.Ret);