Exemplo n.º 1
0
        public PhoneNavigationCodeTraverser(MetadataReaderHost host, IEnumerable <IAssemblyReference> assemblies) : base()
        {
            this.host = host;
            List <IAssembly> assembliesTraversed = new List <IAssembly>();

            foreach (IAssemblyReference asmRef in assemblies)
            {
                assembliesTraversed.Add(asmRef.ResolvedAssembly);
            }

            Microsoft.Cci.Immutable.PlatformType platform = host.PlatformType as Microsoft.Cci.Immutable.PlatformType;

            // TODO obtain version, culture and signature data dynamically
            IAssemblyReference assembly = PhoneTypeHelper.getPhoneAssemblyReference(host);

            // TODO determine the needed types dynamically
            navigationSvcType = platform.CreateReference(assembly, "System", "Windows", "Navigation", "NavigationService");

            assembly            = PhoneTypeHelper.getSystemAssemblyReference(host);
            cancelEventArgsType = platform.CreateReference(assembly, "System", "ComponentModel", "CancelEventArgs");
            navigationCallers   = new HashSet <IMethodReference>();
        }
        private void initializeKnownUIChangers()
        {
            PHONE_UI_CHANGER_METHODS = new Dictionary <string, string[]>();
            IAssemblyReference systemAssembly    = PhoneTypeHelper.getSystemAssemblyReference(host);
            IAssemblyReference systemWinAssembly = PhoneTypeHelper.getSystemWindowsAssemblyReference(host);
            IAssemblyReference phoneAssembly     = PhoneTypeHelper.getPhoneAssemblyReference(host);

            ITypeReference textBoxType = platform.CreateReference(systemAssembly, "System", "Windows", "Controls", "TextBox");

            PHONE_UI_CHANGER_METHODS[textBoxType.ToString()] =
                new string[] { "set_BaselineOffset", "set_CaretBrush", "set_FontSource", "set_HorizontalScrollBarVisibility", "set_IsReadOnly", "set_LineHeight",
                               "set_LineStackingStrategy", "set_MaxLength", "set_SelectedText", "set_SelectionBackground", "set_SelectionForeground", "set_SelectionLength",
                               "set_SelectionStart", "set_Text", "set_TextAlignment", "set_TextWrapping", "set_VerticalScrollBarVisibility", "set_Watermark", };

            ITypeReference textBlockType = platform.CreateReference(systemAssembly, "System", "Windows", "Controls", "TextBlock");

            PHONE_UI_CHANGER_METHODS[textBlockType.ToString()] =
                new string[] { "set_BaselineOffset", "set_FontFamily", "set_FontSize", "set_FontSource", "set_FontStretch", "set_FontStyle", "set_FontWeight", "set_Foreground",
                               "set_CharacterSpacing", "set_LineHeight", "set_LineStackingStrategy", "set_Padding", "set_Text", "set_TextAlignment", "set_TextDecorations",
                               "set_TextTrimming", "set_TextWrapping", };

            ITypeReference uiElementType = platform.CreateReference(systemAssembly, "System", "Windows", "UIElement");

            PHONE_UI_CHANGER_METHODS[uiElementType.ToString()] =
                new string[] { "set_Clip", "set_Opacity", "set_OpacityMask", "set_Projection", "set_RenderTransform",
                               "set_RenderTransformOrigin", "set_Visibility", "Arrange", "InvalidateArrange", "InvalidateMeasure", "SetValue", "ClearValue", // Set/ClearValue are quite unsafe
                               "UpdateLayout", "Measure", };

            ITypeReference frameworkElementType = platform.CreateReference(systemAssembly, "System", "Windows", "FrameworkElement");

            PHONE_UI_CHANGER_METHODS[frameworkElementType.ToString()] =
                new string[] { "set_FlowDirection", "set_Height", "set_HorizontalAlignment", "set_Language", "set_Margin", "set_MaxHeight", "set_MaxWidth",
                               "set_MinHeight", "set_MinWidth", "set_Style", "set_VerticalAlignment", "set_Width", "set_Cursor", };

            ITypeReference borderType = platform.CreateReference(systemAssembly, "System", "Windows", "Controls", "Border");

            PHONE_UI_CHANGER_METHODS[borderType.ToString()] =
                new string[] { "set_Background", "set_BorderBrush", "set_BorderThickness", "set_CornerRadius", "set_Padding", };

            ITypeReference controlType = platform.CreateReference(systemAssembly, "System", "Windows", "Controls", "Control");

            PHONE_UI_CHANGER_METHODS[controlType.ToString()] =
                new string[] { "set_Background", "set_BorderBrush", "set_BorderThickness", "set_CharacterSpacing", "set_FontFamily", "set_FontSize", "set_FontStretch",
                               "set_FontStyle", "set_FontWeight", "set_Foreground", "set_HorizontalContentAlignment", "set_IsEnabled", "set_Padding", "set_VerticalContentAlignment", };

            ITypeReference contentControlType = platform.CreateReference(systemAssembly, "System", "Windows", "Controls", "ContentControl");

            PHONE_UI_CHANGER_METHODS[contentControlType.ToString()] = new string[] { "set_Content", };

            ITypeReference panelType = platform.CreateReference(systemAssembly, "System", "Windows", "Controls", "Panel");

            PHONE_UI_CHANGER_METHODS[panelType.ToString()] = new string[] { "set_Background", };

            ITypeReference canvasType = platform.CreateReference(systemAssembly, "System", "Windows", "Controls", "Canvas");

            PHONE_UI_CHANGER_METHODS[canvasType.ToString()] = new string[] { "set_Left", "set_Top", "set_ZIndex", };

            ITypeReference toggleButtonType = platform.CreateReference(systemAssembly, "System", "Windows", "Controls", "Primitives", "ToggleButton");

            PHONE_UI_CHANGER_METHODS[toggleButtonType.ToString()] = new string[] { "set_IsChecked", };

            ITypeReference gridType = platform.CreateReference(systemAssembly, "System", "Windows", "Controls", "Grid");

            PHONE_UI_CHANGER_METHODS[gridType.ToString()] = new string[] { "set_ShowGridLines", "set_Column", "set_ColumnSpan", "set_Row", "set_RowSpan", };

            ITypeReference imageType = platform.CreateReference(systemAssembly, "System", "Windows", "Controls", "Image");

            PHONE_UI_CHANGER_METHODS[imageType.ToString()] = new string[] { "set_Source", "set_Stretch", };

            ITypeReference inkPresenterType = platform.CreateReference(systemAssembly, "System", "Windows", "Controls", "InkPresenter");

            PHONE_UI_CHANGER_METHODS[inkPresenterType.ToString()] = new string[] { "set_Strokes", };

            ITypeReference itemsControlType = platform.CreateReference(systemAssembly, "System", "Windows", "Controls", "ItemsControl");

            PHONE_UI_CHANGER_METHODS[itemsControlType.ToString()] = new string[] { "set_DisplayMemberPath", "set_ItemsSource", "set_ItemTemplate", };

            ITypeReference selectorType = platform.CreateReference(systemAssembly, "System", "Windows", "Controls", "Primitives", "Selector");

            PHONE_UI_CHANGER_METHODS[selectorType.ToString()] =
                new string[] { "set_SelectedIndex", "set_SelectedItem", "set_SelectedValue", "set_SelectedValuePath", };

            ITypeReference listBoxType = platform.CreateReference(systemAssembly, "System", "Windows", "Controls", "ListBox");

            PHONE_UI_CHANGER_METHODS[listBoxType.ToString()] = new string[] { "set_ItemContainerStyle", };

            ITypeReference passwordBoxType = platform.CreateReference(systemAssembly, "System", "Windows", "Controls", "PasswordBox");

            PHONE_UI_CHANGER_METHODS[passwordBoxType.ToString()] =
                new string[] { "set_CaretBrush", "set_FontSource", "set_MaxLength", "set_Password", "set_PasswordChar",
                               "set_SelectionBackground", "set_SelectionForeground", };

            ITypeReference rangeBaseType = platform.CreateReference(systemAssembly, "System", "Windows", "Controls", "Primitives", "RangeBase");

            PHONE_UI_CHANGER_METHODS[rangeBaseType.ToString()] = new string[] { "set_LargeChange", "set_Maximum", "set_Minimum", "set_SmallChange", "set_Value", };

            ITypeReference progressBarType = platform.CreateReference(systemAssembly, "System", "Windows", "Controls", "ProgressBar");

            PHONE_UI_CHANGER_METHODS[progressBarType.ToString()] = new string[] { "set_IsIndeterminate", };

            ITypeReference sliderType = platform.CreateReference(systemAssembly, "System", "Windows", "Controls", "Slider");

            PHONE_UI_CHANGER_METHODS[sliderType.ToString()] = new string[] { "set_IsDirectionReversed", "set_Orientation", };

            ITypeReference stackPanelType = platform.CreateReference(systemAssembly, "System", "Windows", "Controls", "StackPanel");

            PHONE_UI_CHANGER_METHODS[stackPanelType.ToString()] = new string[] { "set_Orientation", };

            ITypeReference richTextBoxType = platform.CreateReference(systemAssembly, "System", "Windows", "Controls", "RichTextBox");

            PHONE_UI_CHANGER_METHODS[richTextBoxType.ToString()] =
                new string[] { "set_BaselineOffset", "set_CaretBrush", "set_HorizontalScrollBartVisibility", "set_LineHeight", "set_LineStackingStrategy",
                               "set_TextAlignment", "set_TextWrapping", "set_VerticalScrollBarVisibility", "set_Xaml", };

            ITypeReference webBrowserTaskType = platform.CreateReference(phoneAssembly, "Microsoft", "Phone", "Tasks", "WebBrowserTask");

            PHONE_UI_CHANGER_METHODS[webBrowserTaskType.ToString()] = new string[] { "Show", };

            ITypeReference appBarIconButtonType = platform.CreateReference(phoneAssembly, "Microsoft", "Phone", "Shell", "ApplicationBarIconButton");

            PHONE_UI_CHANGER_METHODS[appBarIconButtonType.ToString()] = new string[] { "set_IsEnabled", "set_IconUri", "set_Text", };

            ITypeReference appBarMenuItemType = platform.CreateReference(phoneAssembly, "Microsoft", "Phone", "Shell", "ApplicationBarMenuItem");

            PHONE_UI_CHANGER_METHODS[appBarMenuItemType.ToString()] = new string[] { "set_IsEnabled", "set_Text", };

            ITypeReference emailComposeTaskType = platform.CreateReference(phoneAssembly, "Microsoft", "Phone", "Tasks", "EmailComposeTask");

            PHONE_UI_CHANGER_METHODS[emailComposeTaskType.ToString()] = new string[] { "Show", };

            ITypeReference scaleTransformType = platform.CreateReference(systemWinAssembly, "System", "Windows", "Media", "ScaleTransform");

            PHONE_UI_CHANGER_METHODS[scaleTransformType.ToString()] = new string[] { "set_CenterX", "set_CenterY", "set_ScaleX", "set_ScaleY", };
        }