String Extension


hello,

i found following extensions:

    public static bool isnullorempty<t>(this ienumerable<t> value) {        return value == null || value.count() == 0;      }        public static ienumerable<t> throwifnullorempty<t>(this ienumerable<t> item, string name) {        if (item.isnullorempty())          throw new argumentnullexception(name);        return item;      }

and applied follows:

    public static string mymethod(string value, string key) {        value.throwifnullorempty("value");      }

how can applied string. logical?

should have extension ienumerable , string?

thank you,

miguel

they designing write multiple criteria in fluent style, ie:

    param1.throwifnullorempty().throwiflengthlessthan(3);

that being said, type of thing, i'd use existing library.  cuttingedge.conditions handles of these cases quite nicely.  you can through old discussions (very good/valid) reasons they're not using extension methods on base types string/ienumerable<t>, too...


reed copsey, jr. - http://reedcopsey.com
if post answers question, please click "mark answer" on post , "mark helpful".



Visual Studio Languages  ,  .NET Framework  >  Visual C#



Comments

Popular posts from this blog

Azure DocumentDB Owner resource does not exist

job syspolicy_purge_history job fail in sqlserver 2008

Trying to register with public marketplace error with 'Get-AzureStackStampInformation'