Dynamic Forum Rss Feedhttp://www.codeplex.com/Project/ListForums.aspx?ProjectName=DynamicDynamic Forum Rss DescriptionNew Post: How about generic method invocations?http://www.codeplex.com/Dynamic/Thread/View.aspx?ThreadId=31524<div style="line-height: normal;">I'd like to use your approach to handling generic class instantiation and generic method&nbsp;&nbsp;invocation, but I don't see any way to do it.<br>
<br>
Here's a sample of code I'd like to use it for.<br>
<br>
creating a strongly typed object:<br>
<br>
CreateObject&lt;T&gt;( string a, int b, params object[] c )<br>
{<br>
&nbsp; SomeObject&lt;T&gt; rv = new SomeObject&lt;T&gt;( a, b, c )<br>
<br>
&nbsp; return rv;<br>
}<br>
<br>
<br>
calling a strongly typed generic proc or function:<br>
<br>
...<br>
void Foo&lt;T&gt;( T arg1, T arg2 ) {}<br>
Q bar&lt;Q&gt;( int i, double j ) { }<br>
<br>
Is there a way to accomplish this with this thing?<br>
<br>
<br>
</div>vankirkcTue, 15 Jul 2008 08:05:43 GMTNew Post: How about generic method invocations? 20080715080543ANEW POST: Internal Classhttp://www.codeplex.com/Dynamic/Thread/View.aspx?ThreadId=24967<div style="line-height: normal;">Yes, i've a solution.<br>
<br>
You can see a sample in my project Tangibilis in Codeplex.<br>
<br>
<a href="http://www.codeplex.com/Tangibilis/SourceControl/FileView.aspx?itemId=135071&changeSetId=6122">http://www.codeplex.com/Tangibilis/SourceControl/FileView.aspx?itemId=135071&amp;changeSetId=6122</a><br>
<br>
Good luck.
</div>sbiaWed, 21 May 2008 19:25:34 GMTNEW POST: Internal Class 20080521072534PNEW POST: Internal Classhttp://www.codeplex.com/Dynamic/Thread/View.aspx?ThreadId=24967<div style="line-height: normal;">Yes, i've a solution.<br>
<br>
You can see a sample in my project Tangibilis in Codeplex.<br>
<br>
<a href="http://www.codeplex.com/Tangibilis/SourceControl/FileView.aspx?itemId=135071&changeSetId=6122">http://www.codeplex.com/Tangibilis/SourceControl/FileView.aspx?itemId=135071&amp;changeSetId=6122</a><br>
<br>
Good luck.
</div>sbiaWed, 21 May 2008 16:50:32 GMTNEW POST: Internal Class 20080521045032PNEW POST: Internal Classhttp://www.codeplex.com/Dynamic/Thread/View.aspx?ThreadId=24967<div style="line-height: normal;">I have the same problem. Any solution?
</div>nesherTue, 20 May 2008 18:47:18 GMTNEW POST: Internal Class 20080520064718PNEW POST: Internal Classhttp://www.codeplex.com/Dynamic/Thread/View.aspx?ThreadId=24967<div class="wikidoc">
Hi, How can i invoke method from an internal class ?<br />
</div>sbiaSat, 29 Mar 2008 16:39:41 GMTNEW POST: Internal Class 20080329043941PNEW POST: Nested Objectshttp://www.codeplex.com/Dynamic/Thread/View.aspx?ThreadId=20443<div class="wikidoc">
Code example sent to your email.<br />
</div>mtsu_bravoThu, 17 Jan 2008 21:30:03 GMTNEW POST: Nested Objects 20080117093003PNEW POST: Nested Objectshttp://www.codeplex.com/Dynamic/Thread/View.aspx?ThreadId=20443<div class="wikidoc">
Is there any expectation of extending this to support nested objects? aka something.somethingelse.something<br />I have taken your base and manipulated it with some other examples I have found to support this but it is not fully functional. As I do not fully understand how this works. I can supply you with the code I got if your willing to make the modification to your base to support this.<br /> <br />The problem I have with mine is as long as all of the nested objects are populate it works, but if they are not they will have a value of null and it causes an compare error. These objects are not of type nullable but they have a value of null.<br /> <br />Does this make any sense?<br />Thanks for the library its been very helpful.<br />
</div>mtsu_bravoTue, 15 Jan 2008 01:15:39 GMTNEW POST: Nested Objects 20080115011539ANEW POST: How to access the field like System.Data.RelatedView.values ?http://www.codeplex.com/Dynamic/Thread/View.aspx?ThreadId=18335<div class="wikidoc">
The problem is that the type System.Data.RelatedView is internal into System.Data.dll so the following code can't be compiled : <br />Dynamic&lt;System.Data.RelatedView&gt;.Instance.Field&lt;object[]&gt;.Getter.CreateDelegate(&quot;values&quot;); <br /> <br />so I've wrote this to access it without your lib:<br /> <br /> Type relatedViewType = System.Reflection.Assembly.GetAssembly(typeof(System.Data.DataSet))<br /> .GetType(&quot;System.Data.RelatedView&quot;);<br /> <br /> FieldInfo valuesField = relatedViewType.GetField(&quot;values&quot;, System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);<br /> <br /> //build setter<br /> DynamicMethod setterDef = new DynamicMethod(relatedViewType.Name + &quot;<i>&quot; + valuesField + &quot;</i>Setter&quot;,<br /> typeof(void),<br /> new Type[] { typeof(DataView), typeof(object[]) }, //define 1st param as DataView cause RelatedView is not an accessible type<br /> relatedViewType);<br /> <br /> ILGenerator setterIL = setterDef.GetILGenerator();<br /> setterIL.Emit(OpCodes.Ldarg_0); //we expect in top of the stack object instance<br /> setterIL.Emit(OpCodes.Ldarg_1);<br /> setterIL.Emit(OpCodes.Stfld, valuesField);<br /> setterIL.Emit(OpCodes.Ret); //note: we have to return, even if method is void<br /> <br /> //assign s_RelatedViewKeyValuesSetter with the builded method<br /> s_RelatedViewKeyValuesSetter = (Common.Utility.CodeEmit.Proc&lt;DataView, object[]&gt;)setterDef.CreateDelegate(typeof(Common.Utility.CodeEmit.Proc&lt;DataView, object[]&gt;));<br /> <br /> <br />
</div>BixasBxBTue, 04 Dec 2007 11:18:20 GMTNEW POST: How to access the field like System.Data.RelatedView.values ? 20071204111820ANEW POST: How to access the field like System.Data.RelatedView.values ?http://www.codeplex.com/Dynamic/Thread/View.aspx?ThreadId=18335<div class="wikidoc">
Thanks for the interest.... the fact that a type is internal or private should cause you no trouble if you are running under full trust. Can you upload or send me a sample that breaks, I'll happily fix the library to accomodate.<br />
</div>IDisposableTue, 27 Nov 2007 23:50:24 GMTNEW POST: How to access the field like System.Data.RelatedView.values ? 20071127115024PNEW POST: How to access the field like System.Data.RelatedView.values ?http://www.codeplex.com/Dynamic/Thread/View.aspx?ThreadId=18335<div class="wikidoc">
Hello,<br /> <br />I'm search how to use your generic based framework on a Type which is inaccessible like System.Data.RelatedView ?<br /> <br />Thanks for your great dynamic Reflection Lib.<br /> <br />BxB<br />
</div>BixasBxBMon, 26 Nov 2007 19:33:48 GMTNEW POST: How to access the field like System.Data.RelatedView.values ? 20071126073348PNEW POST: MethodAccessExceptionhttp://www.codeplex.com/Dynamic/Thread/View.aspx?ThreadId=10647<div class="wikidoc">
Hi, of course, as expected, this new code (changeset 22961) works fine in my generic base class scenario too.<br /> <br />Vlado.<br />
</div>vladoooSat, 26 May 2007 09:46:30 GMTNEW POST: MethodAccessException 20070526094630ANEW POST: MethodAccessExceptionhttp://www.codeplex.com/Dynamic/Thread/View.aspx?ThreadId=10647<div class="wikidoc">
I've updated the code according to your suggestion (keeping the existing path intact for varargs methods) and added your test-case. Let me know if the current build does the trick and I'll drop a new release.<br />
</div>IDisposableFri, 25 May 2007 20:01:13 GMTNEW POST: MethodAccessException 20070525080113PNEW POST: MethodAccessExceptionhttp://www.codeplex.com/Dynamic/Thread/View.aspx?ThreadId=10647<div class="wikidoc">
This discussion has been copied to a work item. Click here to <a href="http://www.codeplex.com/Dynamic/WorkItem/View.aspx?WorkItemId=10576">go to the work item and continue the discussion</a>.<br />
</div>IDisposableFri, 25 May 2007 19:44:30 GMTNEW POST: MethodAccessException 20070525074430PNEW POST: MethodAccessExceptionhttp://www.codeplex.com/Dynamic/Thread/View.aspx?ThreadId=10647<div class="wikidoc">
OR another solution to this is to set skipVisibility parameter in DynamicMethod constructor to true:<br /> <br />DynamicMethod dm = new DynamicMethod(&quot;DynamicCompare&quot;<br /> , MethodAttributes.Static | MethodAttributes.Public, CallingConventions.Standard,<br /> typeof(int), new Type[] { typeof(T), typeof(T) }, typeof(T), <b>true</b>);<br />
</div>vladoooFri, 25 May 2007 17:32:41 GMTNEW POST: MethodAccessException 20070525053241PNEW POST: MethodAccessExceptionhttp://www.codeplex.com/Dynamic/Thread/View.aspx?ThreadId=10647<div class="wikidoc">
Hi. I found the solution. I changed Call method in DynamicEmit class to this:<br /> <br />public void Call(MethodInfo method)<br /> {<br /> if (method.IsFinal || !method.IsVirtual)<br /> {<br /> _ilGen.Emit(OpCodes.Call, method);<br /> }<br /> else<br /> {<br /> _ilGen.Emit(OpCodes.Callvirt, method);<br /> }<br /> }<br /> <br />Now everything works fine.<br /> <br />According to this http://blogs.msdn.com/haibo_luo/archive/2006/08/13/698719.aspx<br />EmitCall is mainly for varargs methods and you can (should) use Emit when you do not use varargs.<br />I do not understand MSIL but I might be a bug in EmitCall or I don't know.<br /> <br />Have a nice day.<br /> <br />Vlado<br />
</div>vladoooFri, 25 May 2007 13:49:09 GMTNEW POST: MethodAccessException 20070525014909PNEW POST: MethodAccessExceptionhttp://www.codeplex.com/Dynamic/Thread/View.aspx?ThreadId=10647<div class="wikidoc">
Hi Marc, here is very simple minimal reproduction:<br /> <br />using System;<br />using System.Collections.Generic;<br />using System.Text;<br />using Phydeaux.Utilities;<br /> <br />namespace ConsoleApplication1<br />{<br /> class Program<br /> {<br /> static void Main(string[] args)<br /> {<br /> // get the list<br /> List&lt;CountryBDO&gt; list = CountryBDO.getAllBDOs();<br /> }<br /> <br /> }<br /> <br /> // base class<br /> public abstract class BDORoot&lt;TBDO&gt;<br /> {<br /> private long? _ID;<br /> public long? ID<br /> {<br /> get { return _ID; }<br /> set { _ID = value; }<br /> }<br /> }<br /> <br /> // derived class<br /> public class CountryBDO : BDORoot&lt;CountryBDO&gt;<br /> {<br /> private string _Name;<br /> public string Name<br /> {<br /> get { return _Name; }<br /> set { _Name = value; }<br /> }<br /> <br /> public static List&lt;CountryBDO&gt; getAllBDOs()<br /> {<br /> <br /> List&lt;CountryBDO&gt; list = new List&lt;CountryBDO&gt;();<br /> CountryBDO c1 = new CountryBDO();<br /> c1.ID = 100;<br /> c1.Name = &quot;USA&quot;;<br /> list.Add(c1);<br /> CountryBDO c2 = new CountryBDO();<br /> c2.ID = 50;<br /> c2.Name = &quot;Slovakia&quot;;<br /> list.Add(c2);<br /> CountryBDO c3 = new CountryBDO();<br /> c3.ID = 150;<br /> c3.Name = &quot;Vanuatu&quot;;<br /> list.Add(c3);<br /> <br /> //works<br /> list.Sort(new DynamicComparer&lt;CountryBDO&gt;(&quot;Name&quot;));<br /> <br /> //throws exception<br /> list.Sort(new DynamicComparer&lt;CountryBDO&gt;(&quot;ID&quot;));<br /> <br /> return list;<br /> }<br /> }<br />}<br />
</div>vladoooFri, 25 May 2007 07:26:34 GMTNEW POST: MethodAccessException 20070525072634ANEW POST: MethodAccessExceptionhttp://www.codeplex.com/Dynamic/Thread/View.aspx?ThreadId=10647<div class="wikidoc">
Any chance you could give me a minimal reproduction of the issue in code? I can fix it much faster if I'm sure I'm addressing your actual issue.<br />
</div>IDisposableFri, 25 May 2007 04:48:48 GMTNEW POST: MethodAccessException 20070525044848ANEW POST: MethodAccessExceptionhttp://www.codeplex.com/Dynamic/Thread/View.aspx?ThreadId=10647<div class="wikidoc">
Hi,<br /> <br />I am getting MethodAccessException when I use DynamicComparer to compare classes using some property which is declared at the base-class level.<br /> <br />The base class is abstract generic class BDORoot&lt;T&gt; and has properties like ID, DateCreated etc.. Derived classes inherit from it like: class CurrencyBDO : BDORoot&lt;CurrencyBDO&gt;.<br /> <br />When I use DynamicComparer to sort by (for example) Name property which is declared in CurrencyBDO everything works fine. But when I try to sort by some property declared in BDORoot like ID or DateCreated it throws MethodAccessException (&quot;cannot invoke get_ID() method&quot;) during comparer.Invoke(x, y) call. I run it locally in Full trust so I do not understand why this happens. All that properties and classes are public.<br /> <br />Do you have any idea what might be wrong? My code or something in DynamicEmit class?<br /> <br />BTW: Thanks Mark for great Dynamic Reflection Library .<br /> <br />Vlado.<br />
</div>vladoooThu, 24 May 2007 12:50:42 GMTNEW POST: MethodAccessException 20070524125042PUser Forum: RE: DynamicDeepCopyhttp://www.codeplex.com/Dynamic/Project/DisplayThread.aspx?ForumId=1598&ThreadId=3137&ANCHOR#LastPostHonestly, I don't know how much it would differ from Serialization. The idea doesn't really come out of a specific need, I will just have most of the code done (via the bulk method calls), so it seemed like a good next step. I have had a need in the past for deep copy support though. I would think it would be faster than serialization and it would not require you to mark up your objects as serializable.
The downside to the bulk calls is that right now they take object[] for the properties to be set and return an object[] for retrieved properties (I can't have them both in one method because I am tranforming from one class to another) so there will usually be boxing/unboxing. The only alternative I could come up with was to include Generic Delegates for up to n parameters, but since an object could have dozens of properties, this didn't seem like a very clean approach either.
As long as I'm deep copying an object tree, however, the getting and setting should be able to be called from within the same method on each object and should, I would think, be very fast as there is no serialization / deserialization happening.
That's about all I can come up with though. Any thoughts?JasonMuellerWed, 27 Dec 2006 16:47:00 GMTUser Forum: RE: DynamicDeepCopy 20061227044700PUser Forum: RE: DynamicDeepCopyhttp://www.codeplex.com/Dynamic/Project/DisplayThread.aspx?ForumId=1598&ThreadId=3137&ANCHOR#LastPostI would definately be interested. If the quality of code is good, I will add you to the project as a contributor if you like. Send me the goods at IDisposable@gmail.com
One question, how will this differ from simply doing a serialize/deserialize (which does a deep copy with related objects)?
FYI, I'm going to be commiting a couple things in this project again as soon as a minor issue with the CodePlex workspaces and my old (deceased) laptop is resolved.
IDisposableWed, 27 Dec 2006 09:08:39 GMTUser Forum: RE: DynamicDeepCopy 20061227090839A