/// <summary> /// Generate a source data cooker reference from a given type. /// </summary> /// <param name="candidateType"> /// Data extension type. /// </param> /// <param name="reference"> /// Data extension reference. /// </param> /// <returns> /// <c>true</c> if succeeded, <c>false</c> otherwise. /// </returns> public bool TryCreateSourceDataCookerReference( Type candidateType, out ISourceDataCookerReference reference) { Guard.NotNull(candidateType, nameof(candidateType)); return(SourceDataCookerReference.TryCreateReference(candidateType, out reference)); }
internal static bool TryCreateReference( Type candidateType, out ISourceDataCookerReference reference) { Guard.NotNull(candidateType, nameof(candidateType)); reference = null; // perform this basic check first, as it's cheaper than a more specific test below if (!candidateType.Implements(typeof(IDataCooker))) { return(false); } if (!candidateType.IsInstantiatable()) { // this is ok, could just be an abstract base class for a data cooker return(false); } if (!candidateType.GetInterfaces().Any( i => i.IsGenericType && i.GetGenericTypeDefinition() == typeof(ISourceDataCooker <, ,>))) { // this is ok, it might be some other type of data cooker return(false); } if (!candidateType.IsPublic()) { Console.Error.WriteLine( $"Warning: type {candidateType} seems to be a source data cooker, but is not public."); return(false); } // There must be an empty, public constructor if (!candidateType.TryGetEmptyPublicConstructor(out var constructor)) { Console.Error.WriteLine( $"Warning: type {candidateType} seems to be a data cooker, but is missing an empty public " + "constructor."); return(false); } try { reference = new SourceDataCookerReference(candidateType); } catch (Exception e) { Console.Error.WriteLine($"Cooker Disabled: {candidateType}."); Console.Error.WriteLine($"{e.Message}"); return(false); } return(true); }
public bool AddSourceDataCookerReference(ISourceDataCookerReference dataCooker) { Guard.NotNull(dataCooker, nameof(dataCooker)); bool addedCooker; lock (this.dataCookerReferencesBySource) { if (!this.dataCookerReferencesBySource.ContainsKey(dataCooker.Path.SourceParserId)) { this.dataCookerReferencesBySource.Add(dataCooker.Path.SourceParserId, new HashSet <ISourceDataCookerFactory>()); } addedCooker = this.dataCookerReferencesBySource[dataCooker.Path.SourceParserId].Add(dataCooker); if (addedCooker) { this.sourceDataCookerReferencesByPath[dataCooker.Path] = dataCooker; } } return(addedCooker); }
/// <summary> /// Creates an <see cref="ISourceDataCookerReference"/> for a given type. /// </summary> /// <remarks> /// This will not add the generated reference to a cooker repository, and the cooker's data will not be /// available through the standard cooker framework. /// </remarks> /// <param name="candidateType"> /// Type that represents a source data cooker. /// </param> /// <param name="reference"> /// A reference to a source data cooker for the given type. /// </param> /// <returns> /// <c>true</c> if a reference was generated; otherwise <c>false</c> /// </returns> public static bool TryCreateReference( Type candidateType, out ISourceDataCookerReference reference) { return(SourceDataCookerReference.TryCreateReference(candidateType, out reference)); }