Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8034391
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T01:59:49+00:00 2026-06-05T01:59:49+00:00

So I started with no knowledge on reflection or dynamic typing, but I’ve learned

  • 0

So I started with no knowledge on reflection or dynamic typing, but I’ve learned a lot. However, there is one thing I cannot find: the “as” equivalent for dynamic typing.

What I’m trying to do is the equivalent of this (if it would compile):

foreach (Change c in changes)
{
    (c.Undo as Action<c._Type, c._Type>).Invoke(
        c.OldValue as c._Type, c.NewValue as c._Type);
}

From what I understand, I need to do something along the lines of

Type constructedClass = typeof(Action<,>).MakeGenericType(c._Type);

to construct the needed Action class, but is there a way to implement as for both the Action type and c._Type?

For further clarification, here is the pseudocode (and this is my first time trying to do this kind of thing, so please be nice):

foreach (Object o in objects)
{
    (o.SettableMethod as Action<o.TypeOfParameters, o.TypeOfParameters>).Invoke(
        o.Parameter1 as TypeOfParameters, o.Parameter2 as TypeOfParameters);
}

Thanks in advance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T01:59:50+00:00Added an answer on June 5, 2026 at 1:59 am

    The purpose of the generics on the Action (or in general) is to allow you to manage type safety at compile time. If you use reflection, you are doing extra work to not get that benefit. You might as well have the signature of your Undo Action take two objects of type object, and cast to appropriate types inside the action, if needed.

    Even more generally, you would be better served by a different design. Why are you calling a method on Change that sends properties of Change back in? Could you not call Undo without any parameters, and leave Change responsible for knowing what the new and old values are?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've just started combining my knowledge of C++ classes and dynamic arrays. I was
I have no knowledge of Python. I started with .NET and than learned PHP.
I just started C++ but have some prior knowledge to other languages (vb awhile
As I have started using Linux (Ubuntu) to broaden my knowledge, but the flow
I just started using FPC to practice more my old knowledge of Pascal, but
I have just started studying Android, I have limited java knowledge but am semi
I just started out with C and have very little knowledge about performance issues
Ignore my novice knowledge in jQuery. I started to learn recently and I have
I have a fair knowledge about Javascript, I started with jQuery 1.4 a week
I'm assuming my lack of knowledge (I just started learning Flex yesterday, hah!) is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.