Axiom.Runtime.AMPredicateSet.LoadExternalPredicate C# (CSharp) Method

LoadExternalPredicate() private method

private LoadExternalPredicate ( string path, string pname ) : IAbstractMachinePredicate
path string
pname string
return IAbstractMachinePredicate
        private IAbstractMachinePredicate LoadExternalPredicate(string path, string pname)
        {
            // Load assembly
            Assembly assembly = Assembly.LoadFrom(path);

            if (assembly == null)
            {
                throw new Exception("Error loading external predicate from " + path);
            }

            // Verify that the class implements IAbstractMachinePredicate
            foreach (Type classType in assembly.GetTypes())
            {
                foreach (Type implementedInterface in classType.GetInterfaces())
                {
                    if (implementedInterface.ToString() == "Axiom.Runtime.IAbstractMachinePredicate")
                    {
                        object [] attributes = classType.GetCustomAttributes(typeof(PredicateNameAttribute), false);

                        if (attributes != null)
                        {
                            if (((PredicateNameAttribute)attributes[0]).Name == pname)
                            {
                                // create and return instance of this class type
                                return (IAbstractMachinePredicate)Activator.CreateInstance(classType.UnderlyingSystemType);
                            }
                        }
                    }
                }
            }
            return null;
        }