system.reflection

Get project name of WPF project [duplicate]

冷暖自知 提交于 2019-12-23 09:12:45
问题 This question already has answers here : Application.ProductName equivalent in WPF? (7 answers) Closed 5 years ago . I'm writing my first WPF application, and I'm trying to get the name of the project so I can output it. However, using Assembly.GetEntryAssembly().GetName() or Assembly.GetExecutingAssembly().GetName() gets me the name as well as the version number(i.e., DataPusher, Version=2.0.466.16967). Is there a way to get ONLY the assembly name? Thanks. 回答1: string name = Assembly

Exception Info: System.Reflection.TargetInvocationException

青春壹個敷衍的年華 提交于 2019-12-23 07:26:18
问题 I am working on a WPF application an I receive this error only at run time on single device. Exception Info: System.Reflection.TargetInvocationException My question: Any clue of what could be cause this error? Any idea how to debug the application in release mode? Exception Info: System.Reflection.TargetInvocationException Stack: at System.RuntimeMethodHandle.InvokeMethod(System.Object, System.Object[], System.Signature, Boolean) at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal

Get List if Properties of type ICollection from Generic Class

六月ゝ 毕业季﹏ 提交于 2019-12-22 08:36:56
问题 I have an object that contains some ICollection type properties So basically the class looks like this: Class Employee { public ICollection<Address> Addresses {get;set;} public ICollection<Performance> Performances {get; set;} } The problem is get property names of type ICollection, inside of Generic class, by using reflection. My Generic Class is Class CRUD<TEntity> { public object Get() { var properties = typeof(TEntity).GetProperties().Where(m=m.GetType() == typeof(ICollection ) ... } But

Generate dynamic object from dictionary with C # Reflection

早过忘川 提交于 2019-12-22 05:41:30
问题 I've been researching a bit about reflections in C # and would like to know if I use a dictionary with keys-values ​​can create an object with the variable with the name of each key in the dictionary and their values​​, the key value of that dictionary. I have a method that does the opposite, that extracts an object from a dictionary, this dictionary contains the keys and the class properties and their values​​, the value of the properties. I wonder how to do this if possible. Below is my

Type.GetProperties() doesn't work in Release

三世轮回 提交于 2019-12-21 05:34:26
问题 I am trying to get the properties of the FontWeights class in C# using reflection. var properties = typeof(FontWeights).GetProperties(); var dialog = new MessageDialog("Number of weights: " + properties.Length); await dialog.ShowAsync(); When built with Debug configuration, the above works as expected. However, when using Release no properties are found. Why is it so? Is there a way around it? It's an UWP app. 回答1: It's an UWP app. In the Release build your app is compiled with .NET Native.

How to emit a Type in .NET Core

穿精又带淫゛_ 提交于 2019-12-20 08:57:53
问题 In C#, how do I emit a new Type at runtime with .NET Core? All of the examples I can find for .NET 6 don't seem to work in .NET core (they all begin with getting the current AppDomain, which doesn't exist in .NET core any more). If possible I would appreciate an example that involves creating a Type and adding a property to the Type. 回答1: Here is SO post about creating a dynamic type in .NET 4. How to dynamically create a class in C#? And in the accepted answer is just one use of AppDomain .

Get Types in assembly (error: System.Reflection.ReflectionTypeLoadException)

非 Y 不嫁゛ 提交于 2019-12-18 19:08:16
问题 I´m receiving an Exception of type "Exception Details: System.Reflection.ReflectionTypeLoadException: Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information." with the following code: public IEnumerable<Type> FindClassesOfType(Type assignTypeFrom, IEnumerable<Assembly> assemblies, bool onlyConcreteClasses = true) { foreach(var a in assemblies) { foreach (var t in a.GetTypes()) I need to Get the Types defined in each assembly but it seems

Load an ASP.NET 2.0 aspx page using System.Reflection?

核能气质少年 提交于 2019-12-17 16:54:15
问题 Can I load an stand alone aspx page in another stand alone aspx page using System.Reflection? I am using the ASP.NET 2.0 Web site project model. 回答1: Try using BuildManager.CreateInstanceFromVirtualPath. Sample usage: Page p = BuildManager.CreateInstanceFromVirtualPath("~/Default.aspx", typeof(Page)) This answers this specific question, although, based on your comments, I'm not sure that this is what you really want. 回答2: Don't know about doing it using Reflection, which may well be possible,

Using reflection to get method name and parameters

天涯浪子 提交于 2019-12-17 09:54:19
问题 I am trying to workout a way to programatically create a key for Memcached, based on the method name and parameters. So if I have a method, string GetName(int param1, int param2); it would return: string key = "GetName(1,2)"; I know you can get the MethodBase using reflection, but how do I get the parameters values in the string, not the parameter types? 回答1: What you're looking for is an interceptor. Like the name says, an interceptor intercepts a method invocation and allows you to perform

Read a method's inner calling method names from 'MethodInfo' Class using reflection

此生再无相见时 提交于 2019-12-13 23:28:53
问题 I was reading all properties and methods from a class using reflection. So i want to identify a method's inner calling methods using reflection. I tried to read MethodBody using 'GetMethodBody()' method. But it is listing only local variables. So could you please help on this? 回答1: You can't get method calls from MethodInfo by reflection. Method calls are just an IL instruction, from the reflection point of view all is just IL . There is no difference between instruction that load argument