基于具有匹配唯一字符串的UniqueID快速引用对象 [英] Quick referencing of objects based on UniqueID with a matching Unique string

查看:83
本文介绍了基于具有匹配唯一字符串的UniqueID快速引用对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用OpcNetApi库,并且脑子里有一个难题。

我有一个对象[MyObject],它是Items [type Item]的集合,基类型为ItemId,我用来创建订阅;,读取值得到返回[type ItemValue ]使用基类型ItemId,使其成为[MyObjectValues]。

这些类型Item和类型ItemValue中的每一个都有一个Correlated UniqueID来匹配它们。



我有多个被称为MyObject的对象它由多个项目组成。 [基本上是由一个对象数组组成的数组] List<列表与LT; T> > 其中列表< T> 是MyObjectItems, List<列表与LT; T> > 是MyObjects的封装列表。



我还应该添加每个Item或ItemValue需要有一个对应的propertyName(所以我可以绑定PropertyName(对于我在网格中的列,ItemValue.Value作为列值),因此网格的一行将包含 List< T> ,并且其他行是列表< T> 的列表。





我正在做两个带有结果数据的东西,绑定到winforms应用程序以及更新数据库。

为了快速找到这些列表中的一个项目,这种方案最适合哪种方法,这样我的OnChangeEvent可能会来使用一个ItemValue可以快速访问确切的项目,设置其值,并允许我与Winform绑定自动反映新值。



简单是最好的,事实上是真的好,最好的两个世界甚至更好。

小样品,良好的提示,良好的读数都是受欢迎的,提前你。

I am working with the OpcNetApi libraries, and have a conundrum in my mind.
I have an object [MyObject] that is a collection of Items [type Item] with base type ItemId, which I use to create a subscription;, to read the values I get a return [type ItemValue] with base type ItemId so that becomes [MyObjectValues].
Each of these type Item and type ItemValue has a Correlated UniqueID to match them up.

I have multiple objects that are known as MyObject which consists of multiple Items. [Basically an Array consisting of an Array of Objects] List< List<T> > where List<T> is the MyObjectItems, and List< List<T> > is an encapsulating list of MyObjects.

I should also add that each Item or ItemValue needs to have a corresponding propertyName (so I can bind PropertyName (for my column in a grid, ItemValue.Value for the column value) so a row of the grid would consist of the List<T> and additional rows are the list of the List<T> .


I am doing two things with the resultant data, binding to a winforms application and also updating a database.
What kinds of approaches are best for this scenario in order to quickly find one item in those lists so my OnChangeEvent which may come with one ItemValue can quickly access the exact item, set its value and also allow me to bind with Winform reflecting the new values automagically.

Simple is best, fact is really good, best of both worlds even better.
Small samples , good hints , good reads are all welcome , thank you in advance.

推荐答案

我通常在List< t>中实现。对象一个自定义的this方法,例如:



I usually implement in the List<t> object a custom "this" method, for example:

public class MyItemCollection : List<Item>
{
  ....

  public Item this[String itemID]
  {
     foreach(Item i in this)
     {
        if(Item.ItemID == itemID) return i;
     }
     // return null if Item not found for supplied itemID
     return null;
  }

  ....
}





然后你可以拨打电话喜欢



Then you can make calls like

MyObjectCollection col = new MyObjectCollection();
// Populate collection

String itemID = "MyItem";
Item item = col[itemID];


这篇关于基于具有匹配唯一字符串的UniqueID快速引用对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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