コード例 #1
0
        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));
            }
        }
コード例 #2
0
        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);
        }
コード例 #3
0
        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);
        }
コード例 #4
0
        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));
        }
コード例 #5
0
 public virtual object AugmentCorePublic(AugmentationContext context)
 {
     Contexts.Add(context);
     return(context.Object);
 }
コード例 #6
0
 protected override object AugmentCore(AugmentationContext context)
 {
     return(AugmentCorePublic(context));
 }
コード例 #7
0
 protected abstract object AugmentCore(AugmentationContext context);