예제 #1
0
		private void SerializeContentProperty (IDesignerSerializationManager manager, object instance, 
						       PropertyDescriptor descriptor, CodeStatementCollection statements)
		{
			CodePropertyReferenceExpression propRef = new CodePropertyReferenceExpression ();
			propRef.PropertyName = descriptor.Name;
			object propertyValue = descriptor.GetValue (instance);

			ExpressionContext expressionCtx = manager.Context[typeof (ExpressionContext)] as ExpressionContext;
			if (expressionCtx != null && expressionCtx.PresetValue == instance)
				propRef.TargetObject = expressionCtx.Expression;
			else
				propRef.TargetObject = base.SerializeToExpression (manager, instance);

			CodeDomSerializer serializer = manager.GetSerializer (propertyValue.GetType (), typeof (CodeDomSerializer)) as CodeDomSerializer;
			if (propRef.TargetObject != null && serializer != null) {
				manager.Context.Push (new ExpressionContext (propRef, propRef.GetType (), null, propertyValue));
				object serialized = serializer.Serialize (manager, propertyValue);
				manager.Context.Pop ();

				CodeStatementCollection serializedStatements = serialized as CodeStatementCollection;
				if (serializedStatements != null)
					statements.AddRange (serializedStatements);

				CodeStatement serializedStatement = serialized as CodeStatement;
				if (serializedStatement != null)
					statements.Add (serializedStatement);

				CodeExpression serializedExpr = serialized as CodeExpression;
				if (serializedExpr != null)
					statements.Add (new CodeAssignStatement (propRef, serializedExpr));
			}
		}
		private void SerializeContentProperty (IDesignerSerializationManager manager, object component, 
											   PropertyDescriptor descriptor, CodeStatementCollection statements)
		{
			CodePropertyReferenceExpression propRef = new CodePropertyReferenceExpression ();
			propRef.PropertyName = descriptor.Name;
			object value = descriptor.GetValue (component);

			ExpressionContext expressionCtx = manager.Context[typeof (ExpressionContext)] as ExpressionContext;
			if (expressionCtx != null && expressionCtx.PresetValue == component) {
				propRef.TargetObject = expressionCtx.Expression;
			} else {
				manager.Context.Push (new CodeStatementCollection ());
				propRef.TargetObject = TryGetCachedExpression (manager, component, propRef, value);
				manager.Context.Pop ();
			}

			CodeDomSerializer serializer = manager.GetSerializer (value.GetType (), typeof (CodeDomSerializer)) as CodeDomSerializer;

			if (propRef.TargetObject != null && serializer != null) {
				// request full serialization (presetvalue == instance)
				//
				manager.Context.Push (new ExpressionContext (propRef, propRef.GetType (), component, value));
				object serialized = serializer.Serialize (manager, value);
				manager.Context.Pop ();
				
				CodeStatementCollection serializedStatements = serialized as CodeStatementCollection;
				if (serializedStatements != null)
					statements.AddRange (serializedStatements);

				CodeStatement serializedStatement = serialized as CodeStatement;
				if (serializedStatement != null)
					statements.Add (serializedStatement);

				CodeExpression serializedExpr = serialized as CodeExpression;
				if (serializedExpr != null)
					statements.Add (new CodeAssignStatement (propRef, serializedExpr));
			}
		}