Ejemplo n.º 1
0
        private void Btn_Satellite_Clicked(object sender, EventArgs e)
        {
            var page = new CustomDialogPage(TypesMap.Select((t, i) => new ItemType(t, TypesMapImgDark[i])).ToArray());

            page.Clicked += delegate(object sender1, EventArgs e1) { Map_Clicked(sender1, e1, page.IndexSelected); };
            Navigation.PushPopupAsync(new CommonPopupPage(page, CustomDialogPage.Header));
        }
Ejemplo n.º 2
0
        private static string NonGenericToCsString(string fullname, bool fqn)
        {
            if (TypesMap.TryGetValue(fullname, out var typeName))
            {
                return(typeName);
            }

            var name = fullname;

            if (!fqn)
            {
                var pos = name.LastIndexOf('.');
                if (pos >= 0)
                {
                    name = name[(pos + 1)..];
Ejemplo n.º 3
0
        private string ResolvePropertyType(IPublishedPropertyType propType)
        {
            var propertyType = string.Empty;

            var interfaces = propType.ClrType.GetInterfaces();

            if (interfaces.Any() && interfaces.Count() == 1)
            {
                propertyType = interfaces.First().Name;
                var args = propType.ClrType.GenericTypeArguments;
                if (args.Any())
                {
                    propertyType += "<";

                    foreach (var arg in args)
                    {
                        var mappedType = arg.Name;
                        if (TypesMap.ContainsKey(arg.Name))
                        {
                            mappedType = TypesMap[arg.Name];
                        }
                        propertyType += $"{mappedType},";
                    }
                    propertyType  = propertyType.Trim(',');
                    propertyType += ">";
                }
            }
            else
            {
                var mappedType = string.Empty;

                if (TypesMap.ContainsKey(propType.ClrType.FullName))
                {
                    mappedType = TypesMap[propType.ClrType.FullName];
                }


                if (string.IsNullOrEmpty(mappedType))
                {
                    mappedType = propType.ClrType.Name;
                }

                propertyType = mappedType;
            }

            return(propertyType);
        }
Ejemplo n.º 4
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);
        }