如何将参数类型设置为类型对象的通用列表

时间:2019-05-21 14:27:45

标签: c# .net generic-list

我使用c#.net创建了一个类库文件。当我调用该方法时,它显示以下提到的错误。定义对象类型的列表参数以纠正此错误的正确方法是什么。我已附上我的代码和错误以供参考。

using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Activities;
using System.ComponentModel;
using Microsoft.Office.Interop.Word;


namespace ReadWord
{
    class MyObject
    {
        public string Name { get; set; }
        public string Value { get; set; }
        public string Title { get; set; }
        public string Tag { get; set; }
    }
    public class ReadWord : CodeActivity
    {
[Category("Output")]
        public OutArgument<System.Collections.Generic.List> FieldValueOnly { get; set; }

        protected override void Execute(CodeActivityContext context)
        {
            var a = DocPath.Get(context);
            var list = new List<MyObject>();
            Microsoft.Office.Interop.Word.Application word = new Microsoft.Office.Interop.Word.Application();
            Microsoft.Office.Interop.Word.Document doc = word.Documents.Open(a);

            doc.Activate();
            foreach (InlineShape shape in doc.InlineShapes)
                {
                    if (shape.OLEFormat != null && shape.OLEFormat.ClassType == "Forms.TextBox.1")
                    {
                        //Console.WriteLine(shape.OLEFormat.Object.Name + " :" + shape.OLEFormat.Object.Value);
                        //text += shape.OLEFormat.Object.Value;
                        //ArrField[shape.OLEFormat.Object.Name] = shape.OLEFormat.Object.Value;
                        list.Add(new MyObject { Name = shape.OLEFormat.Object.Name, Value = shape.OLEFormat.Object.Value, Title = "", Tag = ""});
                    }

                }
                FieldValueOnly.Set(context, list);
            }
            word.Quit();
         }
       }
    }

我收到此错误消息'System.InvalidOperationException:类型'System.Collections.Generic.List`1 [ReadWord.MyObject]'的值不能设置为名称为'FieldValueOnly'的位置,因为它是类型“ System.Collections.Generic.List”的位置。”

0 个答案:

没有答案