1,154 questions
2
votes
0
answers
97
views
Using MethodRental's SwapMethodBody on powershell classes
I recently discovered MethodRental and it seems really interesting, coming from JS, being able to pre-empt existing functions can be a neat hacky get-out-of-jail card for the toolbelt.
As an aside, ...
0
votes
1
answer
89
views
Deducing instance to handle an object in C#
I am extending my C# J2K library to dynamically register codecs from other assemblies. That part is working, but I am having trouble understanding IsAssignableFrom(TypeInfo) and how I can deduce which ...
0
votes
2
answers
73
views
Is it possible to replicate ASP.NET RouteAttribute functionality in a non-WebAPI project?
I'm currently working on a console application that essentially mimics an ASP.NET Web API.
Everything was going smoothly until I ran into an issue regarding route attributes.
What I'm trying to ...
0
votes
1
answer
100
views
C# Blazor .NET 9: automatically collect all application Policies
I use .NET 9 and blazor, ASP.NET Core Identity - role, policy, claim.
To differentiate access on pages and components, the code is using policies - like this:
@attribute [Authorize(Policy("...
-1
votes
1
answer
70
views
Hash keys match, but Distinct() doesn't remove duplicates with my custom MemberInfo type class only when the MemberType is set to Custom
I got tired of dealing with properties and fields separately so I made a VariableInfo strategy pattern to handle both without having to know what type it is. You feed the context a FieldInfo or a ...
2
votes
1
answer
266
views
Attribute.IsDefined() isn't working for my custom MemberInfo type
The short of it is that I got tired of dealing with properties and fields separately. I made a VariableInfo strategy pattern to handle both without having to know what type it is. You feed the context ...
2
votes
0
answers
47
views
Is there a way to programmatically determine if a compiled cmdlet requires elevation (other than simply running the command)?
Is there a way to use reflection to programmatically inspect and determine if a given compiled cmdlet requires elevation?
Notes:
This question concerns compiled cmdlets, not script (text) files.
...
0
votes
1
answer
86
views
Moq fully generic Setup with class proxy attempt throws `Late bound operations cannot be performed`
PROBLEM TO SOLVE
I'm trying to create a mock of interface ISomeService using Moq library which will wrap its real implementation SomeService.
Right now I'm doing this manually like this:
var instance =...
3
votes
1
answer
127
views
Is there a way of constructing function pointer types using Reflection?
I need some way of constructing a function pointer type that points to a specific function signature. So something like this:
Type[] args = [typeof(int), typeof(int)];
// Pointer to (int -> int) ...
-1
votes
2
answers
135
views
Is it possible to use reflection to compare two arrays with the same element types?
My class looks something like this:
public class Test
{
public A[] ArrayA { get;set; }
}
public class A
{
public string P1 { get;set; }
public int P2 { get;set; }
}
Suppose I have two ...
2
votes
2
answers
186
views
How to Call a C# Method from C++ with Parameters?
using System;
using System.Runtime.InteropServices;
using System.Reflection;
public struct StructCreatedByUser
{
public int x;
public float anything;
public string name;
}
class Program
{
...
1
vote
1
answer
123
views
A general-purpose decorator - correctly awaiting an awaitable type obtained from Reflection
Preamble: I was looking at how best to implement a general-purpose decorator in C# that copes with async methods. Most examples use DispatcherProxy, which only offers a synchronous Invoke. Unless NET ...
2
votes
2
answers
139
views
C# Dynamic Object call TryInvoke with an unknown array of arguments
I need to invoke a given DynamicObject with a given array of arguments. However, I am struggling on how exactly to do this.
What I would like to do:
using System.Dynamic;
using System.Reflection;
...
0
votes
2
answers
73
views
How to initialize properties using Reflection?
Given the following sample POCO class:
public class TestClass
{
public int Id { get; init; }
public TestClass() {}
}
How can I initialize the Id property using Reflection?
The result should ...
-2
votes
2
answers
142
views
Recursively instantiating the classes inside an object
I want to activate, via reflection automatically and recursively all the nested classes inside a class I am instantiating. Here is the template of what I am trying to do, but I do not know how to make ...