public T Get()
        {
            // Create the object
            var createdObject = mType.CreateObject(mContext);

            // And overrides
            var typeContext = new GenerationContext(mContext.Builders, new TypeGenerationContextNode(mContext.Node, createdObject));

            foreach (var action in mOverrides)
            {
                action.Enact(typeContext, createdObject);
            }

            // And return the created object
            return((T)createdObject);
        }
        private IResultPatternProxy CreateProxyToObject(MethodInfo targetMethod, object result)
        {
            var returnType    = GetMethodReturnType(targetMethod);
            var dynamicResult = _objectBuilder.CreateObject(CreateTypeName(returnType), null, returnType, new[] { typeof(IResultPatternProxy) }, true) as IResultPatternProxy;

            if (result != null)
            {
                var mapperConfiguration = new AutoMapper.MapperConfiguration(config => config.CreateMap(returnType, dynamicResult.GetType()));
                var mapper = new AutoMapper.Mapper(mapperConfiguration);

                mapper.Map(result, dynamicResult);
                dynamicResult.IsNull = false;

                var hh = returnType.IsAssignableFrom(dynamicResult.GetType());
            }

            dynamicResult.IsNull = true;

            return(dynamicResult);
        }
Beispiel #3
0
            private object GetObject(IObjectSetting setting, Type expectedType)
            {
                var            builderName = setting.Builder;
                IObjectBuilder builder     = null;

                if (!string.IsNullOrEmpty(builderName))
                {
                    builder = this.GetServiceInternal <IObjectBuilder>(builderName);
                }
                var ctx = new ObjectBuildContext(this, setting, builder, null);

                this.OnObjectBuilding(ctx);
                if (ctx.ObjectInstance == null && builder != null)
                {
                    ctx.ObjectInstance = builder.CreateObject(setting);
                }
                if (ctx.ObjectInstance == null)
                {
                    var mapTo = this.GetTypeNameInternal(setting.MapTo);
                    if (!string.IsNullOrEmpty(mapTo))
                    {
                        ctx.ObjectInstance = TypeHelper.CreateObject(mapTo, expectedType, true);
                    }
                    else
                    {
                        var typeName = this.GetTypeNameInternal(setting.TypeName);
                        if (!string.IsNullOrEmpty(typeName))
                        {
                            ctx.ObjectInstance = TypeHelper.CreateObject(typeName, expectedType, true);
                        }
                        else
                        {
                            throw new ConfigException("type attribute is required in <object />");
                        }
                    }
                }
                this.OnObjectBuilt(ctx);
                return(ctx.ObjectInstance);
            }