0

aI am trying to use reflection to retrieve the properties of a Microsoft.Office.Interop.Excel.Series object. The code executes with no errors, but only a partial listing of the properties is returned (when compared to the properties listed in the Object Browser for the ...Series object). When looking at a runtime watch listing of the ...Series object, the full listing is displayed under "Dynamic View". Documentation that I have found states that these are Dynamic Members and are not available for editing. Is it possible to use reflection to access the Dynamic Members ?

I am using Windows 8.1, VS 2013 on Office 2013 Professional Plus. I have a strong VBA Background, ~1 year C# experience.

public void LoadProperties(dynamic SourceObject, dynamic TargetObject)
{
  Type sourcetype = SourceObject.GetType();
  Type targettype = TargetObject.GetType();

  if(sourcetype.Equals(targettype))
  {
    PropertyInfo[] properties = typeof(Microsoft.Office.Interop.Excel.Series).GetProperties();
    foreach (PropertyInfo property in properties)
    {
      object propertyvalue = property.GetValue(SourceObject);
      sourcetype.GetProperty(property.Name, BindingFlags.Public | BindingFlags.Instance | BindingFlags.Static | 
                             BindingFlags.NonPublic ).SetValue(TargetObject,propertyvalue);
    }      
  }
}
Soner Gönül
  • 97,193
  • 102
  • 206
  • 364
  • 2
    Open the References node in your project, select Microsoft.Office.Interop.Excel and set the "Embed Interop Types" property to False. Makes this code work. Then think for a while if you *really* want to do that. You don't. You already know what properties it has, you can see them in VS. – Hans Passant Jun 30 '15 at 08:21
  • Thanks for the response. Setting the "Embed Interop Types" property to False returns all of the properties of the series object. – bob smith Jul 05 '15 at 03:22
  • The reason that I am enumerating through the series object is because I want to set one series properties equal to another series properties (with the exception of unique properties line name, formula, ...). Thought this would be the cleanest way. Thanks again for your help. – bob smith Jul 05 '15 at 03:48

0 Answers0