热门标签 | 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();

推荐阅读
  • Iamtryingtomakeaclassthatwillreadatextfileofnamesintoanarray,thenreturnthatarra ... [详细]
  • 向QTextEdit拖放文件的方法及实现步骤
    本文介绍了在使用QTextEdit时如何实现拖放文件的功能,包括相关的方法和实现步骤。通过重写dragEnterEvent和dropEvent函数,并结合QMimeData和QUrl等类,可以轻松实现向QTextEdit拖放文件的功能。详细的代码实现和说明可以参考本文提供的示例代码。 ... [详细]
  • 开发笔记:加密&json&StringIO模块&BytesIO模块
    篇首语:本文由编程笔记#小编为大家整理,主要介绍了加密&json&StringIO模块&BytesIO模块相关的知识,希望对你有一定的参考价值。一、加密加密 ... [详细]
  • 本文讨论了一个关于cuowu类的问题,作者在使用cuowu类时遇到了错误提示和使用AdjustmentListener的问题。文章提供了16个解决方案,并给出了两个可能导致错误的原因。 ... [详细]
  • Linux环境变量函数getenv、putenv、setenv和unsetenv详解
    本文详细解释了Linux中的环境变量函数getenv、putenv、setenv和unsetenv的用法和功能。通过使用这些函数,可以获取、设置和删除环境变量的值。同时给出了相应的函数原型、参数说明和返回值。通过示例代码演示了如何使用getenv函数获取环境变量的值,并打印出来。 ... [详细]
  • Android源码深入理解JNI技术的概述和应用
    本文介绍了Android源码中的JNI技术,包括概述和应用。JNI是Java Native Interface的缩写,是一种技术,可以实现Java程序调用Native语言写的函数,以及Native程序调用Java层的函数。在Android平台上,JNI充当了连接Java世界和Native世界的桥梁。本文通过分析Android源码中的相关文件和位置,深入探讨了JNI技术在Android开发中的重要性和应用场景。 ... [详细]
  • 本文介绍了深入浅出Linux设备驱动编程的重要性,以及两种加载和删除Linux内核模块的方法。通过一个内核模块的例子,展示了模块的编译和加载过程,并讨论了模块对内核大小的控制。深入理解Linux设备驱动编程对于开发者来说非常重要。 ... [详细]
  • Android系统源码分析Zygote和SystemServer启动过程详解
    本文详细解析了Android系统源码中Zygote和SystemServer的启动过程。首先介绍了系统framework层启动的内容,帮助理解四大组件的启动和管理过程。接着介绍了AMS、PMS等系统服务的作用和调用方式。然后详细分析了Zygote的启动过程,解释了Zygote在Android启动过程中的决定作用。最后通过时序图展示了整个过程。 ... [详细]
  • 本文主要解析了Open judge C16H问题中涉及到的Magical Balls的快速幂和逆元算法,并给出了问题的解析和解决方法。详细介绍了问题的背景和规则,并给出了相应的算法解析和实现步骤。通过本文的解析,读者可以更好地理解和解决Open judge C16H问题中的Magical Balls部分。 ... [详细]
  • C++字符字符串处理及字符集编码方案
    本文介绍了C++中字符字符串处理的问题,并详细解释了字符集编码方案,包括UNICODE、Windows apps采用的UTF-16编码、ASCII、SBCS和DBCS编码方案。同时说明了ANSI C标准和Windows中的字符/字符串数据类型实现。文章还提到了在编译时需要定义UNICODE宏以支持unicode编码,否则将使用windows code page编译。最后,给出了相关的头文件和数据类型定义。 ... [详细]
  • 本文讨论了在手机移动端如何使用HTML5和JavaScript实现视频上传并压缩视频质量,或者降低手机摄像头拍摄质量的问题。作者指出HTML5和JavaScript无法直接压缩视频,只能通过将视频传送到服务器端由后端进行压缩。对于控制相机拍摄质量,只有使用JAVA编写Android客户端才能实现压缩。此外,作者还解释了在交作业时使用zip格式压缩包导致CSS文件和图片音乐丢失的原因,并提供了解决方法。最后,作者还介绍了一个用于处理图片的类,可以实现图片剪裁处理和生成缩略图的功能。 ... [详细]
  • 本文介绍了如何使用Express App提供静态文件,同时提到了一些不需要使用的文件,如package.json和/.ssh/known_hosts,并解释了为什么app.get('*')无法捕获所有请求以及为什么app.use(express.static(__dirname))可能会提供不需要的文件。 ... [详细]
  • 本文介绍了在iOS开发中使用UITextField实现字符限制的方法,包括利用代理方法和使用BNTextField-Limit库的实现策略。通过这些方法,开发者可以方便地限制UITextField的字符个数和输入规则。 ... [详细]
  • python限制递归次数(python最大公约数递归)
    本文目录一览:1、python为什么要进行递归限制 ... [详细]
  • 本文介绍了如何使用JSONObiect和Gson相关方法实现json数据与kotlin对象的相互转换。首先解释了JSON的概念和数据格式,然后详细介绍了相关API,包括JSONObject和Gson的使用方法。接着讲解了如何将json格式的字符串转换为kotlin对象或List,以及如何将kotlin对象转换为json字符串。最后提到了使用Map封装json对象的特殊情况。文章还对JSON和XML进行了比较,指出了JSON的优势和缺点。 ... [详细]
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社区 版权所有