Пример #1
0
        private bool ShouldClearCollection(IDesignerSerializationManager manager, ICollection collection)
        {
            bool flag = false;
            PropertyDescriptor descriptor = manager.Properties["ClearCollections"];

            if (((descriptor != null) && (descriptor.PropertyType == typeof(bool))) && ((bool)descriptor.GetValue(manager)))
            {
                flag = true;
            }
            if (!flag)
            {
                SerializeAbsoluteContext context = (SerializeAbsoluteContext)manager.Context[typeof(SerializeAbsoluteContext)];
                PropertyDescriptor       member  = manager.Context[typeof(PropertyDescriptor)] as PropertyDescriptor;
                if ((context != null) && context.ShouldSerialize(member))
                {
                    flag = true;
                }
            }
            if (!flag)
            {
                return(flag);
            }
            MethodInfo method = TypeDescriptor.GetReflectionType(collection).GetMethod("Clear", BindingFlags.Public | BindingFlags.Instance, null, new Type[0], null);

            return(((method != null) && this.MethodSupportsSerialization(method)) && flag);
        }
        public virtual CodeStatementCollection SerializeMemberAbsolute(IDesignerSerializationManager manager, object owningObject, MemberDescriptor member)
        {
            CodeStatementCollection statements;

            if (manager == null)
            {
                throw new ArgumentNullException("manager");
            }
            if (owningObject == null)
            {
                throw new ArgumentNullException("owningObject");
            }
            if (member == null)
            {
                throw new ArgumentNullException("member");
            }
            SerializeAbsoluteContext context = new SerializeAbsoluteContext(member);

            manager.Context.Push(context);
            try
            {
                statements = this.SerializeMember(manager, owningObject, member);
            }
            finally
            {
                manager.Context.Pop();
            }
            return(statements);
        }
Пример #3
0
        /// <summary>
        ///  This method returns true if the given member descriptor should be serialized,
        ///  or false if there is no need to serialize the member.
        /// </summary>
        public override bool ShouldSerialize(IDesignerSerializationManager manager, object value, MemberDescriptor descriptor)
        {
            ArgumentNullException.ThrowIfNull(manager);
            ArgumentNullException.ThrowIfNull(value);

            if (!(descriptor is PropertyDescriptor propertyToSerialize))
            {
                throw new ArgumentNullException(nameof(descriptor));
            }

            bool shouldSerializeProperty = propertyToSerialize.ShouldSerializeValue(value);

            if (!shouldSerializeProperty)
            {
                SerializeAbsoluteContext absolute = (SerializeAbsoluteContext)manager.Context[typeof(SerializeAbsoluteContext)];

                if (absolute is not null && absolute.ShouldSerialize(propertyToSerialize))
                {
                    // For ReadOnly properties, we only want to override the value returned from
                    // ShouldSerializeValue() if the property is marked with DesignerSerializationVisibilityAttribute(Content).
                    // Consider the case of a property with just a getter - we only want to serialize those
                    // if they're marked in this way (see ReflectPropertyDescriptor::ShouldSerializeValue())
                    if (!propertyToSerialize.Attributes.Contains(DesignerSerializationVisibilityAttribute.Content))
                    {
                        shouldSerializeProperty = false; // it's already false at this point, but this is clearer.
                    }
                    else
                    {
                        shouldSerializeProperty = true; // Always serialize difference properties
                    }
                }
            }

            if (shouldSerializeProperty)
            {
                bool isDesignTime = propertyToSerialize.Attributes.Contains(DesignOnlyAttribute.Yes);
                if (!isDesignTime)
                {
                    return(true);
                }
            }

            // If we don't have to serialize, we need to make sure there isn't a member
            // relationship with this property.  If there is, we still need to serialize.

            if (manager.GetService(typeof(MemberRelationshipService)) is MemberRelationshipService relationships)
            {
                MemberRelationship relationship = relationships[value, descriptor];

                if (relationship != MemberRelationship.Empty)
                {
                    return(true);
                }
            }

            return(false);
        }
Пример #4
0
		public virtual object SerializeAbsolute (IDesignerSerializationManager manager, object value)
		{
			if (value == null)
				throw new ArgumentNullException ("value");
			if (manager == null)
				throw new ArgumentNullException ("manager");

			SerializeAbsoluteContext context = new SerializeAbsoluteContext ();
			manager.Context.Push (context);
			object result = this.Serialize (manager, value);
			manager.Context.Pop ();
			return result;
		}
Пример #5
0
        public override bool ShouldSerialize(IDesignerSerializationManager manager, object value, MemberDescriptor descriptor)
        {
            PropertyDescriptor member = descriptor as PropertyDescriptor;

            if (manager == null)
            {
                throw new ArgumentNullException("manager");
            }
            if (value == null)
            {
                throw new ArgumentNullException("value");
            }
            if (member == null)
            {
                throw new ArgumentNullException("descriptor");
            }
            bool flag = member.ShouldSerializeValue(value);

            if (!flag)
            {
                SerializeAbsoluteContext context = (SerializeAbsoluteContext)manager.Context[typeof(SerializeAbsoluteContext)];
                if ((context != null) && context.ShouldSerialize(member))
                {
                    if (!member.Attributes.Contains(DesignerSerializationVisibilityAttribute.Content))
                    {
                        flag = false;
                    }
                    else
                    {
                        flag = true;
                    }
                }
            }
            if (flag && !member.Attributes.Contains(DesignOnlyAttribute.Yes))
            {
                return(true);
            }
            MemberRelationshipService service = manager.GetService(typeof(MemberRelationshipService)) as MemberRelationshipService;

            if (service != null)
            {
                MemberRelationship relationship = service[value, descriptor];
                if (relationship != MemberRelationship.Empty)
                {
                    return(true);
                }
            }
            return(false);
        }
        public virtual object SerializeAbsolute(IDesignerSerializationManager manager, object value)
        {
            object obj2;
            SerializeAbsoluteContext context = new SerializeAbsoluteContext();

            manager.Context.Push(context);
            try
            {
                obj2 = this.Serialize(manager, value);
            }
            finally
            {
                manager.Context.Pop();
            }
            return(obj2);
        }
Пример #7
0
        public virtual object SerializeAbsolute(IDesignerSerializationManager manager, object value)
        {
            if (value == null)
            {
                throw new ArgumentNullException("value");
            }
            if (manager == null)
            {
                throw new ArgumentNullException("manager");
            }

            SerializeAbsoluteContext context = new SerializeAbsoluteContext();

            manager.Context.Push(context);
            object result = this.Serialize(manager, value);

            manager.Context.Pop();
            return(result);
        }
        public override bool ShouldSerialize(IDesignerSerializationManager manager, object value, MemberDescriptor descriptor)
        {
            if (manager == null)
            {
                throw new ArgumentNullException("manager");
            }
            if (value == null)
            {
                throw new ArgumentNullException("value");
            }
            if (descriptor == null)
            {
                throw new ArgumentNullException("descriptor");
            }

            PropertyDescriptor property = (PropertyDescriptor)descriptor;

            if (property.Attributes.Contains(DesignOnlyAttribute.Yes))
            {
                return(false);
            }

            SerializeAbsoluteContext absolute = manager.Context[typeof(SerializeAbsoluteContext)] as SerializeAbsoluteContext;

            if (absolute != null && absolute.ShouldSerialize(descriptor))
            {
                return(true);
            }

            bool result = property.ShouldSerializeValue(value);

            if (!result)
            {
                if (!GetRelationship(manager, value, descriptor).IsEmpty)
                {
                    result = true;
                }
            }

            return(result);
        }
 public virtual CodeStatementCollection SerializeMemberAbsolute(IDesignerSerializationManager manager, object owningObject, MemberDescriptor member)
 {
     CodeStatementCollection statements;
     if (manager == null)
     {
         throw new ArgumentNullException("manager");
     }
     if (owningObject == null)
     {
         throw new ArgumentNullException("owningObject");
     }
     if (member == null)
     {
         throw new ArgumentNullException("member");
     }
     SerializeAbsoluteContext context = new SerializeAbsoluteContext(member);
     manager.Context.Push(context);
     try
     {
         statements = this.SerializeMember(manager, owningObject, member);
     }
     finally
     {
         manager.Context.Pop();
     }
     return statements;
 }
 public virtual object SerializeAbsolute(IDesignerSerializationManager manager, object value)
 {
     object obj2;
     SerializeAbsoluteContext context = new SerializeAbsoluteContext();
     manager.Context.Push(context);
     try
     {
         obj2 = this.Serialize(manager, value);
     }
     finally
     {
         manager.Context.Pop();
     }
     return obj2;
 }
        /// <summary>
        ///  This serializes the given property on this object as a content property.
        /// </summary>
        private void SerializeContentProperty(IDesignerSerializationManager manager, object value, PropertyDescriptor property, bool isExtender, CodeStatementCollection statements)
        {
            CodeDomSerializer.Trace("Property is marked as Visibility.Content.  Recursing.");

            object propertyValue = GetPropertyValue(manager, property, value, out bool validValue);

            // For persist contents objects, we don't just serialize the properties on the object; we
            // serialize everything.
            //
            CodeDomSerializer serializer = null;

            if (propertyValue is null)
            {
                CodeDomSerializer.TraceError("Property {0} is marked as Visibility.Content but it is returning null.", property.Name);

                string name = manager.GetName(value);

                if (name is null)
                {
                    name = value.GetType().FullName;
                }

                manager.ReportError(new CodeDomSerializerException(string.Format(SR.SerializerNullNestedProperty, name, property.Name), manager));
            }
            else
            {
                serializer = (CodeDomSerializer)manager.GetSerializer(propertyValue.GetType(), typeof(CodeDomSerializer));
                if (serializer != null)
                {
                    // Create a property reference expression and push it on the context stack.
                    // This allows the serializer to gain some context as to what it should be
                    // serializing.
                    CodeExpression target = SerializeToExpression(manager, value);

                    if (target is null)
                    {
                        CodeDomSerializer.TraceWarning("Unable to convert value to expression object");
                    }
                    else
                    {
                        CodeExpression propertyRef = null;

                        if (isExtender)
                        {
                            CodeDomSerializer.Trace("Content property is an extender.");
                            ExtenderProvidedPropertyAttribute exAttr = (ExtenderProvidedPropertyAttribute)property.Attributes[typeof(ExtenderProvidedPropertyAttribute)];

                            // Extender properties are method invokes on a target "extender" object.
                            //
                            CodeExpression extender = SerializeToExpression(manager, exAttr.Provider);
                            CodeExpression extended = SerializeToExpression(manager, value);

                            CodeDomSerializer.TraceWarningIf(extender is null, "Extender object {0} could not be serialized.", manager.GetName(exAttr.Provider));
                            CodeDomSerializer.TraceWarningIf(extended is null, "Extended object {0} could not be serialized.", manager.GetName(value));
                            if (extender != null && extended != null)
                            {
                                CodeMethodReferenceExpression methodRef    = new CodeMethodReferenceExpression(extender, "Get" + property.Name);
                                CodeMethodInvokeExpression    methodInvoke = new CodeMethodInvokeExpression
                                {
                                    Method = methodRef
                                };
                                methodInvoke.Parameters.Add(extended);
                                propertyRef = methodInvoke;
                            }
                        }
                        else
                        {
                            propertyRef = new CodePropertyReferenceExpression(target, property.Name);
                        }

                        if (propertyRef != null)
                        {
                            ExpressionContext tree = new ExpressionContext(propertyRef, property.PropertyType, value, propertyValue);
                            manager.Context.Push(tree);

                            object result = null;

                            try
                            {
                                SerializeAbsoluteContext absolute = (SerializeAbsoluteContext)manager.Context[typeof(SerializeAbsoluteContext)];

                                if (IsSerialized(manager, propertyValue, absolute != null))
                                {
                                    result = GetExpression(manager, propertyValue);
                                }
                                else
                                {
                                    result = serializer.Serialize(manager, propertyValue);
                                }
                            }
                            finally
                            {
                                Debug.Assert(manager.Context.Current == tree, "Serializer added a context it didn't remove.");
                                manager.Context.Pop();
                            }

                            if (result is CodeStatementCollection csc)
                            {
                                foreach (CodeStatement statement in csc)
                                {
                                    statements.Add(statement);
                                }
                            }
                            else
                            {
                                if (result is CodeStatement cs)
                                {
                                    statements.Add(cs);
                                }
                            }
                        }
                    }
                }
                else
                {
                    CodeDomSerializer.TraceError("Property {0} is marked as Visibilty.Content but there is no serializer for it.", property.Name);

                    manager.ReportError(new CodeDomSerializerException(string.Format(SR.SerializerNoSerializerForComponent, property.PropertyType.FullName), manager));
                }
            }
        }
Пример #12
0
		public virtual CodeStatementCollection SerializeMemberAbsolute (IDesignerSerializationManager manager, 
										object owningobject, MemberDescriptor member)
		{
			if (member == null)
				throw new ArgumentNullException ("member");
			if (owningobject == null)
				throw new ArgumentNullException ("owningobject");
			if (manager == null)
				throw new ArgumentNullException ("manager");

			SerializeAbsoluteContext context = new SerializeAbsoluteContext (member);
			manager.Context.Push (context);
			CodeStatementCollection result = this.SerializeMember (manager, owningobject, member);
			manager.Context.Pop ();
			return result;
		}
Пример #13
0
        private void SerializeContentProperty(IDesignerSerializationManager manager, object value, PropertyDescriptor property, bool isExtender, CodeStatementCollection statements)
        {
            bool              flag;
            object            presetValue = this.GetPropertyValue(manager, property, value, out flag);
            CodeDomSerializer serializer  = null;

            if (presetValue == null)
            {
                string name = manager.GetName(value);
                if (name == null)
                {
                    name = value.GetType().FullName;
                }
                manager.ReportError(System.Design.SR.GetString("SerializerNullNestedProperty", new object[] { name, property.Name }));
            }
            else
            {
                serializer = (CodeDomSerializer)manager.GetSerializer(presetValue.GetType(), typeof(CodeDomSerializer));
                if (serializer != null)
                {
                    CodeExpression targetObject = base.SerializeToExpression(manager, value);
                    if (targetObject != null)
                    {
                        CodeExpression expression = null;
                        if (isExtender)
                        {
                            ExtenderProvidedPropertyAttribute attribute = (ExtenderProvidedPropertyAttribute)property.Attributes[typeof(ExtenderProvidedPropertyAttribute)];
                            CodeExpression expression3 = base.SerializeToExpression(manager, attribute.Provider);
                            CodeExpression expression4 = base.SerializeToExpression(manager, value);
                            if ((expression3 != null) && (expression4 != null))
                            {
                                CodeMethodReferenceExpression expression5 = new CodeMethodReferenceExpression(expression3, "Get" + property.Name);
                                CodeMethodInvokeExpression    expression6 = new CodeMethodInvokeExpression {
                                    Method = expression5
                                };
                                expression6.Parameters.Add(expression4);
                                expression = expression6;
                            }
                        }
                        else
                        {
                            expression = new CodePropertyReferenceExpression(targetObject, property.Name);
                        }
                        if (expression != null)
                        {
                            ExpressionContext context = new ExpressionContext(expression, property.PropertyType, value, presetValue);
                            manager.Context.Push(context);
                            object obj3 = null;
                            try
                            {
                                SerializeAbsoluteContext context2 = (SerializeAbsoluteContext)manager.Context[typeof(SerializeAbsoluteContext)];
                                if (base.IsSerialized(manager, presetValue, context2 != null))
                                {
                                    obj3 = base.GetExpression(manager, presetValue);
                                }
                                else
                                {
                                    obj3 = serializer.Serialize(manager, presetValue);
                                }
                            }
                            finally
                            {
                                manager.Context.Pop();
                            }
                            CodeStatementCollection statements2 = obj3 as CodeStatementCollection;
                            if (statements2 == null)
                            {
                                CodeStatement statement2 = obj3 as CodeStatement;
                                if (statement2 != null)
                                {
                                    statements.Add(statement2);
                                }
                            }
                            else
                            {
                                foreach (CodeStatement statement in statements2)
                                {
                                    statements.Add(statement);
                                }
                            }
                        }
                    }
                }
                else
                {
                    manager.ReportError(System.Design.SR.GetString("SerializerNoSerializerForComponent", new object[] { property.PropertyType.FullName }));
                }
            }
        }