热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

ASP.NETvNextCoreCLR缺少type.IsPrimitive-ASP.NETvNextCoreCLRmissingtype.IsPrimitive

IamtryingtomigrateawebapptoASP.NetvNextwiththeeventualaimofgettingitrunningonLin

I am trying to migrate a web app to ASP.Net vNext with the eventual aim of getting it running on Linux.

我正在尝试将Web应用程序迁移到ASP.Net vNext,最终目的是让它在Linux上运行。

The app has a lot of reflection code and I must be missing some dependencies as I am getting compile errors on code such as this

该应用程序有很多反射代码,我必须缺少一些依赖项,因为我在代码上遇到编译错误

Type.IsPrimitive, Type.GetConstructor Type.GetMethod Type.GetTypeArray Error CS1061 'Type' does not contain a definition for 'IsPrimitive' and no extension method 'IsPrimitive' accepting a first argument of type 'Type' could be found (are you missing a using directive or an assembly reference?)

Type.IsPrimitive,Type.GetConstructor Type.GetMethod Type.GetTypeArray错误CS1061'Type'不包含'IsPrimitive'的定义,并且没有扩展方法'IsPrimitive'接受类型'Type'的第一个参数可以找到(你是否遗漏了) using指令或程序集引用?)

Error CS1061 'Type' does not contain a definition for 'GetMethod' and no extension method 'GetMethod' accepting a first argument of type 'Type' could be found (are you missing a using directive or an assembly reference?)

错误CS1061'Type'不包含'GetMethod'的定义,并且没有扩展方法'GetMethod'接受类型'Type'的第一个参数(你是否缺少using指令或汇编引用?)

Error CS1061 'Type' does not contain a definition for 'GetProperties' and no extension method 'GetProperties' accepting a first argument of type 'Type' could be found (are you missing a using directive or an assembly reference?)

错误CS1061'Type'不包含'GetProperties'的定义,也没有扩展方法'GetProperties'接受类型'Type'的第一个参数(你是否缺少using指令或汇编引用?)

Error CS1061 'Type' does not contain a definition for 'GetInterface' and no extension method 'GetInterface' accepting a first argument of type 'Type' could be found (are you missing a using directive or an assembly reference?)

错误CS1061'Type'不包含'GetInterface'的定义,也没有扩展方法'GetInterface'接受类型'Type'的第一个参数(你是否缺少using指令或汇编引用?)

I have the following dependencies in my project.json files

我的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"
        }

The following compiles fine under VS 2013 and .Net 4.5 but wont compile in VS 2015 using the dependencies above

以下编译在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();
        }
    }
}

2 个解决方案

#1


21  

If you're using aspnetcore .IsPrimitive is available, but not as a member of Type. You'll find it under TypeInfo, which can be accessed by calling the GetTypeInfo() method of Type. In your example, it would be:

如果您正在使用aspnetcore .IsPrimitive可用,但不是Type的成员。您可以在TypeInfo下找到它,可以通过调用Type的GetTypeInfo()方法来访问它。在您的示例中,它将是:

lStringType.GetTypeInfo().IsPrimitive

Type.GetMethod() is also available, but you'll need to reference the System.Reflection.TypeExtensions package in your project.json file.

Type.GetMethod()也可用,但您需要在project.json文件中引用System.Reflection.TypeExtensions包。

Type.GetTypeArray() is missing, but you can easily write a simple linq query to retrieve an array of member types in the array.

缺少Type.GetTypeArray(),但您可以轻松编写简单的linq查询来检索数组中的成员类型数组。

Type.GetInterface() is not included, but again using System.Reflection.TypeExtensions will expose another method that generates a Type[] of all implemented interfaces for the type specified.

不包括Type.GetInterface(),但是再次使用System.Reflection.TypeExtensions将公开另一个方法,该方法为指定的类型生成所有已实现接口的Type []。

Type[] types = Type.GetInterfaces()

Type.GetProperties() is available again through the System.Reflection.TypeExtensions library.

可以通过System.Reflection.TypeExtensions库再次使用Type.GetProperties()。

#2


1  

You can use the static method System.Reflection.IntrospectionExtensions.GetTypeInfo() to get the same information.

您可以使用静态方法System.Reflection.IntrospectionExtensions.GetTypeInfo()来获取相同的信息。

    var arrayType = typeof(Array);
    var stringType = typeof(string);
    var stringArray = new string[1];
    var stringTypeInfo = stringType.GetTypeInfo();
    if (stringTypeInfo.IsPrimitive)
    {
    }

    ConstructorInfo lCOnstructor= stringTypeInfo.DeclaredConstructors.Where(x => x.GetParameters().Any() == false).FirstOrDefault();
    MethodInfo lMethod = stringTypeInfo.DeclaredMethods.Where(x => x.Name == "Equals").FirstOrDefault();
    Type[] lTArray = stringArray.Where(x => x != null).Select(x => x.GetType()).Distinct().ToArray();
    PropertyInfo[] lProps = stringTypeInfo.DeclaredProperties.ToArray();

推荐阅读
  • 近来有一个需求,是需要在androidjava基础库中插入一些log信息,完成这个工作需要的前置条件有编译好的android源码具体android源码如何编译,这 ... [详细]
  • Spring常用注解(绝对经典),全靠这份Java知识点PDF大全
    本文介绍了Spring常用注解和注入bean的注解,包括@Bean、@Autowired、@Inject等,同时提供了一个Java知识点PDF大全的资源链接。其中详细介绍了ColorFactoryBean的使用,以及@Autowired和@Inject的区别和用法。此外,还提到了@Required属性的配置和使用。 ... [详细]
  • Iamtryingtomakeaclassthatwillreadatextfileofnamesintoanarray,thenreturnthatarra ... [详细]
  • 本文介绍了Redis的基础数据结构string的应用场景,并以面试的形式进行问答讲解,帮助读者更好地理解和应用Redis。同时,描述了一位面试者的心理状态和面试官的行为。 ... [详细]
  • 如何用UE4制作2D游戏文档——计算篇
    篇首语:本文由编程笔记#小编为大家整理,主要介绍了如何用UE4制作2D游戏文档——计算篇相关的知识,希望对你有一定的参考价值。 ... [详细]
  • Android JSON基础,音视频开发进阶指南目录
    Array里面的对象数据是有序的,json字符串最外层是方括号的,方括号:[]解析jsonArray代码try{json字符串最外层是 ... [详细]
  • 本文探讨了C语言中指针的应用与价值,指针在C语言中具有灵活性和可变性,通过指针可以操作系统内存和控制外部I/O端口。文章介绍了指针变量和指针的指向变量的含义和用法,以及判断变量数据类型和指向变量或成员变量的类型的方法。还讨论了指针访问数组元素和下标法数组元素的等价关系,以及指针作为函数参数可以改变主调函数变量的值的特点。此外,文章还提到了指针在动态存储分配、链表创建和相关操作中的应用,以及类成员指针与外部变量的区分方法。通过本文的阐述,读者可以更好地理解和应用C语言中的指针。 ... [详细]
  • 本文介绍了深入浅出Linux设备驱动编程的重要性,以及两种加载和删除Linux内核模块的方法。通过一个内核模块的例子,展示了模块的编译和加载过程,并讨论了模块对内核大小的控制。深入理解Linux设备驱动编程对于开发者来说非常重要。 ... [详细]
  • JDK源码学习之HashTable(附带面试题)的学习笔记
    本文介绍了JDK源码学习之HashTable(附带面试题)的学习笔记,包括HashTable的定义、数据类型、与HashMap的关系和区别。文章提供了干货,并附带了其他相关主题的学习笔记。 ... [详细]
  • 如何查询zone下的表的信息
    本文介绍了如何通过TcaplusDB知识库查询zone下的表的信息。包括请求地址、GET请求参数说明、返回参数说明等内容。通过curl方法发起请求,并提供了请求示例。 ... [详细]
  • 本文介绍了如何使用JSONObiect和Gson相关方法实现json数据与kotlin对象的相互转换。首先解释了JSON的概念和数据格式,然后详细介绍了相关API,包括JSONObject和Gson的使用方法。接着讲解了如何将json格式的字符串转换为kotlin对象或List,以及如何将kotlin对象转换为json字符串。最后提到了使用Map封装json对象的特殊情况。文章还对JSON和XML进行了比较,指出了JSON的优势和缺点。 ... [详细]
  • 向QTextEdit拖放文件的方法及实现步骤
    本文介绍了在使用QTextEdit时如何实现拖放文件的功能,包括相关的方法和实现步骤。通过重写dragEnterEvent和dropEvent函数,并结合QMimeData和QUrl等类,可以轻松实现向QTextEdit拖放文件的功能。详细的代码实现和说明可以参考本文提供的示例代码。 ... [详细]
  • 开发笔记:加密&json&StringIO模块&BytesIO模块
    篇首语:本文由编程笔记#小编为大家整理,主要介绍了加密&json&StringIO模块&BytesIO模块相关的知识,希望对你有一定的参考价值。一、加密加密 ... [详细]
  • android listview OnItemClickListener失效原因
    最近在做listview时发现OnItemClickListener失效的问题,经过查找发现是因为button的原因。不仅listitem中存在button会影响OnItemClickListener事件的失效,还会导致单击后listview每个item的背景改变,使得item中的所有有关焦点的事件都失效。本文给出了一个范例来说明这种情况,并提供了解决方法。 ... [详细]
  • 本文介绍了一个题目的解法,通过二分答案来解决问题,但困难在于如何进行检查。文章提供了一种逃逸方式,通过移动最慢的宿管来锁门时跑到更居中的位置,从而使所有合格的寝室都居中。文章还提到可以分开判断两边的情况,并使用前缀和的方式来求出在任意时刻能够到达宿管即将锁门的寝室的人数。最后,文章提到可以改成O(n)的直接枚举来解决问题。 ... [详细]
author-avatar
革斤Hero_394
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有