繁体   English   中英

C# Reflection GetValue 正在将某些字符替换为?

[英]C# Reflection GetValue is Replacing certain characters with?

使用 .NET 5,我有两个相同的列表 class 列表。 一个是从 SQL 数据库的实体框架生成的,另一个是使用 Oracle 数据库的 Oracles DataManagedAccess 库(如果重要的话)生成的。 此时,根据 VS 调试器显示的内容,有问题的字符串是正确的。

            foreach (var PairedCustomer in PairedCustomers)
            {
                bool MakeProp = false;
                //compare properties we care about (defined in mapping)
                foreach (string prop in PropertiesWeCareAbout)
                {
                    string tProp = PairedCustomer.TargetCustomer.GetType().GetProperty(prop).GetValue(PairedCustomer.TargetCustomer, null).ToString(); 
                    string dProp = PairedCustomer.DCustomer.GetType().GetProperty(prop).GetValue(PairedCustomer.DCustomer, null).ToString();

问题是,在上面的代码中,“PairedCustomer.TargetCustomer”在 object 中有一个字符串值作为“für Fischerei”,但是 tProp 值显示为:“f?r Fischerei”。 它对所有变音符号和类似字符执行此操作,但仅适用于来自 Oracle 的列表。为什么它在列表中显示正确(通过 VS 调试器),但被替换为? 使用反射时(是的......我讨厌使用反射,但目前我没有更好的方法)。

在此处输入图像描述

我终于解决了。 Oracle 响应使用扩展的 Ascii 字符。 解决方案是使用编码转换值:Encoding.GetEncoding(1252).GetString(tProp.Select(c => (byte)c).ToArray());

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM