/// <summary> /// Construct a parameter using its attribute's value. /// </summary> /// <param name="context"></param> /// <param name="pipeline"></param> /// <returns></returns> public virtual object Construct(ConstruktionContext context, ConstruktionPipeline pipeline) { var attribute = (T)context.ParameterInfo.GetCustomAttribute(typeof(T)); var value = _value(attribute); return(value); }
public object Construct(ConstruktionContext requestContext) { var blueprint = _blueprints.First(x => x.Matches(requestContext)); var result = construct(requestContext, blueprint); return(result); }
/// <summary> /// Get detailed log information about the way Construktion is constructing your objects. DO NOT use for normal operations. Should be used for ad hoc debugging only. /// </summary> /// <returns></returns> public object DebuggingConstruct(ConstruktionContext context, out string log) { var pipeline = new DebuggingConstruktionPipeline(_settings); var result = pipeline.DebugSend(context, out List <string> debugLog); log = string.Join("\n", debugLog); return(result); }
private object construct(ConstruktionContext requestContext, Blueprint blueprint) { if (_recurssionGuard.Contains(requestContext.RequestType)) { return(default(object)); } _recurssionGuard.Add(requestContext.RequestType); var result = blueprint.Construct(requestContext, this); _recurssionGuard.Remove(requestContext.RequestType); return(result); }
/// <summary> /// The base implementation returns true if the parameter has the attribute. /// </summary> /// <param name="context"></param> /// <returns></returns> public virtual bool Matches(ConstruktionContext context) => context.ParameterInfo?.GetCustomAttributes(typeof(T)) .ToList() .Any() ?? false;
/// <summary> /// Construct an object of T. /// </summary> /// <param name="context"></param> /// <param name="pipeline"></param> /// <returns></returns> public abstract T Construct(ConstruktionContext context, ConstruktionPipeline pipeline);
/// <inheritdoc /> object Blueprint.Construct(ConstruktionContext context, ConstruktionPipeline pipeline) => Construct(context, pipeline);
/// <summary> /// Matches types of the closed generic. Can be overridden in derived classes. /// </summary> /// <param name="context"></param> /// <returns></returns> public virtual bool Matches(ConstruktionContext context) => true;
/// <inheritdoc /> bool Blueprint.Matches(ConstruktionContext context) => context.RequestType == typeof(T) && Matches(context);
public bool Matches(object item, ConstruktionContext context) => typeof(T).IsAssignableFrom(context.RequestType) && Matches((T)item, context);