-2

リストがあり、リストが入力された後に2つの新しいプロパティを追加したいと思います。

これはできますか?

C#リスト

List<Usp_GetListItemsBySystemResult> PendingListOfItemsToControl = new List<Usp_GetListItemsBySystemResult>(); // Items to Control in Running memory 

// Get items to Control into running memory
FAItemsUnderControl fItemsUnderControl = new FAItemsUnderControl(ConfigurationManager.AppSettings["DatabaseConnectionString"]);
PendingListOfItemsToControl = fItemsUnderControl.getItemsUnderControl(DropDownListSystems.Text.ToString(), "ALL").ToList<Usp_GetListItemsBySystemResult>();

// Add new paramaters to the list here ????????

追加するC#の新しいプロパティ

    public string ItemRequestStatus { get; set; } // Determines the change status if applicable
    public bool IsButtonEnabled { get; set; } // Determines if the delete button is enabled or disabled

C#クラス

public class Usp_GetListItemsBySystemResult
{
    public Usp_GetListItemsBySystemResult();

    public DateTime? Creation_DateTime { get; set; }
    public string Item_Backup_Location { get; set; }
    public string Item_Category { get; set; }
    public short? Item_Check_Interval_Time { get; set; }
    public DateTime? Item_Creation_DateTime { get; set; }
    public DateTime? Item_Last_Access_DateTime { get; set; }
    public DateTime? Item_Last_Modified_DateTime { get; set; }
    public string Item_Name { get; set; }
    public string Item_Path { get; set; }
    public int? Item_Size { get; set; }
    public string Item_Status { get; set; }
    public string Item_Value { get; set; }
    public string Item_Value_SHA256 { get; set; }
    public int? ItemUnderControl_ID { get; set; }
}
4

3 に答える 3

1

MyListから継承されたこれらの2つのプロパティを使用して、独自のクラスを作成する必要がありますList。このようなもの:

public class MyList<T> : List<T>
{
    public string ItemRequestStatus { get; set; } // Determines the change status if applicable
    public bool IsButtonEnabled { get; set; } // Determines if the delete button is enabled or disabled

    public MyList()
    {

    }

    public MyList(IList<T> list)
        : base(list)
    {

    }
}

利用方法:

FAItemsUnderControl fItemsUnderControl = new FAItemsUnderControl(ConfigurationManager.AppSettings["DatabaseConnectionString"]);
var list = fItemsUnderControl.getItemsUnderControl(DropDownListSystems.Text.ToString(), "ALL").ToList<Usp_GetListItemsBySystemResult>();
MyList<Usp_GetListItemsBySystemResult> PendingListOfItemsToControl = new MyList<Usp_GetListItemsBySystemResult>(list);
于 2013-01-14T19:40:10.277 に答える
1

このクラスを作成し、Linqを使用して、この新しいプロパティに値を追加できます。

List<NewClass> = from x in GetListItemsBySystemResult 
                select new NewClass{
                  Creation_DateTime = x.Creation_DateTime ,
                  ...,
                  ItemRequestStatus = "Value",
                  IsButtonEnabled = "Value",
                  };

次に、この新しいリストに新しい値を入力しました。

于 2013-01-14T19:50:17.483 に答える
1

Expandoオブジェクトを作成し、必要なものを追加できます。

var myx = new ExpandoObject() as IDictionary<string, Object>;
myx.Add("NewProp", string.Empty);
于 2013-01-14T20:16:10.117 に答える