使用C#读取ALM自定义字段数据 [英] Read ALM custom fields data using C#

查看:60
本文介绍了使用C#读取ALM自定义字段数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





使用以下链接,我使用c#读取HP ALM数据,在ALM中一些自定义字段也在那里我无法读取自定义文件,你能不能帮助我们。





QC DATA PULLER使用C# [ ^ ] 3



谢谢!



我尝试了什么:



使用以下代码,我可以阅读所有字段代码。



Hi,

Using below link, i read HP ALM data using c#, In ALM some custom fields also there i am unable to read custom fileds, can you help us.


QC DATA PULLER using C#[^]3

Thank You!

What I have tried:

Using below code i am able to read all fields code.

foreach (IBug thisBug in bugL)
                        {
                            dsbug.Tables[0].Rows.Add(thisBug.ID, thisBug.Summary, thisBug.Status, thisBug.AssignedTo, thisBug.DetectedBy, thisBug.ToString(), thisBug.Priority);
}





在实体中,IBug类的代码如下。





In Entities, IBug class has below code.

[DefaultMember("Field")]
    [Guid("2AF970F7-6CCC-4DFB-AA78-08F689481F94")]
    [TypeLibType(4160)]
    public interface IBug : IBaseFieldExMail
    {
        [DispId(0)]
        dynamic this[string FieldName] { get; set; }
        [DispId(20)]
        string AssignedTo { get; set; }
        [DispId(12)]
        dynamic Attachments { get; }
        [DispId(5)]
        bool AutoPost { get; set; }
        [DispId(23)]
        List ChangeLinks { get; }
        [DispId(19)]
        string DetectedBy { get; set; }
        [DispId(13)]
        bool HasAttachment { get; }
        [DispId(22)]
        bool HasChange { get; }
        [DispId(11)]
        dynamic History { get; }
        [DispId(4)]
        dynamic ID { get; }





使用foreach(bugL中的IBug thisBug),我能够读取所有字段,除了动态[string FieldName]。动态这个[field]有自定义字段,我需要读取动态这个值。



如何在类文件中阅读下面的实体。



Using foreach (IBug thisBug in bugL), i am able to read all fields, except dynamic this[string FieldName]. dynamic this["field"] has custom fields, i need to read dynamic this value.

How to read below entity in class file.

dynamic this[string FieldName]

推荐答案

首先,您已发布界面而非类代码。请使用类代码更新问题



其次,您尝试阅读的字段实际上是一个索引器。您可以在此处阅读有关索引器的信息: MSDN [ ^ ]。从链接:

First, you have posted the interface and not class code. Please update the question with the class code.

Second, the "field" you are trying to read is a actually an indexer. You can read about indexers here:MSDN[^]. From the link:
Quote:

索引器允许类或结构的实例像数组一样被索引。索引器类似于属性,除了它们的访问器接受参数。

Indexers allow instances of a class or struct to be indexed just like arrays. Indexers resemble properties except that their accessors take parameters.





查看您发布的代码,这是我的内容可以假设可以在课堂上完成:





Looking at the code you have posted, here is what I can assume might be done in the class:

static class Program
{
    static void Main(string[] args)
    {

        BugClass classObj = new BugClass();

        classObj.Id = 1;
        classObj.Name = "First";

        int firstId = classObj["Id"];
        string firstName = classObj["Name"];

        Console.Read();
    }
}


public interface IBug
{
    dynamic this[string FieldName] { get; set; }

    int Id { get; set; }

    string Name { get; set; }

}

class BugClass:IBug
{

    public dynamic this[string FieldName]
    {
        get
        {
            return this.GetType().GetProperty(FieldName).GetValue(this);
        }
        set
        {
            this.GetType().GetProperty(FieldName).SetValue(this, value);
        }
    }

    public int Id
    {
        get;
        set;
    }

    public string Name
    {
        get;
        set;
    }
}





这里,动态这个本身并没有真正拥有任何东西。它只是一种替代类属性的替代方法。只要您从属性中读取所有值,您的代码就可以了。



Here, dynamic this itself does not really hold anything. It merely is an alternate way to play around with class properties. As long as you are reading all the values from the properties, your code should be fine.


这篇关于使用C#读取ALM自定义字段数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆