public static IDictionary <string, object> ObjectToDictionary(object obj) { Guard.ArgumentNotNull(() => obj); return(FastProperty.ObjectToDictionary( obj, key => key.Replace("_", "-"))); }
public static IDictionary <string, object> ObjectToDictionary(object obj) { Guard.NotNull(obj, nameof(obj)); return(FastProperty.ObjectToDictionary( obj, key => key.Replace("_", "-"))); }
public virtual void AddModelPart(object part, MessageContext messageContext, string name = null) { var model = messageContext.Model; name = name.NullEmpty() ?? ResolveModelName(part); object modelPart = null; switch (part) { case INamedModelPart x: modelPart = x; break; case IModelPart x: MergeModelBag(x, model, messageContext); break; case Order x: modelPart = CreateModelPart(x, messageContext); break; case Domain.Entities.Data.Post x: modelPart = CreateModelPart(x, messageContext); break; } if (modelPart != null) { if (name.IsEmpty()) { throw new Exception($"Could not resolve a model key for part '{modelPart.GetType().Name}'. Use an instance of 'NamedModelPart' class to pass model with name."); } if (model.TryGetValue(name, out var existing)) { // A model part with the same name exists in model already... if (existing is IDictionary <string, object> x) { // but it's a dictionary which we can easily merge with x.Merge(FastProperty.ObjectToDictionary(modelPart)); } else { // Wrap in HybridExpando and merge var he = new HybridExpando(existing, true); he.Merge(FastProperty.ObjectToDictionary(modelPart)); model[name] = he; } } else { // Put part to model as new property model[name] = modelPart; } } }
public static IDictionary <string, object> ObjectToDictionary(object obj) { if (obj == null) { throw new ArgumentNullException(nameof(obj)); } return(FastProperty.ObjectToDictionary( obj, key => key.Replace("_", "-").Replace("@", ""))); }
public static IDictionary <string, object> ObjectToDictionary(object obj) { if (obj == null) { return(new Dictionary <string, object>()); } return(FastProperty.ObjectToDictionary( obj, key => key.Replace("_", "-").Replace("@", ""))); }
public virtual void AddModelPart(object part, MessageContext messageContext, string name = null) { Guard.NotNull(part, nameof(part)); Guard.NotNull(messageContext, nameof(messageContext)); var model = messageContext.Model; name = name.NullEmpty() ?? ResolveModelName(part); object modelPart = null; switch (part) { case INamedModelPart x: modelPart = x; break; case IModelPart x: MergeModelBag(x, model, messageContext); break; case Order x: modelPart = CreateModelPart(x, messageContext); break; case Product x: modelPart = CreateModelPart(x, messageContext); break; case Customer x: modelPart = CreateModelPart(x, messageContext); break; case Address x: modelPart = CreateModelPart(x, messageContext); break; case Shipment x: modelPart = CreateModelPart(x, messageContext); break; case OrderNote x: modelPart = CreateModelPart(x, messageContext); break; case RecurringPayment x: modelPart = CreateModelPart(x, messageContext); break; case ReturnRequest x: modelPart = CreateModelPart(x, messageContext); break; case GiftCard x: modelPart = CreateModelPart(x, messageContext); break; case NewsLetterSubscription x: modelPart = CreateModelPart(x, messageContext); break; case Campaign x: modelPart = CreateModelPart(x, messageContext); break; case ProductReview x: modelPart = CreateModelPart(x, messageContext); break; case BlogComment x: modelPart = CreateModelPart(x, messageContext); break; case NewsComment x: modelPart = CreateModelPart(x, messageContext); break; case ForumTopic x: modelPart = CreateModelPart(x, messageContext); break; case ForumPost x: modelPart = CreateModelPart(x, messageContext); break; case Forum x: modelPart = CreateModelPart(x, messageContext); break; case PrivateMessage x: modelPart = CreateModelPart(x, messageContext); break; case IEnumerable <GenericAttribute> x: modelPart = CreateModelPart(x, messageContext); break; case PollVotingRecord x: modelPart = CreateModelPart(x, messageContext); break; case ProductReviewHelpfulness x: modelPart = CreateModelPart(x, messageContext); break; case ForumSubscription x: modelPart = CreateModelPart(x, messageContext); break; case BackInStockSubscription x: modelPart = CreateModelPart(x, messageContext); break; default: var partType = part.GetType(); modelPart = part; if (partType.IsPlainObjectType() && !partType.IsAnonymous()) { var evt = new MessageModelPartMappingEvent(part); _services.EventPublisher.Publish(evt); if (evt.Result != null && !object.ReferenceEquals(evt.Result, part)) { modelPart = evt.Result; name = evt.ModelPartName.NullEmpty() ?? ResolveModelName(evt.Result) ?? name; } else { modelPart = part; } modelPart = evt.Result ?? part; name = evt.ModelPartName.NullEmpty() ?? name; } break; } if (modelPart != null) { if (name.IsEmpty()) { throw new SmartException($"Could not resolve a model key for part '{modelPart.GetType().Name}'. Use an instance of 'NamedModelPart' class to pass model with name."); } if (model.TryGetValue(name, out var existing)) { // A model part with the same name exists in model already... if (existing is IDictionary <string, object> x) { // but it's a dictionary which we can easily merge with x.Merge(FastProperty.ObjectToDictionary(modelPart), true); } else { // Wrap in HybridExpando and merge var he = new HybridExpando(existing, true); he.Merge(FastProperty.ObjectToDictionary(modelPart), true); model[name] = he; } } else { // Put part to model as new property model[name] = modelPart; } } }