public static IEnumerable <ExtensionReference> GenerateExtensionReferences(string fileName, ConsoleLogger logger) { BaseAssemblyResolver resolver = new DefaultAssemblyResolver(); resolver.AddSearchDirectory(Path.GetDirectoryName(fileName)); ReaderParameters readerParams = new ReaderParameters { AssemblyResolver = resolver }; AssemblyDefinition assembly = AssemblyDefinition.ReadAssembly(fileName, readerParams); var startupAttributes = assembly.Modules.SelectMany(p => p.GetCustomAttributes()) .Where(a => IsWebJobsStartupAttributeType(a.AttributeType, logger)); List <ExtensionReference> extensionReferences = new List <ExtensionReference>(); foreach (var attribute in startupAttributes) { var typeProperty = attribute.ConstructorArguments.ElementAtOrDefault(0); var nameProperty = attribute.ConstructorArguments.ElementAtOrDefault(1); TypeDefinition typeDef = (TypeDefinition)typeProperty.Value; string assemblyQualifiedName = Assembly.CreateQualifiedName(typeDef.Module.Assembly.FullName, GetReflectionFullName(typeDef)); string name; // Because we're now using static analysis we can't rely on the constructor running so have to get the name ourselves. if (string.Equals(attribute.AttributeType.FullName, FunctionsStartupAttributeType, StringComparison.OrdinalIgnoreCase)) { // FunctionsStartup always uses the type name as the name. name = typeDef.Name; } else { // WebJobsStartup does some trimming. name = GetName((string)nameProperty.Value, typeDef); } var extensionReference = new ExtensionReference { Name = name, TypeName = assemblyQualifiedName }; extensionReferences.Add(extensionReference); } return(extensionReferences); }
public static IEnumerable <ExtensionReference> GenerateExtensionReferences(Assembly assembly) { var startupAttributes = assembly.GetCustomAttributes().Where(a => string.Equals(a.GetType().FullName, WebJobsStartupAttributeType, StringComparison.OrdinalIgnoreCase)); List <ExtensionReference> extensionReferences = new List <ExtensionReference>(); foreach (var attribute in startupAttributes) { var nameProperty = attribute.GetType().GetProperty("Name"); var typeProperty = attribute.GetType().GetProperty("WebJobsStartupType"); var extensionReference = new ExtensionReference { Name = (string)nameProperty.GetValue(attribute), TypeName = ((Type)typeProperty.GetValue(attribute)).AssemblyQualifiedName }; extensionReferences.Add(extensionReference); } return(extensionReferences); }