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
-2
votes
1 answer

How to pass parameters to an api in c#?

I have below api url http://myapi/api/getproduct? These parameters will get created from below class public class ApiParamters { public string id {get;set;} public string name {get;set;} public List otherNames {get;set;} } If…
Gaurav123
  • 5,059
  • 6
  • 51
  • 81
-2
votes
1 answer

How to get the return type and the generic type of the return type of current method being executed in c#?

I have this code [HttpPost("search")] public async Task> GetEmployees([FromBody] EmployeeSearchDto employeeSearchParameters) { } How to get ActionResult type and int type I can't seem to find the return type…
-2
votes
1 answer

Detect indexer from MethodInfo

Given the following code: var dict = new Dictionary() { {"",""} }; Expression> expr = () => dict[""]; expr.Body returns an instance of MethodCallExpression, whose Method property returns the get__Item…
Zev Spitz
  • 13,950
  • 6
  • 64
  • 136
-2
votes
1 answer

How to control the accessibility of .net api while loading external .net dll assembly?

I need to allow some users to upload some plugin dll that would run on the server (based on asp.net core) as some custom script (I dont want to use javascript or any other languages to limit the api accessibility). How can I keep the user dlls from…
Alsein
  • 4,268
  • 1
  • 15
  • 35
-2
votes
1 answer

How to get class and method name in the given scenario?

I am using online c# compiler just to determine the class and method name.See the code given below, I am intentionally generating an error. Expected Output is: Hello, world! ExceptionTest , basically from where the exception has been generated.…
user240141
-2
votes
2 answers

Dynamically enumerate fields from List

I'm using the following method to enumerate fields of my classes- EnumerateFields(typeof(Student)); void EnumerateFields(Type type) { PropertyInfo[] props = type.GetProperties(); foreach (PropertyInfo prp in props) { } } It works…
s.k.paul
  • 7,099
  • 28
  • 93
  • 168
-2
votes
2 answers

How to convert Func to Func in C#

I tried to code a function using refelecion to convert a function Func< TSource, bool> to Func< TTarget, bool> but without success This what i did: static Func Convert(Func func) { var…
SomeCode.NET
  • 917
  • 15
  • 33
-2
votes
1 answer

How to dynamically create a generic list based on a type determined at runtime

How can I change the class type in the list based on a condition like this: var clsBoName; if(Type==1) { clsBoName=clsBOManageRoles; } else { clsBoName=clsBOManageOthers; } List RoleCapabilityList = new List();…
user547534
  • 70
  • 8
-3
votes
2 answers

How can I call variable by string name

In my application I am using variables with names like dp1,dp2,....dp13 in order to use them in loops and I want to call thame in a for loop. I want to use it something like given below. DataPoint dp1,dp2,dp3,dp4,dp5; string s1,s2,s3,s4,s5; for(int…
-3
votes
1 answer

How to convert PropertyInfo[] to my class

I'm developing an .NET Core 3.1 API, and I had a situation where I needed to iterate an object using foreach. To be able to do this, I used Reflection: var properties = myClass.GetType().GetProperties(); After that, the code goes through the…
-3
votes
1 answer

How to get values of properties having List in it in C#?

I have below class public class MyClass { public string Name {get; set;} public List Products {get; set;} } if I use the below code, I am able to get value of '''Name''' property. However not able to get values of Products…
Gaurav123
  • 5,059
  • 6
  • 51
  • 81
-3
votes
1 answer

How to find Queue type in assemblies?

I need to deserialize classes created on different machines. The programs are very similar but have differences in Program name, as well as .Net version etc. This code below works quite well, except for when I have a Queue in my class. I am unable…
ManInMoon
  • 6,795
  • 15
  • 70
  • 133
-3
votes
3 answers

Get the propertyInfo by the path to it?

I want to get the propertyInfo by the path that look like this: string path = "window.position.x"; Here an example: PropertyInfo p = typeof(WindowManager).GetProperty(path); the WindowManager has a property called "window", which has a property…
CarpoSep
  • 35
  • 1
  • 5
-3
votes
1 answer

How to Instantiate a Interface or class from given string

this is the function I call this.ExecuteSQLProcedure("sp_GenerateInterface", new object[] { TableName }); Result of above function and is stored in string variable string tableInterface = Public Class UserMaster { Guid UserId { get; set; } …
-3
votes
2 answers

How to get enum value having enum type name and enum option name

I have this enum: public enum SomeEnum { None, Half, All } How would be the following method body, so I can get the value 1 have option "None" and enum name "SomeEnum" stored as string: string enumTypeName = "SomeEnum"; string…
Raphael Ribeiro
  • 529
  • 5
  • 18
1 2 3
74
75