Exemplo n.º 1
0
        /// <summary>
        /// Deserializes an assignment.
        /// This is used for standard properties, e.g.
        /// <code>myPictureBox.Image = value</code>
        /// </summary>
        bool DeserializeProjectResourceAssignStatement(IDesignerSerializationManager manager, CodeAssignStatement assignStatement)
        {
            var propRefTarget = assignStatement.Left as CodePropertyReferenceExpression;

            if (propRefTarget == null)
            {
                return(false);
            }

            var propRefSource = assignStatement.Right as CodePropertyReferenceExpression;

            if (propRefSource == null)
            {
                return(false);
            }

            LoggingService.Debug("Forms designer: deserializing a property assignment:");
            LoggingService.Debug("-> " + CodeStatementToString(assignStatement));

            IComponent component = this.baseSerializer.Deserialize(manager, propRefTarget.TargetObject) as IComponent;

            if (component == null)
            {
                LoggingService.Info("Forms designer: ProjectResourcesComponentCodeDomSerializer could not deserialze the target object to IComponent");
                return(false);
            }
            if (component.Site == null)
            {
                LoggingService.Info("Forms designer: ProjectResourcesComponentCodeDomSerializer: The deserialized component '" + component.ToString() + "' does not have a Site.");
                return(false);
            }

            PropertyDescriptor propDescTarget = TypeDescriptor.GetProperties(component).Find(propRefTarget.PropertyName, false);

            if (propDescTarget == null)
            {
                throw new InvalidOperationException("Could not find the property descriptor for property '" + propRefTarget.PropertyName + "' on object '" + component.ToString() + "'.");
            }

            ProjectResourceInfo resourceInfo = GetProjectResourceFromPropertyReference(manager, propRefSource);

            if (resourceInfo == null)
            {
                return(false);
            }

            // Set the property value of the target component to the value from the resource
            propDescTarget.SetValue(component, resourceInfo.OriginalValue);

            // Store our resource info in the dictionary service.
            // This is needed for the serializer so that it can
            // serialize this value as a project resource reference again.
            StoreResourceInfo(component, propDescTarget.Name, resourceInfo);

            return(true);
        }
Exemplo n.º 2
0
        static void StoreResourceInfo(IComponent component, string propertyName, ProjectResourceInfo resourceInfo)
        {
            var dictService = component.Site.GetService(typeof(IDictionaryService)) as IDictionaryService;

            if (dictService == null)
            {
                throw new InvalidOperationException("The required IDictionaryService is not available on component '" + component.ToString() + "'.");
            }
            dictService.SetValue(ProjectResourceService.ProjectResourceKey + propertyName, resourceInfo);
        }
		public ImageResourceEditorDialog(IProject project, Type requiredResourceType, ProjectResourceInfo projectResource)
			: this(project, requiredResourceType, true)
		{
			if (projectResource == null)
				throw new ArgumentNullException("projectResource");
			
			this.projectResourceRadioButton.Checked = true;
			this.originalImage = this.selectedImage = projectResource.OriginalValue;
			
			Image image = this.selectedImage as Image;
			if (image != null) {
				this.selectedImageIsProjectResource = true;
				this.SetPreviewImage(image);
			} else {
				Icon icon = this.selectedImage as Icon;
				if (icon != null) {
					this.selectedImageIsProjectResource = true;
					this.SetPreviewImage(icon.ToBitmap());
				}
			}
			this.projectTreeScanningBackgroundWorker.RunWorkerAsync(projectResource);
		}
		static void StoreResourceInfo(IComponent component, string propertyName, ProjectResourceInfo resourceInfo)
		{
			var dictService = component.Site.GetService(typeof(IDictionaryService)) as IDictionaryService;
			if (dictService == null) {
				throw new InvalidOperationException("The required IDictionaryService is not available on component '" + component.ToString() + "'.");
			}
			dictService.SetValue(ProjectResourceService.ProjectResourceKey + propertyName, resourceInfo);
		}
Exemplo n.º 5
0
        /// <summary>
        /// Deserializes a method invocation expression.
        /// This is used for extender providers, e.g.
        /// <code>myProvider.SetSomeProperty(targetComponent, value)</code>
        /// </summary>
        bool DeserializeProjectResourceMethodInvokeExpression(IDesignerSerializationManager manager, CodeMethodInvokeExpression invokeExpression)
        {
            if (!invokeExpression.Method.MethodName.StartsWith("Set", StringComparison.OrdinalIgnoreCase) ||
                invokeExpression.Parameters.Count != 2)
            {
                return(false);
            }

            var propRefSource = invokeExpression.Parameters[1] as CodePropertyReferenceExpression;

            if (propRefSource == null)
            {
                return(false);
            }

            LoggingService.Debug("Forms designer: deserializing a method invocation:");
            LoggingService.Debug("-> " + CodeStatementToString(new CodeExpressionStatement(invokeExpression)));

            object extenderProvider = this.baseSerializer.Deserialize(manager, invokeExpression.Method.TargetObject);

            if (extenderProvider == null)
            {
                return(false);
            }

            IComponent targetComponent = this.baseSerializer.Deserialize(manager, invokeExpression.Parameters[0]) as IComponent;

            if (targetComponent == null)
            {
                LoggingService.Info("Forms designer: ProjectResourcesComponentCodeDomSerializer could not deserialze the target object to IComponent");
                return(false);
            }
            if (targetComponent.Site == null)
            {
                LoggingService.Info("Forms designer: ProjectResourcesComponentCodeDomSerializer: The deserialized component '" + targetComponent.ToString() + "' does not have a Site.");
                return(false);
            }

            ProjectResourceInfo resourceInfo = GetProjectResourceFromPropertyReference(manager, propRefSource);

            if (resourceInfo == null)
            {
                return(false);
            }

            // Set the property value of the target component to the value from the resource
            extenderProvider.GetType()
            .InvokeMember(invokeExpression.Method.MethodName,
                          BindingFlags.Instance | BindingFlags.InvokeMethod | BindingFlags.Public,
                          null,
                          extenderProvider,
                          new [] { targetComponent, resourceInfo.OriginalValue },
                          System.Globalization.CultureInfo.InvariantCulture);

            // Store our resource info in the dictionary service.
            // This is needed for the serializer so that it can
            // serialize this value as a project resource reference again.
            StoreResourceInfo(targetComponent, invokeExpression.Method.MethodName.Substring(3), resourceInfo);

            return(true);
        }