private object CreateInstance(TypeIndex tIndex, Binder.BaseTypeConfig cTarget) { // try to resolve the type from the custom resolvers object resolvedObject = m_binder.ResolveType(tIndex.Type); if (resolvedObject != null) { CheckConfigForObject(cTarget, resolvedObject); return resolvedObject; } if (cTarget == null) { // for not binded types, find the most suitable constructor if (!m_notBindedConstructorList.ContainsKey(tIndex.Type)) { ConstructorInfo constructor = FindConstructor(tIndex.Type); if (constructor == null) { throw new Exceptions.UnboundTypeException(); } else { var expr = CreateExpressionConstructor(constructor, ci => ci.GetParameters().Select(p => CreateParameterExpression(p)).ToArray()); m_notBindedConstructorList.Add(tIndex.Type, Expression.Lambda<Func<object>>(expr).Compile()); } } return m_notBindedConstructorList[tIndex.Type](); } else { // create the object from the binded configuration if (cTarget.Constructor == null) { CreateConstructor(cTarget); } var obj = cTarget.Constructor(); if (cTarget.ConstructorType == Binder.BaseTypeConfig.ConstructorTypeConfig.Action) { cTarget.ConstructorAction(obj); } return obj; } }
private void CheckConfigForObject(Binder.BaseTypeConfig tConfig, object resolvedObject) { if (tConfig == null) return; if (tConfig.ConstructorType == Binder.BaseTypeConfig.ConstructorTypeConfig.Action) { tConfig.ConstructorAction(resolvedObject); } }