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

  • Home
  • SEARCH
  • 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

if i have a .net 1.1 class that inherits from DictionaryBase and i am
I have a .NET class library containing a class with a method that performs
Using C# .NET 2.0, I have a composite data class that does have the
I have a class 'Database' that works as a wrapper for ADO.net. For instance,
I have a C# (2008/.NET 3.5) class library assembly that supports WPF (based on
I have inherited a project that has class libraries written in VB.NET, some of
C# question (.net 3.5). I have a class, ImageData, that has a field ushort[,]
I have a class that contains hierarchical data. I want to present this data
Say I have a .NET class like so: public class Person { public string
I have a .NET 3.5 web application for which I have implemented a class

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.