无法调用需要Type参数的c#方法

时间:2016-07-11 18:53:09

标签: c# enums

在这个问题上尝试另一种方法:Attempting to use OOPFactory to parse 271 benefits using EligibilityBenefitDocument

这一次,我试图使用库的不同部分来编写存在于sql中的内容,而不是尝试直接使用该对象。

我正在尝试执行OOPFactory.X12.ImportX12类。

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Configuration;
using OopFactory.X12.Parsing;
using OopFactory.X12.Repositories;
using OopFactory.X12.Sql;
using System.IO;
using System.Diagnostics;
namespace OopFactory.X12.ImportX12
{
    class Program
    {
        enum testc { incrementme };
        static void Main(string[] args)
    {
        string dsn = ConfigurationManager.ConnectionStrings["X12"].ConnectionString;

        bool throwExceptionOnSyntaxErrors = ConfigurationManager.AppSettings["ThrowExceptionOnSyntaxErrors"] == "true";
        string[] segments = ConfigurationManager.AppSettings["IndexedSegments"].Split(',');
        string parseDirectory = ConfigurationManager.AppSettings["ParseDirectory"];
        string parseSearchPattern = ConfigurationManager.AppSettings["ParseSearchPattern"];
        string archiveDirectory = ConfigurationManager.AppSettings["ArchiveDirectory"];
        string failureDirectory = ConfigurationManager.AppSettings["FailureDirectory"];
        string sqlDateType = ConfigurationManager.AppSettings["SqlDateType"];
        int segmentBatchSize = Convert.ToInt32(ConfigurationManager.AppSettings["SqlSegmentBatchSize"]);

        var specFinder = new SpecificationFinder();
        var parser = new X12Parser(throwExceptionOnSyntaxErrors);
        parser.ParserWarning += new X12Parser.X12ParserWarningEventHandler(parser_ParserWarning);
        var repo = new SqlTransactionRepository<int>(dsn, specFinder, segments, ConfigurationManager.AppSettings["schema"], ConfigurationManager.AppSettings["containerSchema"], segmentBatchSize, sqlDateType);

        //var repo = new OopFactory.X12.Sql.SqlTransactionRepository(dsn,"test");
        //var repo = new OopFactory.X12.Sql.SqlTransactionRepository(dsn,new testc());

开箱即用,我收到错误'OopFactory.X12.Repositories.SqlTransationRepository'已过时:'使用OopFactory.X12.Sql库和命名空间'

尝试响应,我在顶部添加一个using子句来导入该命名空间并尝试直接调用该方法(如我在repo变量的注释调用中所示)。

  • 当我尝试给它一个字符串apss时,它告诉我“'OopFactory.X12.Sql.SqlTransactionRepository ....'的最佳重载方法匹配有一些无效的参数
  • 当我尝试传入一个枚举实例时,我也明白了。

我的问题是:如何调用需要System.Type参数的方法?

如果您能告诉我他们实际期望将哪些响应传递给SqlTransactionRepository的方法签名

,我也肯定会对前几个可以正确指出的响应进行投票。
public SqlTransactionRepository(string dsn, Type identityType)
        : this(dsn, new SpecificationFinder(), new[] { "REF", "NM1", "N1", "N3", "N4", "DMG", "PER" }, identityType, "dbo")
    {
    }

2 个答案:

答案 0 :(得分:0)

Lets say that your Type is Person,

You can use typeof(Person):

 SqlTransactionRepository(dsn, typeof(Person));

Or get the type of an instance of person:

 Person p = new Person();
 SqlTransactionRepository(dsn, p.GetType());

答案 1 :(得分:0)

According to the documentation inside the source code (OopFactory X12 Parser)

The identity parameter should have:

the type of all identity columns

and it supports either int or long, meaning you should pass either:

typeof(int)

or

typeof(long)

Hope it helps!