title: How to set an Int16 value to a Nullable<Enum> property using reflection?
body: <p>I need to do this:-</p>
  
  <p><strong>MyClass.cs</strong></p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Text;
  
  namespace set_property__Enum_To_Nullable_Enum
  {
      public enum MyEnum : short
      {
          One, 
          Two, 
          Three 
      }
  
      public class MyClass
      {
          public string MyStringProperty { get; set; }
          public MyEnum? MyEnumProperty { get; set; }
  
          public void ShowAll(string message)
          {
              Console.WriteLine(message);            
              Console.WriteLine("String   = " + MyStringProperty);
              Console.WriteLine("Enum   = " + MyEnumProperty.Value);
          }
      }
  }
  </code></pre>
  
  <p><strong>Program.cs</strong></p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Text;
  using System.Reflection;
  
  namespace set_property__Enum_To_Nullable_Enum
  {
      class Program
      {
          static void Main(string[] args)
          {
              //Names
              string myAssemblyName = "MyAssembly";
              string myNamespaceName = "set_property__Enum_To_Nullable_Enum";
              string myClassName = "MyClass";
              string propertyNameOne = "MyStringProperty";
              string propertyNameTwo = "MyEnumProperty";
  
              //Data            
              string myString = "Hello World!";
              short myInteger = 1;
  
              //Preprocessing
              Assembly myAssmbly = Assembly.Load(myAssemblyName);
              Type myType = myAssmbly.GetType(myNamespaceName + "." + myClassName);
  
              //Create class-instance
              object objectInstance = Activator.CreateInstance(myType);
  
              //Set property-values
              PropertyInfo propertyInfoOne = myType.GetProperty(propertyNameOne);
              propertyInfoOne.SetValue(objectInstance, myString, null);
  
              PropertyInfo propertyInfoTwo = myType.GetProperty(propertyNameTwo);
              propertyInfoTwo.SetValue(objectInstance, myInteger, null);//&lt;---------------
  
              //Call method
              myType.InvokeMember("ShowAll",
                                          BindingFlags.InvokeMethod | BindingFlags.Instance | BindingFlags.Public,
                                          null,
                                          objectInstance,
                                          new object[] { "My name is Khan" });
  
              string end = string.Empty;
          }
      }
  }
  </code></pre>
  
  <p>But Int32 value is not automatically converted to MyEnum. </p>
  
  <p>At the specific line, an exception is being generated.</p>
  
  <pre><code>Object of type 'System.Int16' cannot be converted to type 'System.Nullable`1[set_property__Enum_To_Nullable_Enum.MyEnum]'.
  </code></pre>
  
  <p>How to do it?</p>
  
  <h1>Edit</h1>
  
  <p>I need further help please!</p>
  
  <p>Enum.ToObject() can not handle null.</p>