亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

從通用對象列表中讀取通用值

從通用對象列表中讀取通用值

C#
catspeake 2021-06-04 11:18:51
我正在嘗試遍歷通用對象調用列表Condition<T>以讀取通用字段Value。我跟著這個問題能夠存儲List<Condition<T>>. 我現在遇到的問題是我無法Value在循環中使用該字段。我需要更改什么才能使用該Value字段?主要的string url = "";List<ConditionBase> Conditions = new List<ConditionBase>();Conditions.Add(new Condition<int>(Field.Field1, 1, ConditionOperator.Equal))Conditions.Add(new Condition<string>(Field.Field2, "test", ConditionOperator.NotEqual))foreach (ConditionBase c in Conditions){    if (c.GetType() == typeof(string))    {        // c.Value throws an error        url += c.Field + " " + c.ConditionOperator + " '" + c.Value + "' and ";    }    else if (c.GetType() == typeof(DateTime))    {        // c.Value throws an error        url += c.Field + " " + c.ConditionOperator + " " + Helpers.FormatDate(c.Value) + " and ";    }}條件基礎public interface ConditionBase{    Field Field { get; set; }    ConditionOperator ConditionOperator { get; set; }}狀況public class Condition<T> : ConditionBase{    private Field _Field;    private T _Value;    private ConditionOperator _ConditionOperator;    public Condition(Field field, T value, ConditionOperator condition)    {        this._Field = field;        this._Value = value;        this._ConditionOperator = condition;    }    public Field Field    {        get        {            return this._Field;        }        set        {            if (this._Field != value)            {                this._Field = value;            }        }    }    public T Value    {        get        {            return this._Value;        }        set        {            if (!EqualityComparer<T>.Default.Equals(this._Value, value))            {                this._Value = value;            }        }    }    public ConditionOperator ConditionOperator    {        get        {            return this._ConditionOperator;        }        set        {            if (this._ConditionOperator != value)            {                this._ConditionOperator = value;            }        }    }}
查看完整描述

2 回答

  • 2 回答
  • 0 關注
  • 159 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號