我有一个List<dynamic>,我需要将列表的值和类型传递给服务.服务代码是这样的:
Type type = typeof(IList<>);
// Type genericType = how to get type of list. Such as List<**string**>, List<**dynamic**>, List<**CustomClass**>
// Then I convert data value of list to specified type.
IList data = (IList)JsonConvert.DeserializeObject(this._dataSourceValues[i], genericType);
Run Code Online (Sandbox Code Playgroud)
_dataSourceValues:列表中的值
如果List的类型是dynamic(List<dynamic>),我如何将列表的类型转换为特定类型?
我正在关注https://learn.microsoft.com/en-us/sql/linux/sql-server-linux-configure-docker?view=sql-server-2017在 macos 中配置和运行独立的 sqlserver 容器数据成功。现在我想创建一个 docker-compose 文件,其中包含两件事:
我如何实现(2)?
我的 docker-compose 文件:
version: "3"
services:
web:
build:
context: ./webapi
dockerfile: Dockerfile
ports:
- "4010:80"
environment:
- ASPNETCORE_ENVIRONMENT=Development
depends_on:
- db
db:
image: "mcr.microsoft.com/mssql/server:2017-latest"
ports:
- "4009:1433"
volumes:
- "sqlvolume:/var/opt/mssql"
environment:
SA_PASSWORD: "<password>"
ACCEPT_EULA: "Y"
redis:
image: "redis:alpine"
volumes:
sqlvolume:
Run Code Online (Sandbox Code Playgroud) 我搜索谷歌但结果却是误会.
这是一个代码流程:
public class Store
{
public dynamic GetList(List<string> propertyFields)
{
// Body here
// for in list propertyFields. Such as: ["Code", "Name", "Address", ...]
// dynamic result = ...
// result.Code = "value", result.Name = "abc", result.Address = "homeless", result.... = "..."
// return result
}
}
Run Code Online (Sandbox Code Playgroud)
方法返回一个动态对象.
propertyFields是字段名称列表.当我在列表中传递4个字符串时,dynamic有4个属性字段值(稍后).
当我调用这个方法时:
Store store = new Store();
var rs = store.GetList(["Code","Name","Address"])
Console.WriteLine(rs[0].Code)
Run Code Online (Sandbox Code Playgroud)
这是我的观点.
我的问题:是否有可能在C#中做到这一点?
我有 IList<customClass>
我的 CustomClass: CreatedDate(DateTime), Name(string), Number(int)
我用 OrderBy(p => p.CreatedDate)
我的问题:我如何定制或找到一种方式只订购CreatedDate日期,不包括订单时间?