0

a我正在尝试使用反射来检索 Microsoft.Office.Interop.Excel.Series 对象的属性。代码执行时没有错误,但仅返回部分属性列表(与 ...Series 对象的对象浏览器中列出的属性相比)。查看 ...Series 对象的运行时监视列表时,完整列表显示在“动态视图”下。我发现的文档指出这些是动态成员,不可编辑。是否可以使用反射来访问动态成员?

我在 Office 2013 Professional Plus 上使用 Windows 8.1、VS 2013。我有很强的 VBA 背景,约 1 年 C# 经验。

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);
    }      
  }
}
4

0 回答 0