public void AddMapping(ViewMapping mapping) { if (Mappings.Keys.Contains(mapping.GetHashCode())) { var sb = new System.Text.StringBuilder("ViewMapping Key already exists for type ["); sb.Append(mapping.ViewModel); sb.Append("] with '"); sb.Append(mapping.ViewType); sb.Append("' viewType"); throw new InvalidOperationException(sb.ToString()); } Mappings.Add(mapping.GetHashCode(), mapping); }
private ViewMapping GetMapping(Type viewModel, ViewType viewType = ViewType.Display) { var viewModelMapping = new ViewMapping(viewModel, null, viewType); if (Mappings.Keys.Contains(viewModelMapping.GetHashCode())) { return(Mappings[viewModelMapping.GetHashCode()]); } var sb = new System.Text.StringBuilder("ViewModel ["); sb.Append(viewModelMapping.ViewModel); sb.Append("] was not found for ViewType "); sb.Append(viewModelMapping.ViewType); throw new KeyNotFoundException(sb.ToString()); }