第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

從通用對(duì)象列表中讀取通用值

從通用對(duì)象列表中讀取通用值

C#
catspeake 2021-06-04 11:18:51
我正在嘗試遍歷通用對(duì)象調(diào)用列表Condition<T>以讀取通用字段Value。我跟著這個(gè)問題能夠存儲(chǔ)List<Condition<T>>. 我現(xiàn)在遇到的問題是我無法Value在循環(huán)中使用該字段。我需要更改什么才能使用該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 ";    }}條件基礎(chǔ)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 關(guān)注
  • 158 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)