public static bool isMessageBoxClass(this ITypeReference typeRef, IMetadataHost host) { Microsoft.Cci.Immutable.PlatformType platform = host.PlatformType as Microsoft.Cci.Immutable.PlatformType;; IAssemblyReference systemAssembly = getSystemWindowsAssemblyReference(host); ITypeReference mbType = platform.CreateReference(systemAssembly, "System", "Windows", "MessageBox"); return(typeRef.isClass(mbType)); }
public static bool isNavigationServiceClass(this ITypeReference typeRef, IMetadataHost host) { Microsoft.Cci.Immutable.PlatformType platform = host.PlatformType as Microsoft.Cci.Immutable.PlatformType; IAssemblyReference phoneAssembly = getPhoneAssemblyReference(host); ITypeReference phoneApplicationPageTypeRef = platform.CreateReference(phoneAssembly, "System", "Windows", "Navigation", "NavigationService"); return(typeRef.isClass(phoneApplicationPageTypeRef)); }
public static bool isRoutedEventHandlerClass(this ITypeReference typeRef, IMetadataHost host) { Microsoft.Cci.Immutable.PlatformType platform = host.PlatformType as Microsoft.Cci.Immutable.PlatformType;; IAssemblyReference systemAssembly = getSystemWindowsAssemblyReference(host); ITypeReference routedEvHandlerType = platform.CreateReference(systemAssembly, "System", "Windows", "RoutedEventHandler"); return(typeRef.isClass(routedEvHandlerType)); }
public static bool isPhoneApplicationPageClass(this ITypeReference typeRef, IMetadataHost host) { Microsoft.Cci.Immutable.PlatformType platform = host.PlatformType as Microsoft.Cci.Immutable.PlatformType; IAssemblyReference phoneAssembly = PhoneTypeHelper.getPhoneAssemblyReference(host); ITypeReference phoneApplicationPageTypeRef = platform.CreateReference(phoneAssembly, "Microsoft", "Phone", "Controls", "PhoneApplicationPage"); return(typeRef.isClass(phoneApplicationPageTypeRef)); }
public static bool isPhoneApplicationClass(this ITypeReference typeRef, IMetadataHost host) { Microsoft.Cci.Immutable.PlatformType platform = host.PlatformType as Microsoft.Cci.Immutable.PlatformType; IAssemblyReference systemAssembly = PhoneTypeHelper.getSystemWindowsAssemblyReference(host); ITypeReference applicationClass = platform.CreateReference(systemAssembly, "System", "Windows", "Application"); return(typeRef.isClass(applicationClass)); }
public static bool isCancelEventArgsClass(this ITypeReference typeRef, IMetadataHost host) { Microsoft.Cci.Immutable.PlatformType platform = host.PlatformType as Microsoft.Cci.Immutable.PlatformType; IAssemblyReference systemAssembly = getSystemAssemblyReference(host); ITypeReference cancelEventArgsClass = platform.CreateReference(systemAssembly, "System", "ComponentModel", "CancelEventArgs"); return(typeRef.isClass(cancelEventArgsClass)); }
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>(); }
public static bool isURIClass(this ITypeReference typeRef, IMetadataHost host) { Microsoft.Cci.Immutable.PlatformType platformType = host.PlatformType as Microsoft.Cci.Immutable.PlatformType; if (platformType == null) { return(false); } IAssemblyReference coreRef = platformType.CoreAssemblyRef; AssemblyIdentity systemAssemblyId = new AssemblyIdentity(host.NameTable.GetNameFor("System"), "", coreRef.Version, coreRef.PublicKeyToken, ""); IAssemblyReference systemAssembly = host.FindAssembly(systemAssemblyId); ITypeReference uriTypeRef = platformType.CreateReference(systemAssembly, "System", "Uri"); return(typeRef.isClass(uriTypeRef)); }
public bool isMethodInputHandlerOrFeedbackOverride(IMethodDefinition method) { // FEEDBACK TODO: This is extremely coarse. There must be quite a few non-UI routed/non-routed events Microsoft.Cci.Immutable.PlatformType platform = host.PlatformType as Microsoft.Cci.Immutable.PlatformType;; IAssemblyReference coreAssembly = PhoneTypeHelper.getCoreAssemblyReference(host); ITypeReference eventArgsType = platform.CreateReference(coreAssembly, "System", "EventArgs"); foreach (IParameterDefinition paramDef in method.Parameters) { if (paramDef.Type.isClass(eventArgsType)) { return(true); } } return(false); }
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", }; }
private void InitializeTraverser() { Microsoft.Cci.Immutable.PlatformType platform = host.PlatformType as Microsoft.Cci.Immutable.PlatformType; coreAssemblyRef = platform.CoreAssemblyRef; // TODO obtain version, culture and signature data dynamically AssemblyIdentity MSPhoneAssemblyId = new AssemblyIdentity(host.NameTable.GetNameFor("Microsoft.Phone"), "", new Version("7.0.0.0"), new byte[] { 0x24, 0xEE, 0xC0, 0xD8, 0xC8, 0x6C, 0xDA, 0x1E }, ""); AssemblyIdentity MSPhoneControlsAssemblyId = new AssemblyIdentity(host.NameTable.GetNameFor("Microsoft.Phone.Controls"), "", new Version("7.0.0.0"), new byte[] { 0x24, 0xEE, 0xC0, 0xD8, 0xC8, 0x6C, 0xDA, 0x1E }, ""); AssemblyIdentity MSPhoneSystemWindowsAssemblyId = new AssemblyIdentity(host.NameTable.GetNameFor("System.Windows"), coreAssemblyRef.Culture, coreAssemblyRef.Version, coreAssemblyRef.PublicKeyToken, ""); phoneAssembly = host.FindAssembly(MSPhoneAssemblyId); phoneSystemWindowsAssembly = host.FindAssembly(MSPhoneSystemWindowsAssemblyId); MSPhoneControlsAssembly = host.FindAssembly(MSPhoneControlsAssemblyId); // TODO BUG / XAML DEPENDENCE If a control is declared in XAML, it may be one from a library *not* linked! So, assemblies could be dummy here // TODO determine the needed types dynamically if (phoneAssembly != Dummy.Assembly) { appBarIconButtonType = platform.CreateReference(phoneAssembly, "Microsoft", "Phone", "Shell", "ApplicationBarIconButton"); appBarMenuItemType = platform.CreateReference(phoneAssembly, "Microsoft", "Phone", "Shell", "ApplicationBarMenuItem"); } else { appBarIconButtonType = host.PlatformType.SystemObject; appBarMenuItemType = host.PlatformType.SystemObject; } if (phoneSystemWindowsAssembly != Dummy.Assembly) { checkBoxType = platform.CreateReference(phoneSystemWindowsAssembly, "System", "Windows", "Controls", "CheckBox"); radioButtonType = platform.CreateReference(phoneSystemWindowsAssembly, "System", "Windows", "Controls", "RadioButton"); buttonType = platform.CreateReference(phoneSystemWindowsAssembly, "System", "Windows", "Controls", "Button"); buttonBaseType = platform.CreateReference(phoneSystemWindowsAssembly, "System", "Windows", "Controls", "Primitives", "ButtonBase"); toggleButtonType = platform.CreateReference(phoneSystemWindowsAssembly, "System", "Windows", "Controls", "Primitives", "ToggleButton"); controlType = platform.CreateReference(phoneSystemWindowsAssembly, "System", "Windows", "Controls", "Control"); uiElementType = platform.CreateReference(phoneSystemWindowsAssembly, "System", "Windows", "UIElement"); listBoxType = platform.CreateReference(phoneSystemWindowsAssembly, "System", "Windows", "Controls", "ListBox"); } else { checkBoxType = host.PlatformType.SystemObject; radioButtonType = host.PlatformType.SystemObject; buttonType = host.PlatformType.SystemObject; buttonBaseType = host.PlatformType.SystemObject; toggleButtonType = host.PlatformType.SystemObject; controlType = host.PlatformType.SystemObject; uiElementType = host.PlatformType.SystemObject; listBoxType = host.PlatformType.SystemObject; } if (MSPhoneControlsAssembly != Dummy.Assembly) { pivotType = platform.CreateReference(MSPhoneControlsAssembly, "Microsoft", "Phone", "Controls", "Pivot"); } else { pivotType = host.PlatformType.SystemObject; } trueConstant = new CompileTimeConstant() { Type = platform.SystemBoolean, Value = true }; falseConstant = new CompileTimeConstant() { Type = platform.SystemBoolean, Value = false }; IEnumerable <IPropertyDefinition> controlProperties = controlType.ResolvedType.Properties; IEnumerable <IPropertyDefinition> toggleButtonProperties = toggleButtonType.ResolvedType.Properties; IEnumerable <IPropertyDefinition> uiElementProperties = uiElementType.ResolvedType.Properties; IPropertyDefinition prop = controlProperties.Single(p => p.Name.Value == "IsEnabled"); isEnabledSetter = prop.Setter; isEnabledGetter = prop.Getter; prop = toggleButtonProperties.Single(p => p.Name.Value == "IsChecked"); isCheckedSetter = prop.Setter; isCheckedGetter = prop.Getter; prop = uiElementProperties.Single(p => p.Name.Value == "Visibility"); visibilitySetter = prop.Setter; visibilityGetter = prop.Getter; IEnumerable <IEventDefinition> buttonBaseEvents = buttonBaseType.ResolvedType.Events; IEnumerable <IEventDefinition> toggleButtonEvents = toggleButtonType.ResolvedType.Events; IEventDefinition evt = buttonBaseEvents.Single(e => e.Name.Value == "Click"); clickHandlerAdder = evt.Adder; clickHandlerRemover = evt.Remover; evt = toggleButtonEvents.Single(e => e.Name.Value == "Checked"); checkedHandlerAdder = evt.Adder; checkedHandlerRemover = evt.Remover; evt = toggleButtonEvents.Single(e => e.Name.Value == "Unchecked"); uncheckedHandlerAdder = evt.Adder; uncheckedHandlerRemover = evt.Remover; }