43 lines
1.3 KiB
C#
43 lines
1.3 KiB
C#
using System;
|
|
using ln.types.btree;
|
|
using System.Collections.Generic;
|
|
namespace ln.types.reflection
|
|
{
|
|
public class ObjectPool
|
|
{
|
|
public Type ObjectType { get; }
|
|
public Type IdentityType { get; }
|
|
|
|
public TypeDescriptor TypeDescriptor => TypeDescriptor.GetDescriptor(ObjectType);
|
|
|
|
Func<object, object> getIdentity;
|
|
public object GetIdentity(object o) => getIdentity(o);
|
|
|
|
BTree<object, object> objects = new BTree<object, object>();
|
|
|
|
List<ObjectPool> derivedTypes = new List<ObjectPool>();
|
|
|
|
public ObjectPool(Type objectType, Type identityType, Func<object, object> getIdentityDelegate)
|
|
{
|
|
ObjectType = objectType;
|
|
IdentityType = identityType;
|
|
getIdentity = getIdentityDelegate;
|
|
}
|
|
|
|
public IEnumerable<object> Identities => objects.Keys;
|
|
public IEnumerable<object> Instances => objects.Values;
|
|
|
|
public object this[object identity] => objects[identity];
|
|
|
|
public void Add(object o) => objects.Add(GetIdentity(o), o);
|
|
public void Remove(object identity) => objects.Remove(identity);
|
|
|
|
|
|
public ObjectPoolValue GetValue(string attributePath) => throw new NotImplementedException();
|
|
|
|
public void AddDerivedTypePool(ObjectPool objectPool) => derivedTypes.Add(objectPool);
|
|
|
|
|
|
}
|
|
}
|