/// <summary> /// We customize the output from the default serializer here, adding /// a comment and an extra line of code. /// </summary> public override object Serialize(IDesignerSerializationManager manager, object value) { // first, locate and invoke the default serializer for // the ButtonArray's base class (UserControl) // CodeDomSerializer baseSerializer = (CodeDomSerializer)manager.GetSerializer(typeof(WizardStepsControl).BaseType, typeof(CodeDomSerializer)); object codeObject = baseSerializer.Serialize(manager, value); // now add some custom code // if (codeObject is CodeStatementCollection) { // add a custom comment to the code. // CodeStatementCollection statements = (CodeStatementCollection)codeObject; statements.Insert(4, new CodeCommentStatement("This is a custom comment added by a custom serializer on " + DateTime.Now.ToLongDateString())); // call a custom method. // CodeExpression targetObject = base.SerializeToExpression(manager, value); WizardStepsControl wsc = (WizardStepsControl)value; if (targetObject != null && wsc.Steps != null) { CodePropertyReferenceExpression leftNode = new CodePropertyReferenceExpression(targetObject, "Steps"); CodeObjectCreateExpression rightNode = new CodeObjectCreateExpression(typeof(Collection <Step>)); CodeAssignStatement initializeStepsStatement = new CodeAssignStatement(leftNode, rightNode); statements.Insert(5, initializeStepsStatement); } } // finally, return the statements that have been created return(codeObject); }
public override object Serialize( IDesignerSerializationManager manager, object value) { CodeDomSerializer baseSerializer = manager.GetSerializer( typeof(FlowChart).BaseType, typeof(CodeDomSerializer)) as CodeDomSerializer; object codeObject = baseSerializer.Serialize(manager, value); if (codeObject is CodeStatementCollection) { CodeStatementCollection code = codeObject as CodeStatementCollection; FlowChart chart = value as FlowChart; // Brushes SerializeBrush(code, "BackBrush", chart, chart.BackBrush); SerializeBrush(code, "BoxBrush", chart, chart.BoxBrush); SerializeBrush(code, "TableBrush", chart, chart.TableBrush); SerializeBrush(code, "ArrowBrush", chart, chart.ArrowBrush); // Pens SerializePen(code, "BoxPen", chart, chart.BoxPen); SerializePen(code, "TablePen", chart, chart.TablePen); SerializePen(code, "ArrowPen", chart, chart.ArrowPen); // Text alignment SerializeTextFormat(code, "TextFormat", chart, chart.TextFormat); } return(codeObject); }
/// <summary> /// Serializes the specified object into a CodeDOM object. /// </summary> /// <param name="manager">The serialization manager to use during serialization.</param> /// <param name="value">The object to serialize.</param> /// <returns>A CodeDOM object representing the object that has been serialized.</returns> public override object Serialize(IDesignerSerializationManager manager, object value) { CodeDomSerializer baseClassSerializer = (CodeDomSerializer)manager.GetSerializer( typeof(UICultureChanger).BaseType, typeof(CodeDomSerializer)); CodeStatementCollection codeStatementCollection = (CodeStatementCollection)baseClassSerializer.Serialize( manager, value); string variableName = ((Component)value).Site.Name; // If the CodeStatementCollection only contains the constructor and/or member variable definition, // add comment-block with name of the member variable. if (codeStatementCollection.Count <= 2) { codeStatementCollection.Add(new CodeCommentStatement("")); codeStatementCollection.Add(new CodeCommentStatement(variableName)); codeStatementCollection.Add(new CodeCommentStatement("")); } // Add a call to the UICultureChanger.AddForm method. CodeMethodInvokeExpression codeMethodInvokeExpression = new CodeMethodInvokeExpression( new CodeFieldReferenceExpression(new CodeThisReferenceExpression(), variableName), "AddForm", new CodeExpression[] { new CodeThisReferenceExpression() }); codeStatementCollection.Add(codeMethodInvokeExpression); return(codeStatementCollection); }
public override object Serialize(IDesignerSerializationManager manager, object value) { CodeDomSerializer codeDomSerializer = (CodeDomSerializer)manager.GetSerializer(typeof(PlotToolBarButton).BaseType, typeof(CodeDomSerializer)); object obj = codeDomSerializer.Serialize(manager, value); CodeExpression codeExpression = base.SerializeToExpression(manager, value); if (codeExpression == null) { return(obj); } if (!(obj is CodeStatementCollection)) { return(obj); } CodeStatementCollection codeStatementCollection = (CodeStatementCollection)obj; CodeMethodInvokeExpression expression = new CodeMethodInvokeExpression(codeExpression, "LoadingBegin"); int index = 0; for (int i = 0; i < codeStatementCollection.Count; i++) { if (codeStatementCollection[i] is CodeCommentStatement) { index = i + 1; } } codeStatementCollection.Insert(index, new CodeExpressionStatement(expression)); expression = new CodeMethodInvokeExpression(codeExpression, "LoadingEnd"); codeStatementCollection.Add(expression); return(obj); }
public override object Serialize(IDesignerSerializationManager manager, object value) { CodeDomSerializer _codeDomSerializer = (CodeDomSerializer)manager.GetSerializer( typeof(MultiFunctionChartLegend).BaseType, typeof(CodeDomSerializer)); object _object = _codeDomSerializer.Serialize(manager, value); if (_object is CodeStatementCollection) { CodeStatementCollection _codeStatementCollection = (CodeStatementCollection)_object; CodeExpression _targetObject = base.GetExpression(manager, value); if (_targetObject != null) { CodePropertyReferenceExpression _codePropertyReferenceExpression = new CodePropertyReferenceExpression(_targetObject, "OwnerChart"); CodeAssignStatement _codeAssignStatement = new CodeAssignStatement(_codePropertyReferenceExpression, new CodeThisReferenceExpression()); _codeStatementCollection.Insert(0, _codeAssignStatement); CodeCommentStatement _codeCommentStatement = new CodeCommentStatement( new CodeComment("WARNING: This generates an exception in design time, but is ok (select 'Ignore and continue').")); _codeStatementCollection.Insert(0, _codeCommentStatement); } } return(_object); }
public override object Serialize(IDesignerSerializationManager manager, object value) { CodeDomSerializer serializer = GetBaseSerializer(manager); object returnObj = serializer.Serialize(manager, value); return(returnObj); }
public override object Serialize(IDesignerSerializationManager manager, object value) { try { CodeDomSerializer serial = (CodeDomSerializer)manager.GetSerializer(typeof(Component), typeof(CodeDomSerializer)); if (serial == null) { return(null); } CodeStatementCollection statements = (CodeStatementCollection)serial.Serialize(manager, value); IDesignerHost host = (IDesignerHost)manager.GetService(typeof(IDesignerHost)); if (host == value) { return(statements); } InsertCodeCommentHeader(statements); Calendar cdr = (Calendar)value; CodeExpression cnref = SerializeToExpression(manager, value); CodePropertyReferenceExpression propref = null; //CodeAssignStatement cassign = null; //cdr.CalendarStyle.CalendarHeader = new HeaderStyle(Font, foreColor, backColor, height); // CalendarStyle.CalendarHeader propref = new CodePropertyReferenceExpression(cnref, "CalendarStyle.CalendarHeader"); return(statements); } catch (Exception ex) { MessageBox.Show("Error during Serialize : " + ex.ToString()); return(null); } }
public override object Serialize(IDesignerSerializationManager manager, object value) { CodeDomSerializer _codeDomSerializer = (CodeDomSerializer)manager.GetSerializer( typeof(DXPlayer).BaseType, typeof(CodeDomSerializer)); object _object = _codeDomSerializer.Serialize(manager, value); if (_object is CodeStatementCollection) { CodeStatementCollection _codeStatementCollection = (CodeStatementCollection)_object; CodeExpression _targetObject = base.GetExpression(manager, value); if (_targetObject != null) { CodePropertyReferenceExpression _codePropertyReferenceExpression = new CodePropertyReferenceExpression(_targetObject, "Owner"); CodeAssignStatement _codeAssignStatement = new CodeAssignStatement( _codePropertyReferenceExpression, new CodeThisReferenceExpression()); _codeStatementCollection.Insert(0, _codeAssignStatement); } } return(_object); }
// See sample for the Deserialize method /// <summary> /// We customize the output from the default serializer here, adding /// a comment and an extra line of code. /// </summary> public override object Serialize(IDesignerSerializationManager manager, object value) { // first, locate and invoke the default serializer for // the ButtonArray's base class (UserControl) // CodeDomSerializer baseSerializer = (CodeDomSerializer)manager.GetSerializer(typeof(TaskBarButton).BaseType, typeof(CodeDomSerializer)); object codeObject = baseSerializer.Serialize(manager, value); // now add some custom code // if (codeObject is CodeStatementCollection) { // add a custom comment to the code. // CodeStatementCollection statements = (CodeStatementCollection)codeObject; //statements.Insert(0, new CodeCommentStatement("This is a custom comment added by a custom serializer on " + DateTime.Now.ToLongDateString())); // call a custom method. // CodeExpression targetObject = base.SerializeToExpression(manager, value); if (targetObject != null) { CodeExpression args = new CodeSnippetExpression("this.Handle"); CodeMethodInvokeExpression methodCall = new CodeMethodInvokeExpression(targetObject, "AddToWindow"); methodCall.Parameters.Add(args); statements.Add(methodCall); } } // finally, return the statements that have been created return(codeObject); }
public override object Serialize(IDesignerSerializationManager manager, object tempValue) { CodeDomSerializer baseSerializer = (CodeDomSerializer)manager.GetSerializer ( typeof(System.Collections.ArrayList), typeof(CodeDomSerializer) ); GridColumns columns = (GridColumns)tempValue; if ((columns.Count > 0) && (columns.HasDefaultColumn())) { ArrayList serializeColumns = new ArrayList(); foreach (GridColumn column in columns) { if (!(column is Alphora.Dataphor.DAE.Client.Controls.DataColumn)) { serializeColumns.Add(column); } } return(baseSerializer.Serialize(manager, serializeColumns)); } else { return(baseSerializer.Serialize(manager, tempValue)); } }
/// <summary> /// /// </summary> /// <param name="manager"></param> /// <param name="codeObject"></param> /// <returns></returns> public override object Deserialize(IDesignerSerializationManager manager, object codeObject) { // This is how we associate the component with the serializer. CodeDomSerializer baseClassSerializer = (CodeDomSerializer)manager.GetSerializer(typeof(Component), typeof(CodeDomSerializer)); return(baseClassSerializer.Deserialize(manager, codeObject)); }
public override object Deserialize(IDesignerSerializationManager manager, object codeDomObject) { CodeDomSerializer baseSerializer = (CodeDomSerializer)manager.GetSerializer(typeof(ResourceControl).BaseType, typeof(CodeDomSerializer)); return(baseSerializer.Deserialize(manager, codeDomObject)); }
public override object Serialize(IDesignerSerializationManager manager, object value) { CodeDomSerializer serializer1 = (CodeDomSerializer)manager.GetSerializer(this.GetPropType().BaseType, typeof(CodeDomSerializer)); object obj1 = serializer1.Serialize(manager, value); if (this.ShouldSerialize(value) && (obj1 is CodeStatementCollection)) { string text1 = manager.GetName(value); if ((text1 != null) && (text1 != string.Empty)) { CodeStatementCollection collection1 = (CodeStatementCollection)obj1; CodeExpression expression1 = base.SerializeToExpression(manager, value); IDesignerHost host1 = ((Component)value).Container as IDesignerHost; if (host1.RootComponent != null) { string text2 = manager.GetName(host1.RootComponent); if ((text2 != null) && (text2 != string.Empty)) { CodePropertyReferenceExpression expression2 = new CodePropertyReferenceExpression(expression1, this.GetPropName()); CodeExpression[] expressionArray1 = new CodeExpression[1] { new CodeTypeOfExpression(text2) }; expressionArray1 = new CodeExpression[1] { new CodePrimitiveExpression(text1 + ".XmlScheme") }; CodeMethodInvokeExpression expression3 = new CodeMethodInvokeExpression(new CodeObjectCreateExpression(typeof(ResourceManager), expressionArray1), "GetObject", expressionArray1); CodeCastExpression expression4 = new CodeCastExpression("System.String", expression3); CodeAssignStatement statement1 = new CodeAssignStatement(expression2, expression4); collection1.Add(statement1); } } } } return(obj1); }
public override object Serialize(IDesignerSerializationManager manager, object value) { CodeDomSerializer baseSerializer = (CodeDomSerializer)manager.GetSerializer(typeof(ResourceControl).BaseType, typeof(CodeDomSerializer)); object codeObject = baseSerializer.Serialize(manager, value); if (codeObject is CodeStatementCollection) { CodeStatementCollection statements = (CodeStatementCollection)codeObject; statements.Insert(0, new CodeCommentStatement("MLUResManager is used to set the custom resource file which in the another resource.dll.")); statements.Insert(0, new CodeCommentStatement("Must to set the BaseName property which is use to get the resource file name.")); CodeExpression targetObject = base.SerializeToExpression(manager, value); if (targetObject != null) { CodeExpression Paramter = new CodeArgumentReferenceExpression("ref resources"); CodeMethodInvokeExpression methodCall = new CodeMethodInvokeExpression(targetObject, "reInitResManger", Paramter); statements.Add(methodCall); } } return(codeObject); }
/// <summary> /// Deserializes the specified serialized CodeDOM object into an object. /// </summary> /// <param name="manager"> /// A serialization manager interface that is used during the deserialization process. /// </param> /// <param name="codeObject">A serialized CodeDOM object to deserialize.</param> /// <returns>The deserialized CodeDOM object.</returns> public override object Deserialize(IDesignerSerializationManager manager, object codeObject) { CodeDomSerializer baseClassSerializer = (CodeDomSerializer)manager.GetSerializer( typeof(UICultureChanger).BaseType, typeof(CodeDomSerializer)); return(baseClassSerializer.Deserialize(manager, codeObject)); }
public override object Serialize(IDesignerSerializationManager manager, object value) { CodeDomSerializer baseSerializer = (CodeDomSerializer)manager.GetSerializer(typeof(BvResourceManagerChanger).BaseType, typeof(CodeDomSerializer)); object codeObject = baseSerializer.Serialize(manager, value); if (codeObject is CodeStatementCollection) { CodeStatementCollection statements = (CodeStatementCollection)codeObject; Component component = (Component)value; IDesignerHost host = component.Site.GetService(typeof(IDesignerHost)) as IDesignerHost; if (host != null) { CodeCommentStatement comment = new CodeCommentStatement("Form Is Localizable: " + IsLocalizable(host)); statements.Insert(0, comment); if (IsLocalizable(host)) { CodeTypeDeclaration classTypeDeclaration = (CodeTypeDeclaration)manager.GetService(typeof(CodeTypeDeclaration)); CodeExpression typeofExpression = new CodeTypeOfExpression(classTypeDeclaration.Name); CodeDirectionExpression outResourceExpression = new CodeDirectionExpression(FieldDirection.Out, new CodeVariableReferenceExpression("resources")); CodeExpression rightCodeExpression = new CodeMethodInvokeExpression(new CodeTypeReferenceExpression("bv.common.Resources.BvResourceManagerChanger"), "GetResourceManager", new CodeExpression[] { typeofExpression, outResourceExpression }); statements.Insert(0, new CodeExpressionStatement(rightCodeExpression)); } } } return(codeObject); }
internal ProjectResourcesComponentCodeDomSerializer(CodeDomSerializer baseSerializer) { if (baseSerializer == null) { throw new ArgumentNullException("baseSerializer"); } this.baseSerializer = baseSerializer; }
public SerializableTypeCodeDomSerializer(CodeDomSerializer originalSerializer) { if (originalSerializer == null) { throw new ArgumentNullException("originalSerializer"); } this.originalSerializer = originalSerializer; }
/// <include file='doc\DesignerSerializationObject.uex' path='docs/doc[@for="DesignerSerializationObject.DesignerSerializationObject"]/*' /> /// <devdoc> /// Stores the collection of objects into our serialization object. /// The contents of the objects are not actually serialized until /// this object is serialized. /// </devdoc> public DesignerSerializationObject(IDesignerSerializationManager manager, CodeDomSerializer rootSerializer, ICollection objects) { this.manager = manager; this.rootSerializer = rootSerializer; this.code = null; this.objects = new object[objects.Count]; objects.CopyTo(this.objects, 0); }
/// <summary> /// /// </summary> /// <param name="manager"></param> /// <param name="value"></param> /// <returns></returns> public override object Serialize(IDesignerSerializationManager manager, object value) { CodeDomSerializer baseClassSerializer = (CodeDomSerializer)manager.GetSerializer(typeof(Component), typeof(CodeDomSerializer)); object codeObject = baseClassSerializer.Serialize(manager, value); if (value.GetType().GetInterface("IWSerializer") == null) { System.Windows.Forms.MessageBox.Show("Must not never reach here:" + value.GetType().ToString()); return(codeObject); } MethodInfo mInf = value.GetType().GetInterface("IWSerializer").GetMethod("ShouldSerialize"); if (codeObject is CodeStatementCollection) { CodeStatementCollection statements = (CodeStatementCollection)codeObject; //--- loop through all statements int count = statements.Count; for (int i = 0; i < count; i++) { CodeStatement st = statements[i]; if (st is CodeAssignStatement) { CodeAssignStatement cAssign = (CodeAssignStatement)st; // If left is eg. 'this.BorderColor' if (cAssign.Left is CodePropertyReferenceExpression) { /* if(cAssign.Right is CodeCastExpression){ * CodeCastExpression c = (CodeCastExpression)cAssign.Right; * if(c.Expression is CodeMethodInvokeExpression){ * CodeMethodInvokeExpression mI = (CodeMethodInvokeExpression)c.Expression; * if(mI.Method.TargetObject is CodeVariableReferenceExpression){ * CodeVariableReferenceExpression vR = (CodeVariableReferenceExpression)mI.Method.TargetObject; * System.Windows.Forms.MessageBox.Show(vR.); * } * } * }*/ string propertyName = ((CodePropertyReferenceExpression)cAssign.Left).PropertyName; //--- Check if we need to serialize property. if (!(bool)mInf.Invoke(value, new object[] { propertyName })) { statements.Remove(st); count--; i--; } } } } } return(codeObject); }
/// <summary> /// Serializes the specified object into a CodeDOM object. /// </summary> /// <param name="manager">A serialization manager interface that is used during the deserialization process.</param> /// <param name="value">The object to serialize.</param> /// <returns>A CodeDOM object representing the object that has been serialized.</returns> public override object Serialize(IDesignerSerializationManager manager, object value) { // Set serialization flag bool oldSerializationFlag = false; SerializationStatus oldSerializationStatus = SerializationStatus.None; Chart chart = value as Chart; if (chart != null) { oldSerializationFlag = chart.serializing; oldSerializationStatus = chart.serializationStatus; chart.serializing = true; chart.serializationStatus = SerializationStatus.Saving; } // Serialize object using the base class serializer object result = null; CodeDomSerializer baseSerializer = (CodeDomSerializer)manager.GetSerializer(typeof(Chart).BaseType, typeof(CodeDomSerializer)); if (baseSerializer != null) { result = baseSerializer.Serialize(manager, value); System.CodeDom.CodeStatementCollection statements = result as System.CodeDom.CodeStatementCollection; // Sustom serialization of the DataSource property if (statements != null && chart != null) { // Check if DataSource property is set if (chart.DataSource != null && chart.DataSource is String && ((String)chart.DataSource) != "(none)") { // Add assignment statement for the DataSource property System.CodeDom.CodeExpression targetObject = base.SerializeToExpression(manager, value); if (targetObject != null) { System.CodeDom.CodeAssignStatement assignStatement = new System.CodeDom.CodeAssignStatement( new System.CodeDom.CodePropertyReferenceExpression(targetObject, "DataSource"), new System.CodeDom.CodePropertyReferenceExpression(new System.CodeDom.CodeThisReferenceExpression(), (String)chart.DataSource)); statements.Add(assignStatement); } } } } // Clear serialization flag if (chart != null) { chart.serializing = oldSerializationFlag; chart.serializationStatus = oldSerializationStatus; } return(result); }
public override object Deserialize(IDesignerSerializationManager manager, object tempValue) { CodeDomSerializer baseSerializer = (CodeDomSerializer)manager.GetSerializer ( typeof(Alphora.Dataphor.DAE.Client.Controls.GridColumns).BaseType, typeof(CodeDomSerializer) ); return(baseSerializer.Deserialize(manager, tempValue)); }
public override object Deserialize(IDesignerSerializationManager manager, object codeObject) { try { CodeDomSerializer serial = (CodeDomSerializer)manager.GetSerializer(typeof(Component), typeof(CodeDomSerializer)); return(serial.Deserialize(manager, codeObject)); } catch (Exception ex) { MessageBox.Show("Error during Deserialize : " + ex.ToString()); return(null); } }
public override object Deserialize(IDesignerSerializationManager manager, object codeObject) { // This is how we associate the component with the serializer. CodeDomSerializer baseClassSerializer = (CodeDomSerializer)manager. GetSerializer(typeof(MyComponent).BaseType, typeof(CodeDomSerializer)); /* This is the simplest case, in which the class just calls the base class * to do the work. */ return(baseClassSerializer.Deserialize(manager, codeObject)); }
public override object Serialize(IDesignerSerializationManager manager, object value) { if (manager == null || value == null) { throw new ArgumentNullException((manager == null) ? "manager" : "value"); } CodeDomSerializer codeDomSerializer = (CodeDomSerializer)manager.GetSerializer(typeof(Component), typeof(CodeDomSerializer)); if (codeDomSerializer == null) { return(null); } object obj = codeDomSerializer.Serialize(manager, value); InheritanceAttribute inheritanceAttribute = (InheritanceAttribute)TypeDescriptor.GetAttributes(value)[typeof(InheritanceAttribute)]; InheritanceLevel inheritanceLevel = InheritanceLevel.NotInherited; if (inheritanceAttribute != null) { inheritanceLevel = inheritanceAttribute.InheritanceLevel; } if (inheritanceLevel != InheritanceLevel.InheritedReadOnly) { IDesignerHost designerHost = (IDesignerHost)manager.GetService(typeof(IDesignerHost)); if (designerHost != null) { PropertyDescriptor propertyDescriptor = TypeDescriptor.GetProperties(designerHost.RootComponent)["Localizable"]; if (propertyDescriptor != null && propertyDescriptor.PropertyType == typeof(bool) && (bool)propertyDescriptor.GetValue(designerHost.RootComponent)) { this.SerializeControlHierarchy(manager, designerHost, value); } } CodeStatementCollection codeStatementCollection = obj as CodeStatementCollection; if (codeStatementCollection != null) { Control control = (Control)value; if ((designerHost != null && control == designerHost.RootComponent) || this.HasSitedNonReadonlyChildren(control)) { this.SerializeSuspendLayout(manager, codeStatementCollection, value); this.SerializeResumeLayout(manager, codeStatementCollection, value); ControlDesigner controlDesigner = designerHost.GetDesigner(control) as ControlDesigner; var serializePerformLayoutProp = typeof(ControlDesigner).GetProperty("SerializePerformLayout", BindingFlags.NonPublic | BindingFlags.Instance); if (this.HasAutoSizedChildren(control) || (controlDesigner != null && (bool)serializePerformLayoutProp.GetValue(controlDesigner))) { this.SerializePerformLayout(manager, codeStatementCollection, value); } } if (this.HasMixedInheritedChildren(control)) { this.SerializeZOrder(manager, codeStatementCollection, control); } } } return(obj); }
public void GenerateCodeForSmartPartInfoCompiles() { DesignerSerializerAttribute attr = (DesignerSerializerAttribute)Attribute.GetCustomAttribute( typeof(SmartPartInfo), typeof(DesignerSerializerAttribute)); CodeDomSerializer serializer = (CodeDomSerializer)Activator.CreateInstance(Type.GetType(attr.SerializerTypeName)); UserControl smartPart = new UserControl(); Container container = new Container(); SmartPartInfo info1 = new SmartPartInfo("foo", ""); container.Add(info1, "info1"); MockSPI info2 = new MockSPI("bar", ""); container.Add(info2, "info2"); MockManager manager = new MockManager(container.Components); manager.Services.Add(typeof(IDesignerHost), new MockDesignerHost(smartPart, container)); manager.Services.Add(typeof(IReferenceService), new MockReferenceService(container.Components)); manager.Services.Add(typeof(IContainer), container); manager.Services.Add(typeof(IDesignerSerializationManager), manager); CodeTypeDeclaration declaration = new CodeTypeDeclaration("UserControl1"); CodeMemberMethod init = new CodeMemberMethod(); init.Name = "InitializeComponent"; declaration.Members.Add(init); // Add empty fields for both SPIs. declaration.Members.Add(new CodeMemberField(typeof(ISmartPartInfo), "info1")); declaration.Members.Add(new CodeMemberField(typeof(ISmartPartInfo), "info2")); manager.Services.Add(typeof(CodeTypeDeclaration), declaration); serializer.Serialize(manager, info1); serializer.Serialize(manager, info2); StringWriter sw = new StringWriter(); new Microsoft.CSharp.CSharpCodeProvider().GenerateCodeFromType( declaration, sw, new CodeGeneratorOptions()); sw.Flush(); //Console.WriteLine(sw.ToString()); CompilerResults results = new Microsoft.CSharp.CSharpCodeProvider().CompileAssemblyFromSource( new CompilerParameters(new string[] { "System.dll", new Uri(typeof(SmartPartInfo).Assembly.CodeBase).LocalPath }), sw.ToString()); Assert.IsFalse(results.Errors.HasErrors, ErrorsToString(results.Errors)); }
public override object Serialize(IDesignerSerializationManager manager, object value) { CodeDomSerializer serializer1 = GetSerializer(manager); if (serializer1 == null) { return(null); } return(serializer1.Serialize(manager, value)); }
public override object Serialize(IDesignerSerializationManager manager, object value) { if ((manager == null) || (value == null)) { throw new ArgumentNullException((manager == null) ? "manager" : "value"); } CodeDomSerializer serializer = (CodeDomSerializer)manager.GetSerializer(typeof(Component), typeof(CodeDomSerializer)); if (serializer == null) { return(null); } object obj2 = serializer.Serialize(manager, value); InheritanceAttribute attribute = (InheritanceAttribute)TypeDescriptor.GetAttributes(value)[typeof(InheritanceAttribute)]; InheritanceLevel notInherited = InheritanceLevel.NotInherited; if (attribute != null) { notInherited = attribute.InheritanceLevel; } if (notInherited != InheritanceLevel.InheritedReadOnly) { IDesignerHost service = (IDesignerHost)manager.GetService(typeof(IDesignerHost)); if (service != null) { PropertyDescriptor descriptor = TypeDescriptor.GetProperties(service.RootComponent)["Localizable"]; if (((descriptor != null) && (descriptor.PropertyType == typeof(bool))) && ((bool)descriptor.GetValue(service.RootComponent))) { this.SerializeControlHierarchy(manager, service, value); } } CodeStatementCollection statements = obj2 as CodeStatementCollection; if (statements == null) { return(obj2); } Control parent = (Control)value; if (((service != null) && (parent == service.RootComponent)) || this.HasSitedNonReadonlyChildren(parent)) { this.SerializeSuspendLayout(manager, statements, value); this.SerializeResumeLayout(manager, statements, value); ControlDesigner designer = service.GetDesigner(parent) as ControlDesigner; if (this.HasAutoSizedChildren(parent) || ((designer != null) && designer.SerializePerformLayout)) { this.SerializePerformLayout(manager, statements, value); } } if (this.HasMixedInheritedChildren(parent)) { this.SerializeZOrder(manager, statements, parent); } } return(obj2); }
/// <summary> /// Deserializes the specified serialized CodeDOM object into an object. /// </summary> /// <param name="manager">A serialization manager interface that is used during the deserialization process.</param> /// <param name="codeObject">A serialized CodeDOM object to deserialize.</param> /// <returns>The deserialized CodeDOM object.</returns> public override object Deserialize(IDesignerSerializationManager manager, object codeObject) { CodeDomSerializer baseSerializer = (CodeDomSerializer)manager.GetSerializer(typeof(Chart).BaseType, typeof(CodeDomSerializer)); if (baseSerializer != null) { return(baseSerializer.Deserialize(manager, codeObject)); } return(null); }
/// <summary> /// Deserializes a PaletteGroupView object from the code DOM. /// </summary> /// <param name="manager"></param> /// <param name="codeObject"></param> /// <returns></returns> public override object Deserialize(IDesignerSerializationManager manager, object codeObject) { object retVal = null; // Get base class serializer CodeDomSerializer baseSerializer = (CodeDomSerializer)manager.GetSerializer(typeof(GroupView), typeof(CodeDomSerializer)); if (baseSerializer != null) { // Deserialize palette group view using base class serializer retVal = baseSerializer.Deserialize(manager, codeObject); if (retVal != null) { // Downcast to PaletteGroupView PaletteGroupView palGrpVw = retVal as PaletteGroupView; if (palGrpVw != null) { // Load symbol palette from the resource file and attach // to the palette group view string resName = palGrpVw.Name + "." + "Palette"; System.ComponentModel.Design.IResourceService resSvc = manager.GetService(typeof(System.ComponentModel.Design.IResourceService)) as System.ComponentModel.Design.IResourceService; if (resSvc != null) { System.Resources.IResourceReader resReader = resSvc.GetResourceReader(System.Globalization.CultureInfo.InvariantCulture); if (resReader != null) { // Iterate through the resource file using the resource // reader and find the byte stream for the palette byte[] strmData = null; bool resFound = false; IDictionaryEnumerator resEnum = resReader.GetEnumerator(); while (resEnum.MoveNext() && !resFound) { if ((string)resEnum.Key == resName) { strmData = (byte[])resEnum.Value; resFound = true; } } if (resFound && strmData != null) { palGrpVw.LoadPalette(strmData); } } } } } } return(retVal); }
public CodeDomSerializationProvider () { _componentSerializer = new ComponentCodeDomSerializer (); _propertySerializer = new PropertyCodeDomSerializer (); _eventSerializer = new EventCodeDomSerializer (); _collectionSerializer = new CollectionCodeDomSerializer (); _primitiveSerializer = new PrimitiveCodeDomSerializer (); _rootSerializer = new RootCodeDomSerializer (); _enumSerializer = new EnumCodeDomSerializer (); _othersSerializer = new CodeDomSerializer (); }
protected override void PerformLoad (IDesignerSerializationManager manager) { if (manager == null) throw new ArgumentNullException ("manager"); CodeCompileUnit document = this.Parse (); if (document == null) throw new NotSupportedException ("The language did not provide a code parser for this file"); string namespaceName = null; CodeTypeDeclaration rootDocument = ExtractFirstCodeTypeDecl (document, out namespaceName); if (rootDocument == null) throw new InvalidOperationException ("Cannot find a declaration in a namespace to load."); _rootSerializer = manager.GetSerializer (manager.GetType (rootDocument.Name), typeof (RootCodeDomSerializer)) as CodeDomSerializer; if (_rootSerializer == null) throw new InvalidOperationException ("Serialization not supported for this class"); _rootSerializer.Deserialize (manager, rootDocument); base.SetBaseComponentClassName (namespaceName + "." + rootDocument.Name); }