开发者

Type.GetProperty retunring null, when i expect it to return a valid column PropertyINfo

开发者 https://www.devze.com 2023-01-20 00:40 出处:网络
Here is the code I\'m calling PropertyInfo targetColumn; targetColumn = targetType.GetProperty(\"CtrId\");

Here is the code I'm calling

        PropertyInfo targetColumn;
        targetColumn = targetType.GetProperty("CtrId");

Here is the Class

using System;
using System.Runtime.Serialization;
using System.Xml.Serialization;

namespace JCDCHelper.CV
{
    [DataContract, Serializable]
    public class CenterAllActiveCV
    {
        [DataMember]
        [XmlElement( DataType = "long" )]
        public Int64 CtrId { get; set; }

        [DataMember]
        [XmlElement( DataType = "string", IsNullable = true )]
        public string Name { get; set; }

    }
}

I'm expecting targetColumn to be a valid PropertyInfo, but I'm getting null.

Am I missing something obvious?

Thanks,

Eric-开发者_开发知识库


I was able to run your code just fine. How are you getting a Type reference?

Type targetType = typeof(CenterAllActiveCV);
var property = targetType.GetProperty("CtrId");

This worked for me...


Weird,

I recreated the CV file from scratch, and it works perfectly now. I guess I'll chalk it up to "invisible characters" in the CV...

Always leaves me wtih an unsettled feeling. :)

Cal-

0

精彩评论

暂无评论...
验证码 换一张
取 消