Click here to Skip to main content
15,891,951 members
Home / Discussions / C#
   

C#

 
AnswerRe: how to show/hide forms ? Pin
Pete O'Hanlon1-Nov-06 9:41
mvePete O'Hanlon1-Nov-06 9:41 
AnswerRe: how to show/hide forms ? Pin
Rahithi1-Nov-06 10:44
Rahithi1-Nov-06 10:44 
GeneralRe: how to show/hide forms ? Pin
Ashraf zia1-Nov-06 15:34
Ashraf zia1-Nov-06 15:34 
GeneralRe: how to show/hide forms ? Pin
Rahithi2-Nov-06 4:08
Rahithi2-Nov-06 4:08 
AnswerRe: how to show/hide forms ? Pin
Haseeb Mukhtar1-Nov-06 19:15
Haseeb Mukhtar1-Nov-06 19:15 
AnswerRe: how to show/hide forms ? Pin
quiteSmart1-Nov-06 20:03
quiteSmart1-Nov-06 20:03 
AnswerRe: how to show/hide forms ? Pin
shaz jazz1-Nov-06 20:08
shaz jazz1-Nov-06 20:08 
QuestionPropertyInfo SetValue doesn't work for custom objects. Pin
Matt Casto1-Nov-06 8:00
Matt Casto1-Nov-06 8:00 
I'll start my problem description off with some sample code which will probably do the best job at illustrating the problem.

using System;<br />
<br />
namespace TestCustomTypePropertySetValue<br />
{<br />
  public class CustomThing<br />
  {<br />
    public CustomThing(string input)<br />
    {<br />
      m_input = input;<br />
    }<br />
<br />
    public string Input<br />
    {<br />
      get { return m_input; }<br />
    }<br />
    private string m_input;<br />
<br />
    public override string ToString()<br />
    {<br />
      return this.Input;<br />
    }<br />
<br />
    public static implicit operator CustomThing(string input)<br />
    {<br />
      return new CustomThing(input);<br />
    }<br />
<br />
    public static implicit operator string(CustomThing thing)<br />
    {<br />
      return thing.ToString();<br />
    }<br />
  }<br />
<br />
  public class ClassWithThing<br />
  {<br />
    public CustomThing Thing<br />
    {<br />
      get { return m_thing; }<br />
      set { m_thing = value; }<br />
    }<br />
    private CustomThing m_thing = new CustomThing("default");<br />
  }<br />
<br />
  class Class1<br />
  {<br />
    [STAThread]<br />
    static void Main(string[] args)<br />
    {<br />
      // set a custom thing to a string - this works<br />
      CustomThing thing = "test custom thing input";<br />
      <br />
      // set a string to a custom thing - this works<br />
      string input = thing;<br />
<br />
      // a property of type CustomThing<br />
      ClassWithThing cwt = new ClassWithThing();<br />
      System.Reflection.PropertyInfo propInfo =<br />
        cwt.GetType().GetProperty("Thing");<br />
<br />
      // set the property to a string value - this fails<br />
      propInfo.SetValue(cwt, "test input", null);<br />
    }<br />
  }<br />
}


The last line in my sample code (PropertyInfo.SetValue) throws the exception "Object type cannot be converted to target type." If you run the sample code, you might notice that the SetValue doesn't even call the implicit conversion from string to CustomThing. WTF | :WTF:

I'm getting this exception in code where I don't know the type of the property that I'm calling SetValue() on, and I'd rather not have to hack in a check for my custom type. Does anyone have any ideas on how to do this? Confused | :confused:
AnswerRe: PropertyInfo SetValue doesn't work for custom objects. Pin
Xint01-Nov-06 8:43
Xint01-Nov-06 8:43 
GeneralRe: PropertyInfo SetValue doesn't work for custom objects. Pin
Matt Casto1-Nov-06 8:57
Matt Casto1-Nov-06 8:57 
QuestionSteganography Pin
Musharaf Zaheer Qureshi1-Nov-06 7:05
Musharaf Zaheer Qureshi1-Nov-06 7:05 
AnswerRe: Steganography Pin
led mike1-Nov-06 7:48
led mike1-Nov-06 7:48 
AnswerRe: Steganography Pin
Eric Dahlvang1-Nov-06 12:25
Eric Dahlvang1-Nov-06 12:25 
QuestionDouble / String Conversion Problem Pin
Rick van Woudenberg1-Nov-06 6:41
Rick van Woudenberg1-Nov-06 6:41 
AnswerRe: Double / String Conversion Problem Pin
led mike1-Nov-06 7:54
led mike1-Nov-06 7:54 
AnswerRe: Double / String Conversion Problem Pin
Luc Pattyn1-Nov-06 7:59
sitebuilderLuc Pattyn1-Nov-06 7:59 
AnswerRe: Double / String Conversion Problem Pin
Rick van Woudenberg1-Nov-06 11:20
Rick van Woudenberg1-Nov-06 11:20 
GeneralRe: Double / String Conversion Problem Pin
Stefan Troschuetz1-Nov-06 21:44
Stefan Troschuetz1-Nov-06 21:44 
AnswerRe: Double / String Conversion Problem Pin
Martin#1-Nov-06 23:15
Martin#1-Nov-06 23:15 
Questionorg.pdfbox Pin
Member19781-Nov-06 6:21
Member19781-Nov-06 6:21 
QuestionDisable desktop short cuts Pin
aseef1-Nov-06 6:04
aseef1-Nov-06 6:04 
AnswerRe: Disable desktop short cuts Pin
Judah Gabriel Himango1-Nov-06 13:14
sponsorJudah Gabriel Himango1-Nov-06 13:14 
Questionredirect to another form Pin
minibansal1-Nov-06 5:52
minibansal1-Nov-06 5:52 
AnswerRe: redirect to another form Pin
Christian Graus1-Nov-06 6:12
protectorChristian Graus1-Nov-06 6:12 
GeneralRe: redirect to another form Pin
led mike1-Nov-06 7:55
led mike1-Nov-06 7:55 

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.