I have the following linq statement
builtIn = (from type in Assembly.GetExecutingAssembly().GetTypes()
where type.IsClass && type.Namespace.ToUpper().StartsWith("PD3.MODULES.BUILTIN.")
let onStartMethod = type.GetMethod("Init")
where onStartMethod != null
select onStartMethod
);
but it only works if I leave out the
&& type.Namespace.ToUpper().StartsWith("PD3.MODULES.BUILTIN") part 🙁
Further down the code, I have to take this into account using
if (builtInInit.ToString() == "Pd3.Module Init()")
but I really don’t like this solution so here’s my 2 part question
- Is there a better way of getting methods where the namespace condition is correct?
and - Why do the type.Namespace fail?
With Regard,
Stig
Types in the root namespace can have a null namespace, so it is calling
.StartsWithon a null; just eliminate those first: