Inferables.Internal.BindingRegistry.GetMapForType C# (CSharp) Method

GetMapForType() public method

public GetMapForType ( Type baseType, string name, bool isExplicitType, Stack currentStack ) : TypeFactoryMap
baseType System.Type
name string
isExplicitType bool
currentStack Stack
return TypeFactoryMap
        public TypeFactoryMap GetMapForType(Type baseType, string name, bool isExplicitType, Stack<TypeFactoryMap> currentStack)
        {
            string key = name.ToLower();
            Dictionary<string,TypeFactoryMap> typeLoaderMap = null;
            if (!typeFactoryLoaderMap.TryGetValue(baseType, out typeLoaderMap))
            {
                lock(syncLock)
                {
                    if (!typeFactoryLoaderMap.TryGetValue(baseType, out typeLoaderMap))
                    {
                        typeLoaderMap = new Dictionary<string,TypeFactoryMap>();
                        typeFactoryLoaderMap.Add(baseType,typeLoaderMap);
                    }
                }
            }

            TypeFactoryMap returnMap = null;
            if (!typeLoaderMap.TryGetValue(key, out returnMap))
            {
                lock(syncLock)
                {
                    if (!typeLoaderMap.TryGetValue(key, out returnMap))
                    {
                        if (currentStack == null)
                            currentStack = new Stack<TypeFactoryMap>();
                        if (currentStack.Any(item => item.Name.ToLowerInvariant() == key && item.BaseType == baseType))
                            throw new ArgumentException("Mapping for type '" + baseType.FullName + "' on name '" + name + "' has a circular dependency.");
                        returnMap = new TypeFactoryMap(name, baseType, isExplicitType, this);
                        currentStack.Push(returnMap);
                        returnMap.Init(currentStack);
                        currentStack.Pop();
                        typeLoaderMap.Add(key,returnMap);
                        if (returnMap.Definition.IsSingleton)
                            GetBindingFromMap(returnMap);
                    }
                }
            }

            return returnMap;
        }

Usage Example

        public CustomFactoryMethodMap(MethodInfo methodInfo, BindingRegistry registry)
        {
            string methodName = methodInfo.Name;
            if (!methodName.ToLower().StartsWith(prefix) ||
                methodInfo.GetParameters().Length > 0)
                throw new ArgumentException("Methods on custom types must start with get and must not have any parameters.");

            // TODO: Complete member initialization

            string name = methodName.Length <= prefixLength ?
                (methodInfo.ReturnType.IsInterface && methodInfo.ReturnType.Name.StartsWith("I")
                ? methodInfo.ReturnType.Name.Substring(1) : methodInfo.ReturnType.Name)
                : methodInfo.Name.Substring(prefixLength);

            this.Map = registry.GetMapForType(methodInfo.ReturnType, name, false, null);

            this.MethodInfo = methodInfo;
            this.ReturnType = this.MethodInfo.ReturnType;
        }