private async Task <object> AugmentInternal( object obj, Type type, Action <IState> addState, Action <AugmentationContext, object> configure, object configureState) { var tiw = TypeInfoResolver.ResolveTypeInfo(type); if (tiw.IsPrimitive) { return(obj); } var alwaysBuild = tiw.IsWrapper || configure != null; var typeConfiguration = ResolveTypeConfiguration(tiw.Type, alwaysBuild); if (typeConfiguration == null && configure == null) { // No configuration return(obj); } var state = await CreateDictionaryAndAddStateAsync(addState, obj); var context = new AugmentationContext(obj, typeConfiguration, state); if (tiw.IsArray) { var asEnumerable = obj as IEnumerable; var list = (obj as IList) != null ? new List <object>((obj as IList).Count) : new List <object>(); Debug.Assert(asEnumerable != null, "asEnumerable != null"); foreach (var item in asEnumerable) { // We'll reuse the context. context.Object = item; list.Add(AugmentOne(obj, configure, configureState, tiw, context)); } return(list); } else if (tiw.IsWrapper && ReflectionHelper.IsEnumerableOrArrayType((((AugmenterWrapper)obj).Object).GetType(), out var elementType)) { context.EphemeralTypeConfiguration = ((AugmenterWrapper)obj).TypeConfiguration; obj = (((AugmenterWrapper)obj).Object); tiw = TypeInfoResolver.ResolveTypeInfo(elementType); var asEnumerable = obj as IEnumerable; var list = (obj as IList) != null ? new List <object>((obj as IList).Count) : new List <object>(); foreach (var item in asEnumerable) { // We'll reuse the context. context.Object = item; list.Add(AugmentOne(obj, configure, configureState, tiw, context)); } return(list); } else { return(AugmentOne(obj, configure, configureState, tiw, context)); } }
protected override object AugmentCore(AugmentationContext context) { var obj = context.Object; var root = new AObject(); var typeConfigurations = BuildList(context.TypeConfiguration, context.EphemeralTypeConfiguration); CopyAndAugmentObject(obj, typeConfigurations, root, context.State, null, null); return(root); }
protected override object AugmentCore(AugmentationContext context) { var obj = context.Object; var root = new AObject(); foreach (var typeConfiguration in BuildList(context.TypeConfiguration, context.EphemeralTypeConfiguration)) { AugmentObject(obj, typeConfiguration, root, context.State); } return(root); }
private object AugmentOne( object obj, Action <AugmentationContext, object> configure, object configureState, TypeInfoWrapper tiw, AugmentationContext context) { if (tiw.IsWrapper) { context.Object = ((AugmenterWrapper)obj).Object; context.EphemeralTypeConfiguration = ((AugmenterWrapper)obj).TypeConfiguration; } configure?.Invoke(context, configureState); return(AugmentCore(context)); }
public virtual object AugmentCorePublic(AugmentationContext context) { Contexts.Add(context); return(context.Object); }
protected override object AugmentCore(AugmentationContext context) { return(AugmentCorePublic(context)); }
protected abstract object AugmentCore(AugmentationContext context);