728x90
        private dynamic SafeField(Func<dynamicfunc)
        {
            try
            {
                return func();
            }
            catch (System.NullReferenceException ex)             

            {

                 return "(Not set)";
            }
            catch (System.InvalidOperationException ex)

             {

                //LINQ 시퀀스에 요소가 없습니다.
                //if(ex.Message == "시퀀스에 요소가 없습니다.") .... todo?
                return "(Not data)";
            }
            catch (System.Exception ex)
            {
                return null;
            }
        }

 

사용법

txtREQUIREMENT.Text = SafeField(() => data.REQUIREMENT.NAME);

 

728x90
Posted by kjun.kr
,