Example #1
0
        public void Interface_should_be_created()
        {
            mapper.Initialize(new[] { typeof(InterfaceWithProperties) });

            var result = mapper.CreateInstance <InterfaceWithProperties>(null);

            Assert.IsNotNull(result);
        }
        public object GetConcreteInstance(bool useReasonableDefaults)
        {
            var concreteType     = _messageMapper.GetMappedTypeFor(_messageType);
            var concreteInstance = _messageMapper.CreateInstance(concreteType);

            if (useReasonableDefaults)
            {
                SetReasonableDefaults(concreteInstance, _messageType);
            }
            return(concreteInstance);
        }
        public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
        {
            var jobject = JObject.Load(reader);

            var typeName = jobject.Value <string>("$type");

            var type = Type.GetType(typeName);

            var instance = _messageMapper.CreateInstance(type);

            serializer.Populate(jobject.CreateReader(), instance);

            return(instance);
        }
Example #4
0
        protected override JsonObjectContract CreateObjectContract(Type objectType)
        {
            var mappedTypeFor = _messageMapper.GetMappedTypeFor(objectType);

            if (mappedTypeFor == null)
            {
                return(base.CreateObjectContract(objectType));
            }

            var jsonContract = base.CreateObjectContract(mappedTypeFor);

            jsonContract.DefaultCreator = () => _messageMapper.CreateInstance(mappedTypeFor);

            return(jsonContract);
        }
Example #5
0
        object GetObjectOfTypeFromNode(Type t, XmlNode node)
        {
            if (t.IsSimpleType() || t == typeof(Uri))
            {
                return(GetPropertyValue(t, node));
            }

            if (typeof(IEnumerable).IsAssignableFrom(t))
            {
                return(GetPropertyValue(t, node));
            }

            var result = mapper.CreateInstance(t);

            foreach (XmlNode n in node.ChildNodes)
            {
                Type type = null;
                if (n.Name.Contains(":"))
                {
                    type = Type.GetType("System." + n.Name.Substring(0, n.Name.IndexOf(":")), false, true);
                }

                var prop = GetProperty(t, n.Name);
                if (prop != null)
                {
                    var val = GetPropertyValue(type ?? prop.PropertyType, n);
                    if (val != null)
                    {
                        var propertySet = DelegateFactory.CreateSet(prop);
                        propertySet.Invoke(result, val);
                        continue;
                    }
                }

                var field = GetField(t, n.Name);
                if (field != null)
                {
                    var val = GetPropertyValue(type ?? field.FieldType, n);
                    if (val != null)
                    {
                        var fieldSet = DelegateFactory.CreateSet(field);
                        fieldSet.Invoke(result, val);
                    }
                }
            }

            return(result);
        }
Example #6
0
        protected override JsonObjectContract CreateObjectContract(Type objectType)
        {
            var mappedTypeFor = objectType;

            if (mappedTypeFor.IsInterface)
            {
                mappedTypeFor = _mapper.GetMappedTypeFor(objectType);
            }

            if (mappedTypeFor == null)
            {
                return(base.CreateObjectContract(objectType));
            }

            var objectContract = base.CreateObjectContract(mappedTypeFor);

            objectContract.DefaultCreator = () => _mapper.CreateInstance(mappedTypeFor);

            return(objectContract);
        }
Example #7
0
        public Task <IEnumerable <string> > Query <TPaged>(Action <TPaged> query) where TPaged : IPaged
        {
            var result = _mapper.CreateInstance(query);

            return(Query(result));
        }
 public T CreateInstance <T>()
 {
     return(messageMapper.CreateInstance <T>());
 }
        public Task <IEnumerable <TResponse> > Query <TPaged, TResponse>(Action <TPaged> query)
        {
            var result = _mapper.CreateInstance(query);

            return(Query <TPaged, TResponse>(result));
        }
Example #10
0
        public Task <IEnumerable <TResponse> > Query <TQuery, TResponse>(Action <TQuery> query) where TResponse : IQueryResponse where TQuery : IQuery <TResponse>
        {
            var result = _mapper.CreateInstance(query);

            return(Query <TQuery, TResponse>(result));
        }
Example #11
0
 public Task Publish <T>(IBehaviorContext context, Action <T> messageConstructor, PublishOptions options)
 {
     return(Publish(context, typeof(T), messageMapper.CreateInstance(messageConstructor), options));
 }
Example #12
0
        public void Attributes_on_properties_should_be_mapped()
        {
            mapper.Initialize(new[] { typeof(InterfaceWithPropertiesAndAttributes) });
            Assert.IsTrue(PropertyContainsAttribute("SomeProperty", typeof(SomeAttribute), mapper.CreateInstance(typeof(InterfaceWithPropertiesAndAttributes))));

            // Doesn't affect properties without attributes
            Assert.IsFalse(PropertyContainsAttribute("SomeOtherProperty", typeof(SomeAttribute), mapper.CreateInstance(typeof(InterfaceWithPropertiesAndAttributes))));
        }