Пример #1
0
    public static List <KeyValuePair <int, T> > GenerateIDList <T, T2>(List <T2> baseList) where T : class where T2 : class
    {
        int l = baseList.Count;

        if (l > 0)
        {
            if (PropertyUtils.HasProperty <T2>("key") && PropertyUtils.HasProperty <T2>("value"))
            {
                List <KeyValuePair <int, T> > list = new List <KeyValuePair <int, T> >();
                for (int i = 0; i < l; i++)
                {
                    T2  obj   = baseList[i];
                    int key   = (int)PropertyUtils.GetPropertyValue(obj, "key");
                    T   value = (T)PropertyUtils.GetPropertyValue(obj, "value");
                    KeyValuePair <int, T> pair = new KeyValuePair <int, T>(key, value);
                    list.Add(pair);
                }
                return(list);
            }
            else
            {
                Debug.LogError("property \"key\" or \"value\" doesn't exist in " + typeof(T2));
                return(null);
            }
        }
        else
        {
            return(null);
        }
    }
Пример #2
0
    /// <summary>
    /// Find obj by testing a property equality
    /// </summary>
    /// <param name="propertyName">Property tested</param>
    /// <param name="value">Tested value for equality</param>
    /// <returns></returns>
    public List <T> Find(string propertyName, object value)
    {
        List <T> foundList = new List <T>();

        foreach (KeyValuePair <string, T> item in _namedObjs)
        {
            if (PropertyUtils.HasProperty <T>(propertyName))
            {
                if (value.Equals(PropertyUtils.GetPropertyValue(item.Value, propertyName)))
                {
                    foundList.Add(item.Value);
                }
            }
        }
        return(foundList);
    }