Public Constructors
Old forum URL: forums.lhotka.net/forums/t/5322.aspx
juddaman posted on Friday, August 29, 2008
I've just worked out that my business objects must expose a public constructor for the data portal to work. As far as I can work out this is because the Activator.CreateInstance method requires a public constructor. The overload allowing non-public constructors does not seam to be present on the compact framework. Is this all correct? Anyway around this?
Thanks
George
lawrencek replied on Tuesday, September 23, 2008
Unfortunalty there is no private reflection in CF and it does not appear that it will happen soon.
drozd replied on Thursday, September 25, 2008
As a matter of fact you can invoke private constructors - just substitute
obj = Activator.CreateInstance(objectType);
with:
ConstructorInfo nonPublicConstructorInfo = objectType.GetConstructor(BindingFlags.NonPublic | BindingFlags.Instance, null, new Type[] { }, null);
obj = nonPublicConstructorInfo.Invoke(new object[] { });
A complete thread on this subject: http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=701087&SiteID=1
lawrencek replied on Thursday, September 25, 2008
Very cool I'll give that a try,Copyright (c) Marimer LLC