public void Load(Type compiledStylesheet)
{
Reset();
if (compiledStylesheet == null)
throw new ArgumentNullException(nameof(compiledStylesheet));
object[] customAttrs = compiledStylesheet.GetCustomAttributes(typeof(GeneratedCodeAttribute), /*inherit:*/false);
GeneratedCodeAttribute generatedCodeAttr = customAttrs.Length > 0 ? (GeneratedCodeAttribute)customAttrs[0] : null;
// If GeneratedCodeAttribute is not there, it is not a compiled stylesheet class
if (generatedCodeAttr != null && generatedCodeAttr.Tool == typeof(XslCompiledTransform).FullName)
{
if (new Version(Version).CompareTo(new Version(generatedCodeAttr.Version)) < 0)
{
throw new ArgumentException(SR.Format(SR.Xslt_IncompatibleCompiledStylesheetVersion, generatedCodeAttr.Version, Version), nameof(compiledStylesheet));
}
FieldInfo fldData = compiledStylesheet.GetField(XmlQueryStaticData.DataFieldName, BindingFlags.Static | BindingFlags.NonPublic);
FieldInfo fldTypes = compiledStylesheet.GetField(XmlQueryStaticData.TypesFieldName, BindingFlags.Static | BindingFlags.NonPublic);
// If private fields are not there, it is not a compiled stylesheet class
if (fldData != null && fldTypes != null)
{
// Retrieve query static data from the type
byte[] queryData = fldData.GetValue(/*this:*/null) as byte[];
if (queryData != null)
{
MethodInfo executeMethod = compiledStylesheet.GetMethod("Execute", BindingFlags.Static | BindingFlags.NonPublic);
Type[] earlyBoundTypes = (Type[])fldTypes.GetValue(/*this:*/null);
// Load the stylesheet
Load(executeMethod, queryData, earlyBoundTypes);
return;
}
}
}
// Throw an exception if the command was not loaded
if (_command == null)
throw new ArgumentException(SR.Format(SR.Xslt_NotCompiledStylesheet, compiledStylesheet.FullName), nameof(compiledStylesheet));
}