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
0
votes
3 answers

Map all properties of a class using reflection

I have two domain classes public class Employee { public int Id { get; set; } public string Name { get; set; } public Address Address { get; set; } } public class Address { public string HouseName { get; set; } public string…
BonDaviD
  • 961
  • 3
  • 11
  • 27
0
votes
1 answer

generic class member filling issue (datarow-to-object mapper) (efficient solution)

I am looking to create a database row-to-object mapper for a production server. My goal is to fill at a single location what are the database column name, and into which of this object's field to store a single row returned from a database query. I…
0
votes
2 answers

Accessing fields in a class dynamically

I have this code here where I am trying to save each field in an instance of a class to a separate file. I have it all written out, but something just does not look right about it. The problem is that it doesn't reference the instance, which…
Arlen Beiler
  • 15,336
  • 34
  • 92
  • 135
0
votes
1 answer

How to access other Model field in custom Model field attribute?

The problem is what i'm trying to create a custom Model field attribute in asp.net mvc3 what needs to access other model field. Named for example "PersonId". So i have a model like this public class PersonWoundModel : IAppointmentModel { …
0
votes
2 answers

Issue with CompileAssemblyFromSource when called from a WCF app

I have a WCF service that exposes a method. When a client calls this method, the following occurs: the method does some processing it tries to load an assembly if its already there if the above dll isn't there, it generates C# code, compiles it…
-1
votes
1 answer

C# Static Constructors for Inherited Classes

I have a project with around 100k XML configuration files for managing test equipment. In order to make the files easier to update, I want to be able to port them around to Excel, Access, etc. I've written VBA code to do this, but it is painfully…
-1
votes
1 answer

Access properties in generic class

Suppose I have a class like this: public class DepartmentBase : MyBase where T : new() { public ObservableCollection Employees { get { return _employees; } set { _employees = value;…
Lucy82
  • 654
  • 2
  • 12
  • 32
-1
votes
2 answers

Print the namespace of the currently executing code in C# running in .NET 7

I'd like to print the namespace of the currently executing code running in .NET 7 using C#. Something akin to: Inside of Main (in Program.cs of a program called myApp): // See https://aka.ms/new-console-template for more…
decuser
  • 238
  • 5
  • 20
-1
votes
2 answers

Is "this" static? Checking for Static in the constructor

I need to determine if a member T of class T is a static member, in the constructor. I expect this will involve checking some attributes of "this", but I haven't been able to determine what to look for. public class Thing { public static…
Wes H
  • 4,186
  • 2
  • 13
  • 24
-1
votes
1 answer

Define a generic lambda in C# and assign it to a variable to be used with MakeGenericMethod

I know I can define a generic function and then call it with Type parameters by help of reflection. Something like that: private static void SomeFunc() { // Something type safe against Tf } public void CallingFunc() { var someType =…
Evengard
  • 608
  • 9
  • 19
-1
votes
1 answer

Casting to unknown derived type at runtime?

I've got this command bus implementation which is typically called like this: bus.Invoke(new FocusCommand()); This works fine, but there's now a situation where the command to invoke is dynamic and it's throwing errors: // Command to invoke is…
L. Berger
  • 266
  • 2
  • 15
-1
votes
2 answers

Why does Equals method of attributes compare fields?

When I checked the attributes for equality, I noticed that they already have Equals method that compares the fields. For custom classes this comparison does not occur, since it is bad for performance, but why was an exception made for…
kaboom
  • 41
  • 5
-1
votes
1 answer

Can you check if T inherits from IEnumerable then use methods available to IEnumerable?

So I'm creating a generic method, obviously the signature therefore can take any type of object. The problem I have is I want the user to be able to either just send one object to my method, or a collection (I know, different interface from…
-1
votes
1 answer

c# - How to create Generic T from objectName?

I have created a FetchData method which returns IList and it takes objectName(string) as parameter(name of the object of which we want to return List). Task> FetchData(string processGuiId, string objectName); I am calling a…
-1
votes
1 answer

Get class member of List of Class using Reflection

I have a class typed like this: public class MyClass{ public List mc {get;set;} public List mc2 {get;set;} } public class Myclass1{ public string MyString{get;set} public string Mystring2 {get;set} } How can i…