private string getMatchingType(IOutputWriter cache, string type, IEnumerable<string> usings)
 {
     foreach (var usng in usings) {
         var signature = usng + "." + type;
         if (cache.ContainsType(signature))
             return signature;
     }
     return null;
 }
Exemple #2
0
 private string getMatchingType(IOutputWriter cache, string type, IEnumerable <string> usings)
 {
     foreach (var usng in usings)
     {
         var signature = usng + "." + type;
         if (cache.ContainsType(signature))
         {
             return(signature);
         }
     }
     return(null);
 }
Exemple #3
0
        private string matchToAliases(IOutputWriter cache, string file, string type, Dictionary <string, UsingAlias[]> usingAliasesMap)
        {
            UsingAlias[] aliases;
            if (!usingAliasesMap.TryGetValue(file, out aliases))
            {
                return(null);
            }
            var match = aliases.FirstOrDefault(x => x.Name == type);

            if (match != null)
            {
                if (cache.ContainsType(match.Parent))
                {
                    return(match.Parent);
                }
                var firstMatch = cache.FirstMatchingTypeFromName(match.Parent);
                if (firstMatch != null)
                {
                    return(firstMatch);
                }
                return(match.Parent);
            }
            return(null);
        }
 private string matchToAliases(IOutputWriter cache, string file, string type, Dictionary<string,UsingAlias[]> usingAliasesMap)
 {
     UsingAlias[] aliases;
     if (!usingAliasesMap.TryGetValue(file, out aliases))
         return null;
     var match = aliases.FirstOrDefault(x => x.Name == type);
     if (match != null) {
         if (cache.ContainsType(match.Parent))
             return match.Parent;
         var firstMatch = cache.FirstMatchingTypeFromName(match.Parent);
         if (firstMatch != null)
             return firstMatch;
         return match.Parent;
     }
     return null;
 }
        public string Resolve(PartialType type, string typeToMatch)
        {
            if (!typeToMatch.Contains(".") && !typeToMatch.Contains("("))
            {
                return(null);
            }
            if (_writer.ContainsType(typeToMatch))
            {
                return(typeToMatch);
            }
            var    chunks           = getChunks(typeToMatch);
            string currentType      = null;
            string currentSignature = "";
            var    isUsing          = false;
            // As we are dealing with members we need to handle member (method/field) and it's
            // parent class/struct...
            var parents = new[] { type.Parent, getParent(type.Parent) };
            Func <string, string> typeFromSignature = _writer.VariableTypeFromSignature;

            foreach (var chunk in chunks)
            {
                // Prepare loop scoped variables to default
                isUsing          = false;
                currentSignature = appendToSignature(currentSignature, chunk);

                // Match against scoped member variables local/member
                currentType = matchToInstanceTypes(currentType, parents, typeFromSignature, chunk);

                // Match against namespaces
                if (currentType == null)
                {
                    currentType = matchToNamespaces(currentSignature);
                    isUsing     = true;
                }

                // Reset signature fetcher (only for static a single round)
                typeFromSignature = _writer.VariableTypeFromSignature;

                // Match against static containers (if not namespace it's static)
                if (currentType == null)
                {
                    currentType = resolveType(type, chunk);
                    if (currentType != null)
                    {
                        typeFromSignature = _writer.StaticMemberFromSignature;
                    }
                }

                if (currentType == null)
                {
                    return(null);
                }

                // Resolve type
                if (!isUsing)
                {
                    currentType = resolveType(type, currentType, currentType);
                }

                // Set resolved type / static class as next parent
                parents = new[] { currentType };
            }
            return(currentType);
        }