This project is read-only.

How to get a part Type from the ContentPartDefinition

Topics: Customizing Orchard, Writing modules
Sep 13, 2013 at 9:39 PM
May be a basic question but how to get the c# Type corresponding to a part when we only know the part name without the assembly where it is defined ?
Sep 13, 2013 at 9:42 PM
There isn't necessarily a C# type corresponding to a part, so I don't think there's a simple way to do this.
Sep 13, 2013 at 9:52 PM
And if we consider that there is a c# type ?

I have tried this

Type x= AppDomain.CurrentDomain.GetAssemblies()
                            .SelectMany(a => a.GetTypes())
                            .Where(t => t.Name == partName)
but so heavy....
Sep 14, 2013 at 12:04 AM
That's the way it is. What's your scenario?
Sep 14, 2013 at 12:20 AM
User selects a part name and I fill a select with its properties....could be nice to be able to use the same thing as NHibernate is using, but I have found nothing.
now trying something as
Type x= AppDomain.CurrentDomain.GetAssemblies()
                        .SelectMany(a => a.GetTypes())
                        .Where(t => t.Name == partName)
var lst=x.GetProperties(BindingFlags.DeclaredOnly | BindingFlags.SetProperty | BindingFlags.Public | BindingFlags.Instance)
            .Select(p => new {
                Name = p.Name,
                IndexParameters = p.GetIndexParameters(),
                Accessors = p.GetAccessors(false)
            .Where(x => x.IndexParameters.Count() == 0) // must not be an indexer
            .Where(x => x.Accessors.Length != 1 || x.Accessors[0].ReturnType == typeof(void)) //must have get/set, or only set
            .Select(p => p.Name);
Sep 14, 2013 at 12:23 AM
What is nHibernate using?
Sep 14, 2013 at 12:46 AM
certainly something to find properties for parts ? some mapping ?
Sep 14, 2013 at 1:32 AM
What makes you believe that? I don't see what it could be using besides reflection.
Sep 14, 2013 at 7:51 PM
Back to
Type x= AppDomain.CurrentDomain.GetAssemblies()
                        .SelectMany(a => a.GetTypes())
                        .Where(t => t.Name == partName)
I am getting this load exception when trying to find a type for a part in the list of assemblies of CurrentDomain, seems that at some point the loop fails on a missing assembly, sorry but it's in french

{"Impossible de charger le fichier ou l'assembly 'Microsoft.Practices.EnterpriseLibrary.Common, Version=5.0.505.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' ou une de ses dépendances. Le fichier spécifié est introuvable.":"Microsoft.Practices.EnterpriseLibrary.Common, Version=5.0.505.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"}

It is very strange, I only get an exception on a Part in one of my modules, this module has no refernce to the upper missing assembly ?
The module is working, the part also ???
Sep 14, 2013 at 8:53 PM
Something has got to have a reference to it. I don't remember how lazy the assembly loader is. It's possible that until something tries to access it, it doesn't even attempt to load it. I'd track that reference down.
Sep 14, 2013 at 8:59 PM
I am suspecting the SQLAzure recent add which is using a piece of code from Patterns & Practice ......
Sep 14, 2013 at 10:17 PM
Confirmed it is NHibernate.SQLAzure, I open an issue