Why Possible System.NullReferenceException ?
От: Какая разница Украина  
Дата: 27.03.14 12:12
Оценка:
Hi All!

ReSharper 8.1.23.546
Visual Studio 2013

Показывает сабжевый хинт на выделенный StartWith

Label — string property

 Label = doc.GetType().InvokeMember("FullName", BindingFlags.GetProperty, null, doc, null) as string;
                    if (!string.IsNullOrEmpty(Label) && Label.StartsWith(@"@:\"))
                    {
                        var ext = Path.GetExtension(Label);
                        if (!string.IsNullOrEmpty(ext))
                        {
                            var index = ext.IndexOf('_');
                            if (index >= 0)
                                Label = Label.Substring(0, Label.Length - (ext.Length - index));
                        }
                    }
!0xDEAD
Re: Why Possible System.NullReferenceException ?
От: UberPsychoSvin  
Дата: 27.03.14 12:57
Оценка:
Здравствуйте, Какая разница, Вы писали:


КР>Hi All!


КР>ReSharper 8.1.23.546

КР>Visual Studio 2013

КР>Показывает сабжевый хинт на выделенный StartWith


КР>Label — string property


КР>
КР> Label = doc.GetType().InvokeMember("FullName", BindingFlags.GetProperty, null, doc, null) as string;
КР>                    if (!string.IsNullOrEmpty(Label) && Label.StartsWith(@"@:\"))
КР>                    {
КР>                        var ext = Path.GetExtension(Label);
КР>                        if (!string.IsNullOrEmpty(ext))
КР>                        {
КР>                            var index = ext.IndexOf('_');
КР>                            if (index >= 0)
КР>                                Label = Label.Substring(0, Label.Length - (ext.Length - index));
КР>                        }
КР>                    }
КР>


private string Label
{
  get { return null; }
  set { throw new NotImplementedException(); }
}
Re[2]: Why Possible System.NullReferenceException ?
От: Какая разница Украина  
Дата: 27.03.14 13:01
Оценка:
UPS>
UPS>private string Label
UPS>{
UPS>  get { return null; }
UPS>  set { throw new NotImplementedException(); }
UPS>}
UPS>


ага как раз мой случай
!0xDEAD
Re: Why Possible System.NullReferenceException ?
От: Kalina9001  
Дата: 27.03.14 16:20
Оценка:
Здравствуйте, Какая разница, Вы писали:

КР>Показывает сабжевый хинт на выделенный StartWith


КР>Label — string property


Теоритически значение может поменяться между вызовами

КР>
КР> Label = doc.GetType().InvokeMember("FullName", BindingFlags.GetProperty, null, doc, null) as string;
КР>                    if (!string.IsNullOrEmpty(Label) && Label.StartsWith(@"@:\"))
КР>                    {
КР>                        var ext = Path.GetExtension(Label);
КР>                        if (!string.IsNullOrEmpty(ext))
КР>                        {
КР>                            var index = ext.IndexOf('_');
КР>                            if (index >= 0)
КР>                                Label = Label.Substring(0, Label.Length - (ext.Length - index));
КР>                        }
КР>                    }
КР>




var label = Label;
if (!string.IsNullOrEmpty(label) && label.StartsWith(@"@:\"))
{
  var ext = Path.GetExtension(label);
  if (!string.IsNullOrEmpty(ext))
    {
        var index = ext.IndexOf('_');
        if (index >= 0)
            Label = label.Substring(0, label.Length - (ext.Length - index));
    }
}
... << RSDN@Home 1.2.0 alpha 5 rev. 56>>
Re: Why Possible System.NullReferenceException ?
От: itslave СССР  
Дата: 15.04.14 16:36
Оценка:
Здравствуйте, Какая разница, Вы писали:


КР>Hi All!


КР>ReSharper 8.1.23.546

КР>Visual Studio 2013

КР>Показывает сабжевый хинт на выделенный StartWith


КР>Label — string property


КР>
КР> Label = doc.GetType().InvokeMember("FullName", BindingFlags.GetProperty, null, doc, null) as string;
КР>                    if (!string.IsNullOrEmpty(Label) && Label.StartsWith(@"@:\"))
КР>                    {
КР>                        var ext = Path.GetExtension(Label);
КР>                        if (!string.IsNullOrEmpty(ext))
КР>                        {
КР>                            var index = ext.IndexOf('_');
КР>                            if (index >= 0)
КР>                                Label = Label.Substring(0, Label.Length - (ext.Length - index));
КР>                        }
КР>                    }
КР>
 
Подождите ...
Wait...
Пока на собственное сообщение не было ответов, его можно удалить.