Showing posts with label Internal Property. Show all posts
Showing posts with label Internal Property. Show all posts

Wednesday, July 22, 2009

Calling Internal Property of Class through Reflection

Type contentType = typeof(SPContentType);
Type paramType = typeof(SPContentTypeId);
Type[] paramArray = { paramType };
ConstructorInfo consInfo = contentType.GetConstructor(BindingFlags.Instance BindingFlags.NonPublic, null, CallingConventions.Any, paramArray, null);
object[] paramsX = { new SPContentTypeId(contentTypeID) };
SPContentType contentTypeObject = consInfo.Invoke(paramsX) as SPContentType; contentTypeObject.GetType().InvokeMember("Web", BindingFlags.NonPublic BindingFlags.Instance BindingFlags.SetProperty BindingFlags.IgnoreCase, null, contentTypeObject, new object[] { targetWeb }); contentTypeObject.GetType().InvokeMember("Collection", BindingFlags.NonPublic BindingFlags.Instance BindingFlags.SetProperty BindingFlags.IgnoreCase, null, contentTypeObject, new object[] { targetWeb.ContentTypes }); return contentTypeObject;