ICode9

精准搜索请尝试: 精确搜索
  • c#-使用ModuleBuilder将类标记为“内部静态”2019-10-29 10:07:50

    我正在使用Reflection.Emit生成动态程序集,并且一切正常,但是由于以下代码,生成的类被标记为内部密封: var typeBuilder = moduleBuilder.DefineType("MyNamespace.Program", TypeAttributes.Class | TypeAttributes.Sealed); 我看不到任何暗示静态的TypeAttributes成员.这似乎不

  • CodeGo.net>使用另一个类实例访问一个类方法?2019-10-29 06:06:06

    我需要动态调用一个类并使用该类的方法. public class A { public void test() { } } public Class B { public void test() { } } class object intermediate { //here will decide which class to be invoked //return the invoked class instance } class client

  • c#-通过反射通过自定义属性对实体进行Linq排序2019-10-29 06:05:15

    获得了具有Country属性和String属性Name的Customer类. 客户还实现IComparable< Country>.像这样: public int CompareTo(Country other) { return string.Compare(this.Name, other.Name); } 现在: var custList = new List<Customer>{...}; custList.OrderBy(cust => cust.

  • java-将MethodHandles.publicLookup()与Method.setAccessible(true)组合2019-10-29 05:01:10

    我知道publicLookup()比public方法的lookup()更快,我想利用它.如果我要在非固有公共方法但已调用setAccessible(true)的方法上使用MethodHandles.publicLookup().unreflect(Method),它将起作用吗?解决方法:由于每个人都可以调用成功调用setAccessible(true)的Method,因此可以像其他

  • c#-获取实现类型的具体属性2019-10-29 01:08:33

    鉴于以下课程 public Foo { public Foo() { this.Bar = new Bar(); } public IBar Bar{ get; set;} } public Bar : IBar { // implemented properties } 如何使用反射获得Foo属性Bar的具体实现? instance.GetType().GetProperty("Bar").PropertyType 仅产生接口

  • 是否可以通过标识(即==)比较Java方法对象,还是必须使用equals()?2019-10-28 18:11:18

    在Java中,可以通过标识(即==)比较java.lang.reflect.Method对象的实例,还是必须使用equals()?解决方法:这个问题通常不涉及==和equals之间的区别,而是特别涉及java.lang.reflect.Method实例. 这是一个合理的问题,因为可以合理地假设每个Method仅存在一个实例-与Class对象类似,它们在

  • c#-以编程方式获取强制转换和输出运算符的类型2019-10-28 10:07:15

    在C#中,给定两个输入类型,是否可以为运算符确定输出类型和隐式向上转换类型?例如,考虑表达式s i.说我有以下信息: short s; int i; Type leftType = typeof(short); Type rightType = typeof(int); 我可以确定有关表达式s i的以下信息吗? Type leftUpcastType = typeof(int); Type

  • Java Reflections’NoClassDef’错误2019-10-28 07:12:57

    我正在尝试浏览所有使用自定义库反射实现了接口的类.这是我的资料来源: public static List<IModdable> getAllModClasses() { Reflections reflections = new Reflections("mod.api.core"); //getting error here Set<Class<? extends IModdable>> classes = reflection

  • java-是否可以通过编程方式关闭Android设备上的USB存储设备?2019-10-28 06:00:44

    我试图一遍又一遍地搜索,并感到困惑,我们是否可以控制USB存储而无需植根电话,如果可以的话?我尝试了以下方法来启用和禁用权限,但全部无效: StorageManager storage = (StorageManager)getApplicationContext().getSystemService(STORAGE_SERVICE); Method method = storage.getCla

  • 在Java中,此类类将编译为什么?2019-10-28 05:00:11

    下面是定义类类型的代码: package annotationtype; public class Example { public static void main(String[] args){ } } 由javac从功能上编译为: public class annotationtype.Example{ public static Class<annotationtype.Example> class; { cla

  • 格式化获取属性ToString2019-10-28 02:09:08

    使用反射,我可以对属性执行ToString.但是有没有办法在执行此操作时提供格式? public static object GetCustomValue(object src, string propName) { return src.GetType().GetMethod(propName).GetValue(src, null); } 像这样调用函数可以正常工作 GetCustomValue(obj, "ToS

  • 获取List中元素的类型,其中List是Java中方法的返回类型2019-10-28 02:03:36

    我使用反射将包中的每个方法都获取了,然后根据每个方法的返回类型,我想执行一些操作. 但不幸的是,我在收藏方面遇到了问题.当我找到一种方法来返回诸如List之类的集合时,我找不到找到有关List元素类型的方法.我使用下面的代码来获取方法的返回类型. if (method.getReturnType().eq

  • 在Java 8中更改字段注释的注释值2019-10-28 01:01:17

    我认为标题说明了问题.这是一些代码: import static org.junit.Assert.assertEquals; import java.lang.annotation.*; public class Main { public static void main(String[] args) throws Exception { assertEquals("foo", Main.class.getDeclaredMethod("myM

  • 在C#中从一堆ICollection创建一个IEnumerable2019-10-28 00:05:31

    我有一个由许多类似的集合组成的类: public virtual ICollection<C> CStuff { get; set; } public virtual ICollection<D> DStuff { get; set; } public virtual ICollection<E> EStuff { get; set; } 每种类型都实现一个公共接口. public class C : IStuff {} public class D :

  • c#-使用EntityFramework和.NET Native时出现PlatformNotSupportedException2019-10-27 17:05:03

    我有一个UWP(Windows 10)应用程序,可以在调试模式下完美运行(禁用.NET Native). 当我在发布模式下运行它时(或在带有.NET Native编译的调试模式下,我在返回context.Set().ToList();行上收到错误. public IEnumerable<TMobileEntity> ReadAll() { using (var conte

  • (通过反射)检测C#中Enum是否为“标志”类型的策略2019-10-27 16:04:44

    我正在使用反射来读取程序集中的类型(以生成代码).我可以看到应该使用[Flags]属性标记了一些枚举,但是写这些枚举的人忘记了添加此属性. 有没有可靠的方法来检测何时可以将枚举视为“标记”枚举? 目前,我的策略是按降序读取枚举,并检查element(last -1)* 2 == element(last)的值. 在

  • 反射用列表c#修剪列表中的所有字符串2019-10-27 06:08:06

    我有一个修剪所有字符串的方法. public static IEnumerable<T> Trim<T>(this IEnumerable<T> collection) { foreach (var item in collection) { var stringProperties = item.GetType().GetProperties() .Where(p => p.PropertyT

  • 编译器如何从LAMBDA表达式推断委托类型?2019-10-26 23:05:43

    样本代码 int id = 123; ThreadPool.QueueUserWorkItem(state => ThreadEntryPoint((int)state), id); public void ThreadEntryPoint(int uniqueId) { Console.WriteLine("uniqueId=" + uniqueId); } 题 从提供的LAMBDA表达式中,编译器如何知道需要创建QueueUserWorkItem(W

  • 如果通过类java.lang.reflect.Field的’set’方法设置了值,那么它在并发性方面是否具有可见性?2019-10-26 18:00:41

    在此方法的Java文档中,未提及并发性,因此’set’方法似乎不能确保可见性.我对此不确定. 实际上,由于这个问题,我遇到了困难.我将基于Zookeeper构建一个分布式配置平台.像其他配置平台一样,如果字段由特定注释注释,则该平台会将其映射到Zookeeper中的节点.更改映射节点的值后,动物园

  • c#-确定字段是否使用通用参数2019-10-26 16:09:49

    我对此感到困惑,似乎无法绕开它,所以希望有人能指出我正确的方向. 我的课如下: public class Foo<T> { public List<T> Data; } 现在,我正在编写代码以反映此类,并希望找到一种确定字段Data是否具有通用参数的方法. 我最初的方法是继续尽可能降低级别,一旦将IsGenericParamete

  • (C#.Net Core)使用反射从外部程序集实例化类2019-10-26 14:05:04

    我目前正在尝试开发一种在外部项目中使用反射以编程方式运行测试类的方法.这是应该显示我的问题的简化代码块. string pathToDLL = @"C:\Path\To\Test\Project\UnitTests.dll"; IEnumerable<Type> testClasses = assembly.GetExportedTypes(); Type testClass = testClasses.First

  • C#-Enum参数的DefaultValue和RawDefaultValue的意外差异2019-10-26 13:06:03

    考虑以下示例: class Program { static void Main(string[] args) { foreach(var par in typeof(A).GetMethod("Method").GetParameters()) { Console.WriteLine("Def {0}, RawDef {1}", par.DefaultValu

  • 反射使HashCode不稳定2019-10-26 05:05:29

    在以下代码中,访问SomeClass的自定义属性将导致SomeAttribute的哈希函数变得不稳定. 这是怎么回事? static void Main(string[] args) { typeof(SomeClass).GetCustomAttributes(false);//without this line, GetHashCode behaves as expected SomeAttribute tt = new Som

  • 为什么我无法从已加载的Java类中检测注释?2019-10-26 05:02:11

    我有一个插件,我想从我的maven项目中访问模型包的类列表.到目前为止,我只是这样做将类加载到插件中: try { runtimeClasspathElements = project.getRuntimeClasspathElements(); } catch (DependencyResolutionRequiredException e) { // TODO A

  • c#-.NET Core中的MethodInfo ReflectedType2019-10-26 03:05:25

    如何替换.NET Core中的MethodInfo.ReflectedType? 在.NET Core 1.1中,MethodInfo.ReflectedType仍然不可用. 有什么选择?解决方法:有一个整洁的网站APIsOf.Net,您可以在其中找到有关.Net世界中类的完整信息. 到目前为止,抽象属性MemberInfo.ReflectedType仅在.Net Standard的2.0版本

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有