Esempio n. 1
0
 internal void AddUsing(string @namespace)
 {
     if (Using == null)
     {
         Using = new List <string>();
     }
     if (Using.Contains(@namespace))
     {
         return;
     }
     Using.Add(@namespace);
 }
Esempio n. 2
0
        private void WriteNonGenericClrType(StringBuilder sb, string s)
        {
            // map model types
            s = Regex.Replace(s, @"\{(.*)\}\[\*\]", m => ModelsMap[m.Groups[1].Value + "[]"]);

            // takes care eg of "System.Int32" vs. "int"
            if (TypesMap.TryGetValue(s, out string typeName))
            {
                sb.Append(typeName);
                return;
            }

            // if full type name matches a using clause, strip
            // so if we want Umbraco.Core.Models.IPublishedContent
            // and using Umbraco.Core.Models, then we just need IPublishedContent
            typeName = s;
            string typeUsing = null;
            var    p         = typeName.LastIndexOf('.');

            if (p > 0)
            {
                var x = typeName.Substring(0, p);
                if (Using.Contains(x))
                {
                    typeName  = typeName.Substring(p + 1);
                    typeUsing = x;
                }
                else if (x == ModelsNamespace) // that one is used by default
                {
                    typeName  = typeName.Substring(p + 1);
                    typeUsing = ModelsNamespace;
                }
            }

            // nested types *after* using
            typeName = typeName.Replace("+", ".");

            // symbol to test is the first part of the name
            // so if type name is Foo.Bar.Nil we want to ensure that Foo is not ambiguous
            p = typeName.IndexOf('.');
            var symbol = p > 0 ? typeName.Substring(0, p) : typeName;

            // what we should find - WITHOUT any generic <T> thing - just the type
            // no 'using' = the exact symbol
            // a 'using' = using.symbol
            var match = typeUsing == null ? symbol : (typeUsing + "." + symbol);

            // if not ambiguous, be happy
            if (!IsAmbiguousSymbol(symbol, match))
            {
                sb.Append(typeName);
                return;
            }

            // symbol is ambiguous
            // if no 'using', must prepend global::
            if (typeUsing == null)
            {
                sb.Append("global::");
                sb.Append(s.Replace("+", "."));
                return;
            }

            // could fullname be non-ambiguous?
            // note: all-or-nothing, not trying to segment the using clause
            typeName = s.Replace("+", ".");
            p        = typeName.IndexOf('.');
            symbol   = typeName.Substring(0, p);
            match    = symbol;

            // still ambiguous, must prepend global::
            if (IsAmbiguousSymbol(symbol, match))
            {
                sb.Append("global::");
            }

            sb.Append(typeName);
        }
Esempio n. 3
0
 public bool HasUsing(string path)
 {
     return(Using.Contains(path));
 }