Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>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...</p> <p>EDIT: Based on our discussion in the comments, here's a thought:</p> <p>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. <a href="http://msdn.microsoft.com/en-us/library/4zfbcfc1.aspx" rel="nofollow noreferrer">Link.</a>. 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().</p> <p>There's another overload that may be of interest that takes a type to extend, and interfaces:</p> <p><a href="http://msdn.microsoft.com/en-us/library/f53tx4x8.aspx" rel="nofollow noreferrer">http://msdn.microsoft.com/en-us/library/f53tx4x8.aspx</a></p> <p>EDIT2: Code sample:</p> <p>First, create an interface:</p> <pre><code>public interface ISaveExtentable //I suck at naming stuff :-p { } </code></pre> <p>Then, in the code you liked to in that site, you'll find a method called: GetTypeBuilder. Change it to this:</p> <pre><code> 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; } </code></pre> <p>Then, create an extension method on that interface to do the save:</p> <pre><code> public static class SaveExtendableExtensions { public static void Save(this ISaveExtentable ise) { //implement save functionality. } } </code></pre> <p>You'll most likely need to use reflection in your Save method to get all the properties since the type was created dynamically.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload