private ProcessorType(Type type, ProcessorField[] fields, ContentProcessorAttribute attrib) { Type = type; var genArgs = type.BaseType.GetGenericArguments(); InputType = genArgs[0]; OutputType = genArgs[1]; WriterType = genArgs[2]; Fields = fields; Attribute = attrib; }
private void findPipelineEntries(ProjectReference reference) { // Search through the assembly and find content importers and processors. Assembly assembly = Assembly.LoadFrom(reference.StoredReference); foreach (Type type in assembly.GetTypes()) { foreach (object attribute in type.GetCustomAttributes(true)) { if (attribute is ContentImporterAttribute) { ContentImporterAttribute ia = attribute as ContentImporterAttribute; if (ia.DisplayName != null && ia.DisplayName != string.Empty) { importers.Add(new ContentImporterInfo(type.Name, ia.DisplayName, ia.FileExtensions, ia.DefaultProcessor, ia.CacheImportedData)); } else { importers.Add(new ContentImporterInfo(type.Name, type.Name, ia.FileExtensions, ia.DefaultProcessor, ia.CacheImportedData)); } } else if (attribute is ContentProcessorAttribute) { ContentProcessorAttribute pa = attribute as ContentProcessorAttribute; if (pa.DisplayName != null && pa.DisplayName != string.Empty) { processors.Add(new ContentProcessorInfo(type.Name, pa.DisplayName)); } else { processors.Add(new ContentProcessorInfo(type.Name, type.Name)); } } } } }
public ProcessorInfo(ContentProcessorAttribute attribute, Type type) { Attribute = attribute; Type = type; }
// Attempts to create an ProcessorType out of a passed type, will return null if it is invalid public static ProcessorType TryCreate(BuildEngine engine, Type type) { // Check if it is derived from IContentProcessor if (type.GetInterface(INTERFACE_NAME) == null) { return(null); } // Must have the correct attribute ContentProcessorAttribute attrib = (ContentProcessorAttribute)type.GetCustomAttributes(ATTRIBUTE_TYPE, false)?.FirstOrDefault(); if (attrib == null) { engine.Logger.EngineError($"The type '{type.FullName}' is a ContentProcessor but is missing the required attribute."); return(null); } if (!attrib.Enabled) { engine.Logger.EngineInfo($"Skipping ContentProcessor type '{type.FullName}' - it is marked as disabled."); return(null); } // Validate the attribute information if (attrib.DisplayName == null) { TypeError(engine, type, "cannot have a null display name."); return(null); } // Ensure some required type info if (type.IsAbstract) { TypeError(engine, type, "is abstract and cannot be instantiated."); return(null); } if (type.GetConstructor(BindingFlags.Instance | BindingFlags.Public, null, CallingConventions.HasThis, new Type[0], null) == null) { TypeError(engine, type, "does not have a public no-args constructor, and cannot be instantiated."); return(null); } // Validate the specified content writer Type writerType = type.BaseType.GetGenericArguments()[2]; if (writerType.IsAbstract) { WriterError(engine, writerType, "is abstract and cannot be instantiated."); return(null); } if (writerType.GetConstructor(BindingFlags.Instance | BindingFlags.Public, null, CallingConventions.HasThis, new Type[0], null) == null) { WriterError(engine, writerType, "does not have a public no-args constructor, and cannot be instantiated."); return(null); } // Get the fields var fields = ProcessorField.LoadFromType(engine, type); if (fields == null) { return(null); } // Good to go return(new ProcessorType(type, fields, attrib)); }