Esempio n. 1
0
 /// <summary>
 /// Clears the properties of this instance.
 /// </summary>
 internal void Reset(bool childs = true, bool remove = true, bool collectionId = true, bool record = true, bool map = true)
 {
     Completed = false;
     if (childs)
     {
         ChildDependencies.Clear();
     }
     if (remove && _UberMap != null && !_UberMap.IsDisposed)
     {
         _UberMap.MetaEntities.Remove(this);
     }
     if (collectionId)
     {
         CollectionId = null;
     }
     if (record)
     {
         Record = null;
     }
     if (map)
     {
         UberMap = null;
     }
 }
Esempio n. 2
0
        /// <summary>
        /// Resolves child properties of an object through the engine
        /// </summary>
        /// <typeparam name="T">Any class</typeparam>
        /// <param name="o">The object to resolve the properties of</param>
        /// <param name="resolutionPackage">Information to be used when resolving types</param>
        /// <returns>The passed in object with resolved properties (just in case)</returns>
        public static T ResolveProperties <T>(T o, ResolutionPackage resolutionPackage)
        {
            if (resolutionPackage is null)
            {
                throw new ArgumentNullException(nameof(resolutionPackage));
            }

            Type oType = o.GetType();

            if (!ChildDependencies.ContainsKey(oType))
            {
                ChildDependencies.TryAdd(oType, oType.GetProperties().Where(p => Attribute.IsDefined(p, typeof(DependencyAttribute))).ToList());
            }

            foreach (PropertyInfo thisDependency in ChildDependencies[oType])
            {
                if (!AnyRegistration(thisDependency.PropertyType))
                {
                    Type defaultType = thisDependency.GetCustomAttribute <DependencyAttribute>().Default;

                    thisDependency.SetValue(o, Resolve(
                                                new Registration()
                    {
                        ServiceProvider = typeof(TransientServiceProvider),
                        RegisteredType  = thisDependency.PropertyType,
                        ToInstantiate   = defaultType ?? thisDependency.PropertyType
                    }, resolutionPackage).SingleOrDefault());
                }
                else
                {
                    thisDependency.SetValue(o, Resolve(thisDependency.PropertyType, resolutionPackage, true));
                }
            }

            return(o);
        }