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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T11:23:01+00:00 2026-05-11T11:23:01+00:00

I have been saddled with using an in-house data access library that is effectively

  • 0

I have been saddled with using an in-house data access library that is effectively XML passed to a stored procedure, which returns XML. There is nothing I can do about this. I tried to get ActiveRecord approved, but my request was declined. However, using the excellent code provided at http://blog.bodurov.com/Post.aspx?postID=27, I added an extension method to IEnumerable that converts the key-value pairs I make out of the ragged XML coming back into strongly typed objects, complete with property names!

This:

dict['keyName1'] 

becomes

MyObject.keyName1 

Now the interface supports databinding! Pretty cool! I’d like to take it a step further, though. I want the objects emitted to have Save() methods too, so that I can ape the ActiveRecord pattern and provide my web guys with an intuitive object layer to use from ASP.net.

How do I write a method in Visual Studio, in source code, and attach it at runtime to the emitted objects? I am not interested in (or qualified for) writing assembly or IL. I’d like to do this in C#. This is my first StackOverflow question and I am posting this with company-mandated IE6, so please be gentle.

  • 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. 2026-05-11T11:23:01+00:00Added an answer on May 11, 2026 at 11:23 am

    From what I gather on that article, it’s creating anonymous types for you, and you’re using that to get the values. If that’s the case, there’s no easy way to add methods on to those objects. However, if the XML structure will be the same every time the SP executes, why not create a concrete class that has all the properties you need, and populate a collection of those objects yourself with the XML. That way, you can easily add any methods you need directly into the class…

    EDIT: Based on our discussion in the comments, here’s a thought:

    In the code there, when you’re building up the type, you’re using: ModuleBuilder.DefineType. There’s an overload to DefineType which takes a type to extend. Link.. Therefore, create an interface (it doesn’t event have to have any methods in it), and when you’re dynamically building up the type, extend that interface using the overload I linked you to. Then create an extension method on that interface that does the Save().

    There’s another overload that may be of interest that takes a type to extend, and interfaces:

    http://msdn.microsoft.com/en-us/library/f53tx4x8.aspx

    EDIT2: Code sample:

    First, create an interface:

    public interface ISaveExtentable //I suck at naming stuff :-p {  } 

    Then, in the code you liked to in that site, you’ll find a method called: GetTypeBuilder. Change it to this:

            private static TypeBuilder GetTypeBuilder(string typeSigniture)         {             AssemblyName an = new AssemblyName('TempAssembly' + typeSigniture);             AssemblyBuilder assemblyBuilder =                 AppDomain.CurrentDomain.DefineDynamicAssembly(                     an, AssemblyBuilderAccess.Run);             ModuleBuilder moduleBuilder = assemblyBuilder.DefineDynamicModule('MainModule');              TypeBuilder tb = moduleBuilder.DefineType('TempType' + typeSigniture                                 , TypeAttributes.Public |                                 TypeAttributes.Class |                                 TypeAttributes.AutoClass |                                 TypeAttributes.AnsiClass |                                 TypeAttributes.BeforeFieldInit |                                 TypeAttributes.AutoLayout                                 , typeof(object), new Type[] {typeof(ISaveExtentable)});             return tb;         } 

    Then, create an extension method on that interface to do the save:

        public static class SaveExtendableExtensions     {           public static void Save(this ISaveExtentable ise)           {               //implement save functionality.            }     } 

    You’ll most likely need to use reflection in your Save method to get all the properties since the type was created dynamically.

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

Sidebar

Ask A Question

Stats

  • Questions 121k
  • Answers 121k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer I think your best approach here would be to take… May 12, 2026 at 12:20 am
  • Editorial Team
    Editorial Team added an answer Have you installed Service Pack 1 for Vistual studio 2008? May 12, 2026 at 12:20 am
  • Editorial Team
    Editorial Team added an answer That is essentially: "which is better: a bucket or a… May 12, 2026 at 12:20 am

Related Questions

I have been experimenting with woopra.com A web analytics tool. Which requires a piece
I have been working on a web services related project for about the last
I have been working with Visual Studio (WinForm and ASP.NET applications using mostly C#)
I have been looking into IKVMing Apache's FOP project to use with our .NET

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.