Questions tagged [system.reflection]

System.Reflection is a namespace of the .NET framework. It contains types that retrieve information about assemblies, modules, members, parameters, and other entities in managed code by examining their metadata.

System.Reflection is a namespace of the .NET framework. It contains types that retrieve information about assemblies, modules, members, parameters, and other entities in managed code by examining their metadata.

References

1116 questions
-1
votes
1 answer

convert object from one assembly to another cli c++

I have an multi Module Project. Here we are passing System::Object^ from one exe to code from another DLL. When I am trying to convert that Object to its type(Here we have the same definition) in DLL, I am getting the below error... [A] can not be…
-1
votes
2 answers

How to call Count on a bunch of ISet properties where T varies

I have a class with a bunch of properties of type ISet, where T varies from property to property. I'd like to iterate over an object's properties, find the ones that are some sort of ISet and call Count on each of them. Thanks.
Michael
  • 1,351
  • 1
  • 11
  • 25
-1
votes
2 answers

How can I get class name of a child from main caller class

I have five classes class Program { static void Main(string[] args) { Abstract test = new Child(); test.Exectue(); } } public abstract class Abstract { public void Exectue() { IStrategy strategy = new…
Kacper S.
  • 51
  • 1
  • 6
-1
votes
1 answer

Casting ExpandoObject to AnonymousType of T

Im trying to clone an AnonymousType and enconter some strange behavior. could anyone tell me why and also tell me a solution. Here is a test code. public static T DeepClone(this T objectToBeCloned) where T : class { // this…
Alen.Toma
  • 4,684
  • 2
  • 14
  • 31
-1
votes
1 answer

C# identify only collection like datatypes by using reflection

I am using C# .Net 4.7.2 I want to analyse a type by using reflection. One part of the analysing is to identify the properties which are of any kind of collection. Such as Collection, List, Array, IEnumerable, etc. I thought it would be easy and…
GeorgeDuke
  • 151
  • 15
-1
votes
3 answers

Accessing a parent instance's properties?

Lets say I have a few classes that looks a bit like these: This class I'll call the parent instance: public class Foo : Disposable { public Foo() { Bars = new List(); FullPath = string.empty; } public Foo(string…
Robert Smith
  • 309
  • 3
  • 10
-1
votes
1 answer

typeof().GetFields doesnt show List

I am trying to go through my class, but I am unable to list everything. I have class: public class Order { public string PO_NO { get; set; } public string APPROVED_DATE { get; set; } public string SPPLR_CONTACT { get; set; }…
Tomáš Filip
  • 727
  • 3
  • 6
  • 23
-1
votes
2 answers

C# Clear the private list data from Nunit testcase (newbie)

I want to set the default values to variables and list while testing my code using Nunit. My code public class Myclass { static bool isShown = false; protected static List registery = new List(); //My…
Arunkumar
  • 73
  • 1
  • 11
-1
votes
1 answer

How do I get the typeparam names from a generic type definition?

Suppose I have a generic type definition as such: var type = typeof(IReadOnlyDictionary<,>) How would I get the typeparam name of the generic arguments? In the example above, I'm looking for "TKey" and "TValue" for typeof(IList<>) I am expecting…
Suraj
  • 35,905
  • 47
  • 139
  • 250
-1
votes
3 answers

Get name and value of property when that property is an array of another class?

I understand how to use Reflection to get the property name and value of a given class. But what if that property is an array containing 1 or more of another class? var person = new { Name = "John", Characteristic = new[] { new…
kroe761
  • 3,296
  • 9
  • 52
  • 81
-1
votes
2 answers

C# Find Properties of Classes in a .dll

I'm trying to create a method that counts the properties of a given class. I want to pass in the class name as a string perhaps and then can turn the string into a reference of the given class. I have literally hundreds of classes (generated by…
-1
votes
2 answers

No constructor found while instantiating Assembly on runtime

After loading a DLL and obtaining a type, I get an exception trying to instantiate it: Assembly dll = Assembly.LoadFrom(@"C:\path\file.dll"); Type type = dll.GetType("namespace.CustomClass"); object obj = Activator.CreateInstance(type); // <--…
Mario M.
  • 416
  • 2
  • 10
-1
votes
2 answers

Execute method of one nested class as property in another

I have the following class: public class Happy : IHappy { //public some properties and etc... { get; set; } public bool IsHappy() { //Do something... } } And it is a property in another class: public class Exemplo { public…
AlamBique
  • 167
  • 1
  • 9
-1
votes
1 answer

Why do I get System.InvalidProgramException: Common Language Runtime detected an invalid program

I'm just trying to generate code that just generate a int constant. Here is the code: string name = Path.GetFileNameWithoutExtension(outputPath); string filename = Path.GetFileName(outputPath); AssemblyName assemblyName = new…
-1
votes
1 answer

Reflection Property.SetValue(

I have the following class to create objects from a delimited line: public class Mapper { public T Map(string line, char delimiter) { if(String.IsNullOrEmpty(line)) throw new ArgumentNullException(nameof(line)); …