小编LbI*_*ISS的帖子

如何将字典参数传递给web-api方法?

我在这里读过所有类似的问题,但我无法提出解决方案.我正在尝试调用web-api方法:

[HttpGet]
public SearchViewModel Get(SearchTypes type, string text, [FromUri]Dictionary<string, string> toyParams)
{
    //Code here
}
Run Code Online (Sandbox Code Playgroud)

我想从uri获取最后一个参数.我试过了

HTTP://本地主机:?39101 /#/搜索/玩具/狐someParameter = 123

HTTP://本地主机:?39101 /#/搜索/玩具/狐toyParams [0].重点= someParameter&toyParams [0].价值= 123

但toyParams Dictionary总是空着.

c# asp.net asp.net-web-api

6
推荐指数
1
解决办法
4564
查看次数

如何自动创建属性?

我有一个"设置"类,它具有一些可用性属性和限制set访问器.我有10个项目似乎很容易,但随后他们的数量增加了.我需要一些方法来自动创建这些属性,类似于:

foreach(var property in SettingsList)
{
    _settings.AddAutoProperty(property);
}
Run Code Online (Sandbox Code Playgroud)

它可能涉及反思,但我无法得到有效的解决方案.

属性定义:

public bool cbNextExcCount
{
    get { return (bool)this.GetValueById("cbNextExcCount"); }
}

public bool cbSaveOnChangeExc
{
    get { return (bool)this.GetValueById("cbSaveOnChangeExc"); }
}

public bool cbAutoIncrement
{
    get { return (bool)this.GetValueById("cbAutoIncrement"); }
}

public bool cbRememberOnExit
{
    get { return (bool)this.GetValueById("cbRememberOnExit"); }
}

...etc.
Run Code Online (Sandbox Code Playgroud)

更新 总结一下,我写了下一个代码:

public IDictionary<string, object> Properties = new ExpandoObject();
private List<string> SettingsList = new List<string> 
{ 
    "cbNextExcCount",
    "cbSaveOnChangeExc",
    "cbAutoIncrement",
    "cbRememberOnExit"
};

public void CreateProperties()
{
    foreach (string SettingName in …
Run Code Online (Sandbox Code Playgroud)

.net c# reflection properties

5
推荐指数
1
解决办法
331
查看次数

标签 统计

c# ×2

.net ×1

asp.net ×1

asp.net-web-api ×1

properties ×1

reflection ×1