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

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

想要使Func <UnknownType,bool>其中UnknownType僅在運(yùn)行時(shí)已知

想要使Func <UnknownType,bool>其中UnknownType僅在運(yùn)行時(shí)已知

C#
素胚勾勒不出你 2021-04-29 14:10:45
因此,我正在嘗試使用atm表達(dá)式。得到以下代碼:除以下幾點(diǎn)外,代碼工作正常:我需要用ForeignKeyProperty.PropertyType替換ViewModel類型,該類僅在運(yùn)行時(shí)在var condition = Expression.Lambda < Func < ViewModel, bool> >預(yù)期的最終結(jié)果:ForeignKeyProperty.SetValue(model, repository.GetList  <ForeignKeyProperty.PropertyType >().Single(x => x.Id == model.Id));protected List < Action < IVenturaRepository, ViewModel>> SetForeignKeyProperties<ViewModel>() where ViewModel : BaseViewModel        {            var viewModelType = typeof(ViewModel);            var foreignKeyProperties = viewModelType.GetProperties().Where(x => x.PropertyType.IsSubclassOf(typeof(BaseViewModel)));            var actions = new List < Action < IVenturaRepository, ViewModel>>();            var repositoryType = typeof(IVenturaRepository);            foreach(var ForeignKeyProperty in foreignKeyProperties)            {                var foreignKeyIdProperty = viewModelType.GetProperties().SingleOrDefault(x => x.Name == ForeignKeyProperty.Name + "Id");                //ForeignKeyProperty.SetValue(model, repository.GetList<ViewModel>().Single(x => x.Id == model.Id));                var listMethod = repositoryType.GetMethods().SingleOrDefault(x => x.Name == "GetList").MakeGenericMethod(ForeignKeyProperty.PropertyType);                //Expression.Call(singleMethod,);                var repositoryVariable = Expression.Parameter(repositoryType, "repository");                var paramViewModelType = Expression.Parameter(viewModelType, "model");                var paramForeignEntityId = Expression.Property(paramViewModelType, "Id");                var listMethodCall = Expression.Call(repositoryVariable, listMethod);                var modelParameter = Expression.Parameter(ForeignKeyProperty.PropertyType, "x");                var foreignKeyTypeConstant = Expression.Constant(ForeignKeyProperty.PropertyType);                       ),                        modelParameter                    );            }            return actions;        }有人可以指出我正確的方向嗎?
查看完整描述

2 回答

?
叮當(dāng)貓咪

TA貢獻(xiàn)1776條經(jīng)驗(yàn) 獲得超12個(gè)贊

使用Object作為類型。那么您可以在運(yùn)行時(shí)以及在將類型強(qiáng)制轉(zhuǎn)換為正確類型之后通過(guò)getType()檢查類型。或使用動(dòng)態(tài)以避免投射。


查看完整回答
反對(duì) 回復(fù) 2021-05-08
  • 2 回答
  • 0 關(guān)注
  • 146 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號(hào)

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