Click here to Skip to main content
15,896,606 members
Home / Discussions / C#
   

C#

 
GeneralRe: Reflection for non public type in Unit Testing Pin
Member 91405152-Mar-16 19:18
Member 91405152-Mar-16 19:18 
GeneralRe: Reflection for non public type in Unit Testing Pin
Bernhard Hiller2-Mar-16 20:42
Bernhard Hiller2-Mar-16 20:42 
AnswerRe: Reflection for non public type in Unit Testing Pin
BillWoodruff2-Mar-16 2:53
professionalBillWoodruff2-Mar-16 2:53 
GeneralRe: Reflection for non public type in Unit Testing Pin
Member 91405152-Mar-16 19:37
Member 91405152-Mar-16 19:37 
QuestionInput format was not in correct format for int? Followed by "Invalid expression term try" Pin
Sam 91001-Mar-16 8:26
Sam 91001-Mar-16 8:26 
AnswerRe: Input format was not in correct format for int? Followed by "Invalid expression term try" Pin
Eddy Vluggen1-Mar-16 9:07
professionalEddy Vluggen1-Mar-16 9:07 
GeneralRe: Input format was not in correct format for int? Followed by "Invalid expression term try" Pin
Sam 91001-Mar-16 12:08
Sam 91001-Mar-16 12:08 
QuestionRe: Input format was not in correct format for int? Followed by "Invalid expression term try" Pin
Matt T Heffron1-Mar-16 13:35
professionalMatt T Heffron1-Mar-16 13:35 
Eddie's right about the code smell of the try with an empty catch. Use int.TryParse to determine if there's a parsing error.
If value.Value is an empty string then the parsing will fail.
(Since you aren't getting a NullReferenceException on the .ToString() it means that value.Value isn't null.)
So what you should do first is to check value.Value for being empty.
C#
/// <summary>
/// Parse a set of values into an instance of tbl_Mine_MineGroup using Reflection
/// </summary>
public static tbl_Location ParseLocation(IOrderedDictionary values)
{
  tbl_Location locFromValues = new tbl_Location();
  Type locType = typeof(tbl_Location);    // we KNOW this
            
  // use reflection to update properties, because I'm lazy
  foreach (DictionaryEntry value in values)
  {
    string key = value.Key as string;
    if (key == null)
      throw new InvalidOperationException(string.Format("Key is not a string: {0}", value.Key);
    string val = value.Value as string;
    bool emptyValue = string.IsNullOrEmpty(val);
    object storableValue = null;

    if (key.Equals("Latitude") || key.Equals("Longitude"))
    {
      double parsed;
      // if the parse fails treat it the same as empty and leave storableValue null
      if (!emptyValue && double.TryParse(val, out parsed))
        storableValue = parsed; 
    }
    else if (key.Contains("ID"))
    {
      int parsed;
      // if the parse fails treat it the same as empty and leave storableValue null
      if (!emptyValue && int.TryParse(val, out parsed))
        storableValue = parsed; 
    }
    else
    {
      storableValue = val;
    }
    // storableValue has null or the "boxed" values of the parsed numeric values or the string
    // this is equivalent to using double? and int? above
    locType.GetProperty(key).SetValue(locFromValues, storableValue);
  }
 
  return locFromValues;
}

All of a sudden you mention TextBox.
The TextBox's .Text property expects a string value.
So where is the value from the PostID property of the tbl_Location get put into this TextBox's .Text property you mention?
That is probably where the "null" from "parsing" the empty string gets displayed.
"Fairy tales do not tell children the dragons exist. Children already know that dragons exist. Fairy tales tell children the dragons can be killed."
- G.K. Chesterton

AnswerRe: Input format was not in correct format for int? Followed by "Invalid expression term try" Pin
Sam 91003-Mar-16 4:28
Sam 91003-Mar-16 4:28 
QuestionWhy getting Error :Column name doesn't belong to table Pin
Veena Hosur29-Feb-16 23:32
Veena Hosur29-Feb-16 23:32 
QuestionRe: Why getting Error :Column name doesn't belong to table Pin
Richard MacCutchan1-Mar-16 0:00
mveRichard MacCutchan1-Mar-16 0:00 
AnswerRe: Why getting Error :Column name doesn't belong to table Pin
Veena Hosur1-Mar-16 0:08
Veena Hosur1-Mar-16 0:08 
GeneralRe: Why getting Error :Column name doesn't belong to table Pin
Richard MacCutchan1-Mar-16 0:25
mveRichard MacCutchan1-Mar-16 0:25 
AnswerRe: Why getting Error :Column name doesn't belong to table Pin
Richard MacCutchan1-Mar-16 0:06
mveRichard MacCutchan1-Mar-16 0:06 
SuggestionRe: Why getting Error :Column name doesn't belong to table Pin
Sascha Lefèvre1-Mar-16 0:13
professionalSascha Lefèvre1-Mar-16 0:13 
GeneralRe: Why getting Error :Column name doesn't belong to table Pin
Luc Pattyn1-Mar-16 2:35
sitebuilderLuc Pattyn1-Mar-16 2:35 
GeneralRe: Why getting Error :Column name doesn't belong to table Pin
Sascha Lefèvre1-Mar-16 2:49
professionalSascha Lefèvre1-Mar-16 2:49 
QuestionData Access Layer for C# Pin
levanduyet_vn29-Feb-16 21:44
levanduyet_vn29-Feb-16 21:44 
AnswerRe: Data Access Layer for C# Pin
Richard MacCutchan29-Feb-16 21:55
mveRichard MacCutchan29-Feb-16 21:55 
GeneralRe: Data Access Layer for C# Pin
levanduyet_vn29-Feb-16 22:16
levanduyet_vn29-Feb-16 22:16 
GeneralRe: Data Access Layer for C# Pin
Richard MacCutchan29-Feb-16 22:32
mveRichard MacCutchan29-Feb-16 22:32 
AnswerRe: Data Access Layer for C# Pin
Pete O'Hanlon29-Feb-16 22:10
mvePete O'Hanlon29-Feb-16 22:10 
GeneralRe: Data Access Layer for C# Pin
levanduyet_vn29-Feb-16 22:14
levanduyet_vn29-Feb-16 22:14 
GeneralRe: Data Access Layer for C# Pin
Pete O'Hanlon29-Feb-16 22:30
mvePete O'Hanlon29-Feb-16 22:30 
GeneralRe: Data Access Layer for C# Pin
levanduyet_vn29-Feb-16 22:48
levanduyet_vn29-Feb-16 22:48 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.