magic-string

ASP.net MVC Action URLs with lambda expression

I'm sure I have seen this syntax <%= Url.Action((MyController c) => c.MyMethod("a")) %> or something like it as a way to generate action URLs in ASP.net MVCs without magic strings. However, I can't find that Action overload. I have ASP.NET MVC 1.0. Where is it? ...

Decouple the screens without magic strings

My WPF project will be organised like this : Screens Group1 Screen1 View.xaml ViewModel.cs Group2 Screen2 View.xaml ViewModel.cs To show the Screen1 from the Screen2 I'll use something like this: ScreenManager.Show("Group1.Screen1") This looks (using reflection) in the Screens.Grou...

An "elegant" way of identifying a field?

Hi. I'm writing a system that underlies programmer applications and that needs to detect their access to certain data. I can mostly do so with properties, like this: public class NiceClass { public int x { get; set; } } Then I go in and tweak the get and set accessors so that they handle the accesses appropriately. However this r...

.Net - Strategies to avoid magic string

In the code where I work, we got many think like that : if (user.HasRight("Profile.View")) {} So, there is many place where we pass a string as parameter to see if the user have a specific right. I don't like that because that generate a lot of magic string. What would be a better way of doing it ? Enum, Constant, class ? ...

Using a lambda expression to avoid using a "magic string" to specify a property

I am writing a service to take a collection of objects of a particular type and output its primitive, string, and DateTime types to a string in CSV Format. I have both of the below statements working. I find the the lambda based version to be much cleaner. Magic String Version string csv = new ToCsvService<DateTime>(objs) .Exclude(...

Getting magic strings out of QueryOver (or Fluent NHibernate perhaps)?

One of the many reason to use FluentNHibernate, the new QueryOver API, and the new Linq provider are all because they eliminate "magic string," or strings representing properties or other things that could be represented at compile time. Sadly, I am using the spatial extensions for NHibernate which haven't been upgraded to support Query...

How can I remove magic strings from custom model binders?

I've written a couple of custom model binders now, and have realised that I've fallen into the trap of relying on magic strings, e.g.: if (bindingContext.ValueProvider.ContainsPrefix("PaymentKey")) { paymentKey = bindingContext.ValueProvider.GetValue("PaymentKey").AttemptedValue; } I'd like to be able to use an exp...