ASP.NET vNext Core CLR缺少type.IsPrimitive
我正在尝试将一个网络应用程序迁移到ASP.Net vNext,最终的目的是让它在
Linux上运行.
该应用程序有很多反射代码,我必须缺少一些依赖关系,因为我正在得到如此代码的编译错误
我的project.json文件中有以下依赖关系 "frameworks" : { "aspnetcore50" : { "dependencies": { "System.Runtime": "4.0.20-beta-22416","System.Linq": "4.0.0.0-beta-22605","System.Reflection": "4.0.10.0-beta-22605","System.Reflection.Primitives": "4.0.0.0-beta-22605","System.Runtime.Extensions": "4.0.10.0-beta-22605","System.Reflection.Extensions": "4.0.0.0-beta-22605" } 以下编译在VS 2013和.Net 4.5下,但不会在VS 2015中使用上述依赖项进行编译 using System; using System.Reflection; namespace Project1 { public class Class1 { public Class1() { Type lBaseArrayType = typeof(Array); Type lStringType = typeof(string); string[] lStringArray = new string[1]; if (lStringType.IsPrimitive) { } ConstructorInfo lConstructor = lStringType.GetConstructor(new Type[0]); MethodInfo lMethod = lStringType.GetMethod("Equals"); Type[] lTArray = Type.GetTypeArray(lStringArray); PropertyInfo[] lProps = lStringType.GetProperties(); } } } 解决方法
如果您使用的是aspnetcore .IsPrimitive可用,但不是Type的成员.您可以在TypeInfo下找到它,可以通过调用Type的GetTypeInfo()方法来访问它.在你的例子中,它将是:
lStringType.GetTypeInfo().IsPrimitive Type.GetMethod()也可用,但您需要在project.json文件中引用System.Reflection.TypeExtensions包. Type.GetTypeArray()缺少,但您可以轻松地编写一个简单的linq查询来检索数组中的成员类型数组. Type.GetInterface()不包括在内,但是再次使用System.Reflection.TypeExtensions将会公开另一种为指定类型生成所有实现的接口的Type []的方法. Type[] types = Type.GetInterfaces() Type.GetProperties()可以通过System.Reflection.TypeExtensions库再次可用. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
- ASP.NET WebMethod返回包含在引号中的JSON
- asp.net – 由TaskScheduler和SynchronizationContext混淆同
- asp.net – 自动完成扩展程序 – 滚动条导致结果关闭?
- 使用ASP.NET 5中的默认DI容器一次注册所有服务,类似于Autof
- asp.net-membership – MiniProfiler和SqlMembershipProvid
- asp.net-mvc – 在自定义HTML帮助器中调用Html.ActionLink
- asp.net-mvc – 使用缓存配置文件缓存ChildActions将不起作
- asp.net-mvc – 具有指定操作的Response.RedirectToRoute
- asp.net-mvc-3 – ViewBag/ViewData生命周期
- asp.net-mvc – Html.HiddenFor值属性未设置
- asp.net – 无法在ASP应用程序中调试某些aspx页面
- asp.net-mvc – 在没有EF的情况下在appsettings.
- 权限管理之ASP.NET Forms身份认证
- 如何在Asp.Net Mvc中进行Basecamp风格的账户?
- asp.net-mvc – 如何在RegularExpression中忽略大
- 运行SonarQube针对ASP.Net核心解决方案/项目
- asp.net-mvc-3 – MVC 3不显眼的验证 – 有条件地
- asp.net-mvc-3 – 具有角色的AuthorizeAttribute
- asp.net-mvc – 查找单元测试方向,显示部分视图的
- .net – SignalR长轮询在5秒内断开连接