reflection

Is certain matlab-routine used in matlab script?

浪尽此生 提交于 2021-02-07 13:28:04
问题 I am running a big m-file that I didn't write myself and that depends on certain subfunctions. I want to know if anywhere in all nested functions a particular function (in my case the function eig.m (to calculate eigenvalues) ) is used. Is there a quick way to do this? kind regards, Koen 回答1: You can use the semi-documented function getcallinfo (see Yair Altman's blog for more information about it): getcallinfo Returns called functions and their first and last lines This function is

Is certain matlab-routine used in matlab script?

对着背影说爱祢 提交于 2021-02-07 13:26:58
问题 I am running a big m-file that I didn't write myself and that depends on certain subfunctions. I want to know if anywhere in all nested functions a particular function (in my case the function eig.m (to calculate eigenvalues) ) is used. Is there a quick way to do this? kind regards, Koen 回答1: You can use the semi-documented function getcallinfo (see Yair Altman's blog for more information about it): getcallinfo Returns called functions and their first and last lines This function is

How do you get the name of a generic class using reflection?

半城伤御伤魂 提交于 2021-02-07 09:59:45
问题 How do you get the name of a generic class using reflection eg public class SomeGenericClass<T> { } SomeGenericClass<int> test = new SomeGenericClass<int>(); test.GetType().Name returns "SomeGenericClass'1" How do I get it to return "SomeGenericClass" without the '1? 回答1: How about just the following? test.GetType().Name.Split('\'')[0] It works on non-generic classes too. 回答2: The '1 is part of the name, because, for example, List<T> and List (if I created such a class) are different classes.

How can I programmatically do method overload resolution in C#?

耗尽温柔 提交于 2021-02-07 04:49:20
问题 When the C# compiler interprets a method invocation it must use (static) argument types to determine which overload is actually being invoked. I want to be able to do this programmatically. If I have the name of a method (a string ), the type that declares it (an instance of System.Type ), and a list of argument types I want to be able to call a standard library function and get back a MethodInfo object representing the method the C# compiler would choose to invoke. For instance if I have

Get value of field by string

試著忘記壹切 提交于 2021-02-07 04:46:23
问题 I want to get the value of a field of an object by using a string as variable name. I tried to do this with reflection: myobject.GetType().GetProperty("Propertyname").GetValue(myobject, null); This works perfectly but now I want to get the value of "sub-properties": public class TestClass1 { public string Name { get; set; } public TestClass2 SubProperty = new TestClass2(); } public class TestClass2 { public string Address { get; set; } } Here I want to get the value Address from a object of

TypeScript type definition for an object property path [duplicate]

无人久伴 提交于 2021-02-07 04:27:11
问题 This question already has answers here : Typescript: deep keyof of a nested object (2 answers) Closed 1 year ago . Is it possible to type an array of strings in such a way that the array can only be a valid property path in a given object? The type definition should work for all deeply nested objects. Example: const object1 = { someProperty: true }; const object2 = { nestedObject: object1, anotherProperty: 2 }; type PropertyPath<Type extends object> = [keyof Type, ...Array<string>]; // <--

C# - comparing two .net dlls using reflection

落爺英雄遲暮 提交于 2021-02-07 03:54:22
问题 I want to compare two identical .net dlls which are located at different locations. Hence, I am loading the dlls using System.Reflection.Assembly.LoadFile(filename) instead of System.Reflection.Assembly.LoadFrom(filename) . But the .Net dlls that are to be compared have reference to other assemblies (which are in the same folder as the respective dll). Loading the dll using LoadFile(filename) followed by GetTypes() throws an ReflectionTypeLoadException . How should I load two identical dlls

C# - comparing two .net dlls using reflection

左心房为你撑大大i 提交于 2021-02-07 03:54:09
问题 I want to compare two identical .net dlls which are located at different locations. Hence, I am loading the dlls using System.Reflection.Assembly.LoadFile(filename) instead of System.Reflection.Assembly.LoadFrom(filename) . But the .Net dlls that are to be compared have reference to other assemblies (which are in the same folder as the respective dll). Loading the dll using LoadFile(filename) followed by GetTypes() throws an ReflectionTypeLoadException . How should I load two identical dlls

C# - comparing two .net dlls using reflection

霸气de小男生 提交于 2021-02-07 03:52:49
问题 I want to compare two identical .net dlls which are located at different locations. Hence, I am loading the dlls using System.Reflection.Assembly.LoadFile(filename) instead of System.Reflection.Assembly.LoadFrom(filename) . But the .Net dlls that are to be compared have reference to other assemblies (which are in the same folder as the respective dll). Loading the dll using LoadFile(filename) followed by GetTypes() throws an ReflectionTypeLoadException . How should I load two identical dlls

Generic constructors and reflection

喜夏-厌秋 提交于 2021-02-07 01:57:44
问题 Is it possible to see which constructor was the generic one? internal class Foo<T> { public Foo( T value ) {} public Foo( string value ) {} } var constructors = typeof( Foo<string> ).GetConstructors(); The property 'ContainsGenericParameters' returns me for both constructors false. Is there any way to find out that constructors[0] is the generic one? They both have the same signature, but I would like to call the "real" string one. EDIT: I want to invoke the given type using ilGen.Emit(