private static bool ValidateInternalRecursive(LicenseContext context, Type type, object instance, bool allowExceptions, out License license, out string licenseKey)
{
LicenseProvider provider = GetCachedProvider(type);
if (provider == null && !GetCachedNoLicenseProvider(type))
{
// NOTE : Must look directly at the class, we want no inheritance.
//
LicenseProviderAttribute attr = (LicenseProviderAttribute)Attribute.GetCustomAttribute(type, typeof(LicenseProviderAttribute), false);
if (attr != null)
{
Type providerType = attr.LicenseProvider;
provider = GetCachedProviderInstance(providerType);
if (provider == null)
{
provider = (LicenseProvider)SecurityUtils.SecureCreateInstance(providerType);
}
}
CacheProvider(type, provider);
}
license = null;
bool isValid = true;
licenseKey = null;
if (provider != null)
{
license = provider.GetLicense(context, type, instance, allowExceptions);
if (license == null)
{
isValid = false;
}
else
{
// For the case where a COM client is calling "RequestLicKey",
// we try to squirrel away the first found license key
//
licenseKey = license.LicenseKey;
}
}
// When looking only at a type, we need to recurse up the inheritence
// chain, however, we can't give out the license, since this may be
// from more than one provider.
//
if (isValid && instance == null)
{
Type baseType = type.BaseType;
if (baseType != typeof(object) && baseType != null)
{
if (license != null)
{
license.Dispose();
license = null;
}
string temp;
isValid = ValidateInternalRecursive(context, baseType, null, allowExceptions, out license, out temp);
if (license != null)
{
license.Dispose();
license = null;
}
}
}
return isValid;
}