From 22236251cb6a7df286d8787895da670bd49b9aeb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=8F=E7=BA=A2=E5=B8=BD?= <761716178@qq.com> Date: Tue, 26 Dec 2023 15:42:00 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B0=83=E6=95=B4=E7=BB=91=E5=AE=9A=E5=8F=82?= =?UTF-8?q?=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CPF/AttachedProperties.cs | 4 ++++ CPF/BindingDescribe.cs | 13 +++++++++++++ CPF/CpfObject.cs | 4 ++++ CPF/Json/Reflection.cs | 3 ++- 4 files changed, 23 insertions(+), 1 deletion(-) diff --git a/CPF/AttachedProperties.cs b/CPF/AttachedProperties.cs index d990c57..7c7cf95 100644 --- a/CPF/AttachedProperties.cs +++ b/CPF/AttachedProperties.cs @@ -308,6 +308,10 @@ namespace CPF { Value = value; } + public AttachedDescribe(object value, Func find, string sourceProperty, BindingMode binding, Func convert, Func convertBack, Action SourceToTargetError, Action TargetToSourceError) : base(find, sourceProperty, binding, convert, convertBack, SourceToTargetError, TargetToSourceError) + { + Value = value; + } public object Value { get; set; } diff --git a/CPF/BindingDescribe.cs b/CPF/BindingDescribe.cs index fd81865..8f76f2d 100644 --- a/CPF/BindingDescribe.cs +++ b/CPF/BindingDescribe.cs @@ -108,6 +108,18 @@ namespace CPF this.TargetToSourceError = TargetToSourceError; } + public BindingDescribe(Func find, string sourcePropertyName, BindingMode bindingMode = BindingMode.OneWay, Func convert = null, Func convertBack = null, Action SourceToTargetError = null, Action TargetToSourceError = null) + { + BindingMode = bindingMode; + PropertyName = sourcePropertyName; + Source = find; + //Find = find; + Convert = convert; + ConvertBack = convertBack; + this.SourceToTargetError = SourceToTargetError; + this.TargetToSourceError = TargetToSourceError; + } + //public BindingDescribe(CommandDescribe command) //{ // Command = command; @@ -388,6 +400,7 @@ namespace CPF //} public BindingMode BindingMode { get; set; } = BindingMode.OneWay; public object Source { get; set; } + //public Func Find { get; set; } public Action SourceToTargetError { get; set; } public Action TargetToSourceError { get; set; } diff --git a/CPF/CpfObject.cs b/CPF/CpfObject.cs index 121e386..c8f1010 100644 --- a/CPF/CpfObject.cs +++ b/CPF/CpfObject.cs @@ -223,6 +223,10 @@ namespace CPF { Bindings.Add(propertyName, value.PropertyName, layer1, value.BindingMode, value.Convert, value.ConvertBack, value.SourceToTargetError, value.TargetToSourceError); } + else if (value.Source is Func find) + { + Bindings.Add(propertyName, value.PropertyName, find, value.BindingMode, value.Convert, value.ConvertBack, value.SourceToTargetError, value.TargetToSourceError); + } else { Bindings.Add(propertyName, value.PropertyName, value.Source, value.BindingMode, value.Convert, value.ConvertBack, value.SourceToTargetError, value.TargetToSourceError); diff --git a/CPF/Json/Reflection.cs b/CPF/Json/Reflection.cs index cae568b..0ddda5d 100644 --- a/CPF/Json/Reflection.cs +++ b/CPF/Json/Reflection.cs @@ -644,10 +644,11 @@ namespace CPF.Json class ILGenerator { static Type type = Type.GetType("System.Reflection.Emit.ILGenerator"); + static Type LocalBuilder = Type.GetType("System.Reflection.Emit.LocalBuilder"); static MethodInfo Emit_ = type.GetMethod("Emit", new Type[] { typeof(OpCode) }); static MethodInfo Emit_Type = type.GetMethod("Emit", new Type[] { typeof(OpCode), typeof(Type) }); static MethodInfo Emit_con = type.GetMethod("Emit", new Type[] { typeof(OpCode), typeof(ConstructorInfo) }); - static MethodInfo Emit_Local = type.GetMethod("Emit", new Type[] { typeof(OpCode), typeof(LocalVariableInfo) }); + static MethodInfo Emit_Local = type.GetMethod("Emit", new Type[] { typeof(OpCode), LocalBuilder }); static MethodInfo Emit_FieldInfo = type.GetMethod("Emit", new Type[] { typeof(OpCode), typeof(FieldInfo) }); static MethodInfo Emit_MethodInfo = type.GetMethod("Emit", new Type[] { typeof(OpCode), typeof(MethodInfo) }); static MethodInfo Emit_MethodInfo_Type = type.GetMethod("EmitCall", new Type[] { typeof(OpCode), typeof(MethodInfo), typeof(Type[]) });