Exemple #1
0
 internal void StoreInstance(object instance, Type type, GetInstanceMembersDelegate getInstanceMembers)
 {
     if (!_typedInstances.ContainsKey(type))
     {
         _typedInstances.Add(type, instance);
     }
     foreach (MemberInfo member in getInstanceMembers(instance, type))
     {
         SetValue(member.Name, member.GetValue(instance));
     }
 }
Exemple #2
0
        internal object GetInstance(Type type, GetInstanceMembersDelegate getInstanceMembers)
        {
            object instance;

            if (_typedInstances.ContainsKey(type))
            {
                instance = _typedInstances[type];
            }
            else
            {
                instance = Activator.CreateInstance(type);
                _typedInstances.Add(type, instance);
            }
            foreach (MemberInfo member in getInstanceMembers(instance, type))
            {
                if (ContainsKey(member.Name))
                {
                    member.SetValue(instance, GetValue(member.Name));
                }
            }
            return(instance);
        }