草庐IT

Reflection

全部标签

reflection - 如何获取 SQLite 数据库表中列的列表?

我想检索表中的列列表。该数据库是最新版本的SQLite(我相信是3.6)。我正在寻找使用SQL查询执行此操作的代码。与列相关的元数据(例如长度、数据类型等...)的额外加分 最佳答案 您要查找的内容称为数据字典。在sqlite中,可以通过查询sqlite_master表(或View?)找到所有表的列表sqlite>createtablepeople(first_namevarchar,last_namevarchar,email_addressvarchar);sqlite>select*fromsqlite_master;tabl

c# - System.Reflection.Missing.Value 有什么作用?

我遇到了下面给出的代码ObjectoMissing=System.Reflection.Missing.ValueoDataDoc=wrdApp.Documents.Open(refoName,refoMissing,refoMissing,refoMissing,refoMissing,refoMissing,refoMissing,refoMissing,refoMissing,refoMissing,refoMissing,refoMissing,refoMissing,refoMissing,refoMissing);我不明白refoMissing会做什么。它会自动获取值或类似

c# - 对类型约束的反射(reflection)

在类和方法定义中,可以添加类型约束,例如whereT:IFoo。是否可以使用System.Type或MethodInfo反射(reflect)这些约束?到目前为止我还没有发现任何东西;任何帮助将不胜感激。 最佳答案 您可以遍历类型的泛型参数,并且对于每个参数,您可以询问约束类型。您可以使用:Type.GetGenericArguments的Type找到类型的通用参数,即。Type,你会发现T.Type.GetGenericParameterConstraints为您提供每个此类参数受约束的基本类型,您可以根据从上述方法中找到的参数调

c# Reflection - 查找集合的通用类型

我反射(reflect)了一个属性“Blah”,它的类型是ICollectionpublicICollectionBlah{get;set;}privatevoidbutton1_Click(objectsender,RoutedEventArgse){varpi=GetType().GetProperty("Blah");MessageBox.Show(pi.PropertyType.ToString());}这给了我(如你所料!)ICollection...但我真的想获得集合类型,即ICollection(而不是ICollection)-请问有人知道我该怎么做吗?

c# - System.Reflection GetProperties 方法不返回值

有人可以向我解释一下,如果按如下方式设置类,为什么GetProperties方法不会返回公共(public)值。publicclassDocumentA{publicstringAgencyNumber=string.Empty;publicboolDescription;publicboolEstablishment;}我正在尝试设置一个简单的单元测试方法来尝试该方法如下,它具有所有适当的using语句和引用。我所做的只是调用以下但它返回0PropertyInfo[]pi=target.GetProperties(BindingFlags.Public|BindingFlags.In

c# - 如何在 C# 中使用 System.Reflection.MethodBase 查找方法的返回类型?

如何从MethodBase中找出方法的返回类型?我正在使用PostSharp并尝试覆盖CompileTimeValidate(MethodBase方法)方法以确保该属性应用于具有正确签名的方法。谢谢, 最佳答案 MethodBase用作MethodInfo的基类它有一个属性ReturnType.您可以尝试转换为MethodInfo的实例并检查该属性。 关于c#-如何在C#中使用System.Reflection.MethodBase查找方法的返回类型?,我们在StackOverflow上

c# - 通过 System.Reflection 访问内部成员?

我正在尝试对具有许多内部函数的类进行单元测试。这些显然也需要测试,但我的测试项目是独立的,主要是因为它涵盖了许多小的相关项目。到目前为止我所拥有的是:FieldInfo[]_fields=typeof(ButtonedForm.TitleButton).GetFields(BindingFlags.NonPublic|BindingFlags.Instance|BindingFlags.DeclaredOnly);Console.WriteLine("{0}fields:",_fields.Length);foreach(FieldInfofiin_fields){Console.Wr

c# - 如何使用 reflection.emit 发出显式接口(interface)实现?

观察以下简单的源代码:usingSystem;usingSystem.Linq.Expressions;usingSystem.Reflection;usingSystem.Reflection.Emit;namespaceA{publicstaticclassProgram{privateconstMethodAttributesExplicitImplementation=MethodAttributes.Private|MethodAttributes.Virtual|MethodAttributes.Final|MethodAttributes.HideBySig|Method

c# - 命令绑定(bind)无法将类型为 'System.Reflection.RuntimeEventInfo' 的对象转换为类型 'System.Reflection.MethodInfo'

当我通过XAML将按钮连接到命令时,出现运行时错误System.Windows.Markup.XamlParseException:在“System.Windows.Data.Binding”上提供值引发异常。--->System.InvalidCastException:无法将“System.Reflection.RuntimeEventInfo”类型的对象转换为类型“System.Reflection.MethodInfo”。当我删除XAML中的命令绑定(bind)时,一切正常,我的项目显示等。这是命令绑定(bind):Click="{BindingElementName=Main

c# - 使用 System.Reflection 获取方法的全名

我有一个如下所示的类:publicclassMyClass{...protectedvoidMyMethod(){...stringmyName=System.Reflection.MethodBase.GetCurrentMethod.Name;...}...}myName的值为“MyMethod”。有没有一种方法可以使用反射为myName获取“MyClass.MyMethod”的值? 最佳答案 您可以查看从GetCurrentMethod获得的MethodBase的ReflectedType,即,MethodBasemethod