我最近創(chuàng)建了通用sql命令生成代碼。一切正常,但我目前正在努力解決的一件事。如何通過給定的屬性名稱獲取實例/ Answer屬性的值?是)我有的:問題實例作為對象(例如myObject)問題的屬性+內(nèi)部道具名稱(字符串)+內(nèi)部類類型[Table("Question")]public class Question{ [Column("QuestionID", true)] public int QuestionId { get; set; } [Column("Number")] public string Nr { get; set; } [Column("CorrectAnswer", typeof(Answer), nameof(Answer.Text))] public Answer CorrectAnswer { get; set; }}[AttributeUsage(AttributeTargets.Property, Inherited = false)]public class ColumnAttribute : DatabaseAttribute{ public bool IsTechnicalId { get; private set; } = false; public string DeepPropName { get; private set; } = null; public Type DeepClass { get; private set; } = null; public bool HasDeepProp { get; private set; } = false; public ColumnAttribute(string name) : base(name) { } /// <summary> /// Creates a deep object property column definition /// </summary> /// <param name="name"></param> /// <param name="deepProperty"></param> public ColumnAttribute(string name, Type deepClass, string deepPropertyName) : base(name) { DeepPropName = deepPropertyName; DeepClass = deepClass; HasDeepProp = true; } public ColumnAttribute(string name, bool isTechnicalId) : this(name) { IsTechnicalId = isTechnicalId; }}我當(dāng)前用于獲取道具和值的代碼如下所示。 一切都可以正常運行,唯一的例外是:如何獲取要搜索的對象內(nèi)另一個對象的屬性值?我可以獲取實例對象屬性的任何實例嗎?Edit1:我可以通過if(pInfo.Name == "CorrectAnswer") answerRef = pInfo.GetValue(obj, null);然后從answerRef角色獲取道具,以獲取給定propName的值
- 1 回答
- 0 關(guān)注
- 160 瀏覽
添加回答
舉報
0/150
提交
取消