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 4242476
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T03:26:50+00:00 2026-05-21T03:26:50+00:00

I have a.NET class that I want to use from both C# and PowerShell.

  • 0

I have a.NET class that I want to use from both C# and PowerShell. Cut down to its bare bones, it’s something like this:

class Record
{
    Dictionary<string, string> _fields = new Dictionary<string, string>();
    public IDictionary<string, string> Fields { get { return _fields; } }
    //...other stuff...
}

So I get a Record from somewhere and I can do record.Fields[“foo”] = “bar” to modify/add fields from either C# or PowerShell. Works great.

But I’d like to make it a little more PowerShell-friendly. I want to do record.foo = “bar” and have it call the appropriate getters and setters. (I’d like to do the same with C# at some point, probably using dynamic, but that’s a separate fun project). Seems like I need a wrapping proxy class.

I know about add-member but I am worried that it would be slow and use a lot of memory when dealing with tens of thousands of records. I also don’t know how to have it handle record.somenewvalue = “abc”.

I’m guessing that I want to create my proxy class in C#, using the facilities in System.Management.Automation or Microsoft.PowerShell but don’t quite know where to start. Can anyone help point me in the right direction?

  • 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-05-21T03:26:51+00:00Added an answer on May 21, 2026 at 3:26 am

    I figured out one way to do it. Just make Record itself a dictionary. Here’s some sample code:

    $source = @"
        using System.Collections.Generic;
        public class Record : Dictionary<string, object>
        {
        }
    "@
    
    add-type -typedefinition $source
    
    $x = new-object record
    $x.add('abc', '1') # add
    $x['def'] = '2'    # indexer
    $x.ghi = 3         # "member"
    
    $x
    

    It outputs:

    Key     Value                                                       
    ---     -----                                                       
    abc     1                                                           
    def     2                                                           
    ghi     3                                                           
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a class in .NET that implements IXmlSerializable. I want to serialize its
I have copied class from net which inherits UIImageView. How to put that class
This is .NET 4.0/C#. I have a class that inherits from an interface: public
I have a custom control that inherits from .NET's CompositeControl class. This control overrides
I have a class that inherits from ObservableCollection<T> to re-use the INotifyCollection functionality, but
I'm using protobuf-net v2 and have a class that inherits List that I wan't
If I have a .Net class that is not part of any namespace then
I have an ASP.NET VB.NET web project that references a VB.NET class library. I
I have an ASP.NET WebService that returns an object of List public class Students
I'm working on an asp.net MVC application. I have a class that wraps a

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.