⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 vsnetcollector.cs

📁 UML设计相关的源码。作UML相关开发的不容错过。
💻 CS
📖 第 1 页 / 共 4 页
字号:
					parameterData.Name        = codeParameter.Name;

				}
				else if( codeElement.Kind == vsCMElement.vsCMElementVariable )
				{
					///
					/// Variable Type
					///
					EnvDTE.CodeVariable codeVariable = (EnvDTE.CodeVariable) codeElement;

					// Save Data
					VariableData variableData     = new VariableData();
					variableData.Parent           = parentElementData;
					variableData.VSObjectReference= codeVariable;

					// Save this object
					parentElementData.AddMember( variableData );

					variableData.AccessType   = (Data.enumElementAccessType) codeVariable.Access;
					variableData.ElementType  = enumElementType.elementTypeVariable;
					variableData.DocComment   = codeVariable.DocComment;
					variableData.Name         = codeVariable.Name;
					variableData.IsConstant   = codeVariable.IsConstant;
					variableData.IsShared     = codeVariable.IsShared;
					variableData.InitExpression = codeVariable.InitExpression;
				
					// Save the Phototypes data 
					EnvDTE.CodeVariable source      = codeVariable;
					VariableData        destination = variableData;
					{
						destination.PhotoType.className         = source.get_Prototype((int) vsCMPrototype.vsCMPrototypeClassName );
						destination.PhotoType.fullName          = source.get_Prototype((int) vsCMPrototype.vsCMPrototypeFullname );
						destination.PhotoType.noName            = source.get_Prototype((int) vsCMPrototype.vsCMPrototypeNoName );
						destination.PhotoType.paramDefaultValus = source.get_Prototype((int) vsCMPrototype.vsCMPrototypeParamDefaultValues );
						destination.PhotoType.paramNames        = source.get_Prototype((int) vsCMPrototype.vsCMPrototypeParamNames );
						destination.PhotoType.paramTypes        = source.get_Prototype((int) vsCMPrototype.vsCMPrototypeParamTypes );
						destination.PhotoType.phototypeInitExpression = source.get_Prototype((int) vsCMPrototype.vsCMPrototypeInitExpression );
						destination.PhotoType.phototypeType     = source.get_Prototype((int) vsCMPrototype.vsCMPrototypeType );
						destination.PhotoType.uniqueSignature   = source.get_Prototype((int) vsCMPrototype.vsCMPrototypeUniqueSignature );
					}
				}

			}

			/// <summary>
			/// Collect function data from EnvDTE.CodeFunction object
			/// </summary>
			/// <param name="codeFunction">ref: EnvDTE.CodeFunction</param>
			/// <param name="functionData">ref: FunctionData</param>
			private void CollectFunctionData( EnvDTE.CodeFunction codeFunction, FunctionData functionData )
			{
				functionData.ElementType       = enumElementType.elementTypeFunction;
				functionData.VSObjectReference = codeFunction;
				// Save Data
				functionData.AccessType   = (Data.enumElementAccessType) codeFunction.Access;
				//functionData.Comment      = codeFunction.Comment;
				functionData.DocComment   = codeFunction.DocComment;
				functionData.Name         = codeFunction.Name;
				functionData.CanOverride  = codeFunction.CanOverride;
				functionData.FunctionType = (Data.enumFunctionType) codeFunction.FunctionKind;
				functionData.IsOverloaded = codeFunction.IsOverloaded;
				functionData.IsShared     = codeFunction.IsShared;
				
				// Get the parameter data
				if( codeFunction.Parameters.Count > 0 )
				{
					for( int i = 0 ; i < codeFunction.Parameters.Count ; i ++ )
					{
						CollectElementData( codeFunction.Parameters.Item(i+1), functionData );
					}
				}

				// Save the Phototypes data 
				EnvDTE.CodeFunction source      = codeFunction;
				FunctionData        destination = functionData;
			{
				destination.PhotoType.className         = source.get_Prototype((int) vsCMPrototype.vsCMPrototypeClassName );
				destination.PhotoType.fullName          = source.get_Prototype((int) vsCMPrototype.vsCMPrototypeFullname );
				destination.PhotoType.noName            = source.get_Prototype((int) vsCMPrototype.vsCMPrototypeNoName );
				destination.PhotoType.paramDefaultValus = source.get_Prototype((int) vsCMPrototype.vsCMPrototypeParamDefaultValues );
				destination.PhotoType.paramNames        = source.get_Prototype((int) vsCMPrototype.vsCMPrototypeParamNames );
				destination.PhotoType.paramTypes        = source.get_Prototype((int) vsCMPrototype.vsCMPrototypeParamTypes );
				destination.PhotoType.phototypeInitExpression = source.get_Prototype((int) vsCMPrototype.vsCMPrototypeInitExpression );
				destination.PhotoType.phototypeType     = source.get_Prototype((int) vsCMPrototype.vsCMPrototypeType );
				destination.PhotoType.uniqueSignature   = source.get_Prototype((int) vsCMPrototype.vsCMPrototypeUniqueSignature );
			}
	
			}

			public void WriteToFile( String fileName )
			{
				try
				{
					XmlTextWriter xmlWriter = new XmlTextWriter( fileName, System.Text.Encoding.UTF8 );
				
					// Write file header
					WriteHeader( xmlWriter );
				
					// First Write Solutions
					xmlWriter.WriteStartElement( "Solution" );
					SolutionData sluData = (SolutionData) codeData.SolutionList[0];
					xmlWriter.WriteAttributeString( "Name", sluData.Name );
			
			
					for( int nProjectIndex = 0 ; nProjectIndex < sluData.Element.Count; nProjectIndex ++ )
					{
						// Then Write Projects
						ProjectData prjData  = (ProjectData) sluData.Element[nProjectIndex]; 
				
						xmlWriter.WriteStartElement( "Project" );
						xmlWriter.WriteAttributeString( "Name", prjData.Name );

						for( int nProjectItemIndex = 0 ; nProjectItemIndex < prjData.Element.Count ; nProjectItemIndex ++ )
						{
							ProjectItemData prjItemData = (ProjectItemData) prjData.Element[nProjectItemIndex];

							// Get Code Elements Data
							// Only one element in those collections
							CodeModelData codeModelData = (CodeModelData) prjItemData.Element[0];
							CodeElementsData codeElementData = (CodeElementsData) codeModelData.Element[0];
							//*****************MODIFY BY 06/10/2002*********************//
							// Add Output ProjectItem Data                              //
							// Used to generate code                                    //
							//**********************************************************//
							xmlWriter.WriteStartElement( "ProjectItem" );
							xmlWriter.WriteAttributeString( "Name", prjItemData.Name );
						
							for( int nCodeElementIndex = 0 ; nCodeElementIndex < codeElementData.Element.Count ; nCodeElementIndex ++ )
							{
								WriteElements( xmlWriter, (ElementData) codeElementData.Element[nCodeElementIndex] );
							}

							xmlWriter.WriteEndElement();   // Project Item Element End
						}
						xmlWriter.WriteEndElement();  // Project Element End
					}
					xmlWriter.WriteEndElement();  // Solution Element End

					xmlWriter.Close();
				}
				catch ( Exception e )
				{
				
				}
			}

			/// <summary>
			/// Parse data elements and writer it into xml files
			/// </summary>
			/// <param name="xmlWriter"></param>
			/// <param name="elementData"></param>
			private void WriteElements( XmlTextWriter xmlWriter, ElementData elementData )
			{
				// Write each elements
				if( elementData.ElementType == enumElementType.elementTypeUnknow )
				{
					// Initialization a new element data object
					xmlWriter.WriteStartElement( "UnknowType" );
					xmlWriter.WriteAttributeString( "Name", elementData.Name );
					xmlWriter.WriteEndElement();
				}
				else if( elementData.ElementType == enumElementType.elementTypeNameSpace )
				{	
					///
					/// Namespace Type
					///
					WriteNameSpaceData( xmlWriter, (NameSpaceData) elementData );

				}
				else if( elementData.ElementType == enumElementType.elementTypeClass )
				{
					///
					/// Class Type
					///
					WriteClassData( xmlWriter, (ClassData) elementData );
				}
				else if( elementData.ElementType == enumElementType.elementTypeDelegate )
				{
					///
					/// Delegate Type
					///
					WriteDelegateData( xmlWriter, (DelegateData) elementData );
				
				}
				else if( elementData.ElementType == enumElementType.elementTypeEnum )
				{
					///
					/// Enum Type
					///
					WriteEnumData( xmlWriter, (EnumData) elementData );
				
				}
				else if( elementData.ElementType == enumElementType.elementTypeFunction )
				{
					///
					/// Function Type
					///
					WriteFunctionData( xmlWriter, (FunctionData) elementData );

				}
				else if( elementData.ElementType == enumElementType.elementTypeInterface )
				{
					///
					/// Interface Type
					///
					WriteInterfaceData( xmlWriter, (InterfaceData) elementData );

				}
				else if( elementData.ElementType == enumElementType.elementTypeProperty )
				{
					///
					/// Property Type
					/// 
					WritePropertyData( xmlWriter, (PropertyData) elementData);

				}
				else if( elementData.ElementType == enumElementType.elementTypeStruct )
				{
					///
					/// Struct Type
					///
					WriteStructData( xmlWriter, (StructData) elementData);
				
				}
				else if( elementData.ElementType == enumElementType.elementTypeParameter )
				{	
					///
					/// Parameter Type
					///
					WriteParameterData( xmlWriter, (ParameterData) elementData );
				}
			}

			private void WriteParameterData( XmlTextWriter xmlWriter, ParameterData parameterData )
			{
				///
				/// Parameter Type
				///
				// Initialization a new element data object
				xmlWriter.WriteStartElement( "Parameter" );
				xmlWriter.WriteAttributeString( "Name", parameterData.Name );

				if( IsWriteObjectInfo == true )
				{
					xmlWriter.WriteAttributeString( "Parent", parameterData.Parent.ToString() );
					xmlWriter.WriteAttributeString( "VSObjectReference", parameterData.VSObjectReference.ToString() );
				}
				xmlWriter.WriteEndElement();
			}

			private void WriteClassData( XmlTextWriter xmlWriter, ClassData classData )
			{
				///
				/// Class Type
				///
				xmlWriter.WriteStartElement( "Class" );
				xmlWriter.WriteAttributeString( "Name", classData.Name );
				xmlWriter.WriteAttributeString( "IsAbstract", XmlConvert.ToString(classData.IsAbstract) );
				xmlWriter.WriteAttributeString( "AccessType", classData.AccessType.ToString() );
				xmlWriter.WriteAttributeString( "Comment", classData.DocComment );
				if( IsWriteObjectInfo == true )
				{
					xmlWriter.WriteAttributeString( "Parent", classData.Parent.ToString() );
					xmlWriter.WriteAttributeString( "VSObjectReference", classData.VSObjectReference.ToString() );
					xmlWriter.WriteAttributeString( "ParentNameSpace", classData.ParentNameSpaceName );
				}

				// Bulid parent class name to ClassData.BaseList
				if( classData.BaseList.Count > 0 )
				{
					for( int i = 0; i < classData.BaseList.Count; i ++ )
					{
						xmlWriter.WriteAttributeString( "BaseClass", classData.BaseList[i].ToString() );
					}
				}

				// Check weather this class contain members
				if( classData.Element.Count > 0 )
				{
					for( int i = 0; i < classData.Element.Count; i ++ )
					{
						WriteElements( xmlWriter, (ElementData) classData.Element[i] );
					}
				}
				xmlWriter.WriteEndElement();
			}

			private void WriteDelegateData( XmlTextWriter xmlWriter, DelegateData delegateData )
			{
				///
				/// Delegate Type
				///
				xmlWriter.WriteStartElement( "Delegate" );
				xmlWriter.WriteAttributeString( "Name", delegateData.Name );
				xmlWriter.WriteAttributeString( "AccessType", delegateData.AccessType.ToString() );
				xmlWriter.WriteAttributeString( "Comment", delegateData.DocComment );
				if( IsWriteObjectInfo == true )
				{
					xmlWriter.WriteAttributeString( "Parent", delegateData.Parent.ToString() );
					xmlWriter.WriteAttributeString( "VSObjectReference", delegateData.VSObjectReference.ToString() );
					xmlWriter.WriteAttributeString( "ParentNameSpace", delegateData.ParentNameSpaceName );
				}

				// Save the Phototypes data 
				xmlWriter.WriteStartElement( "Phototypes" );
				DelegateData        destination = delegateData;
			{
				xmlWriter.WriteAttributeString( "ClassName",destination.PhotoType.className );
				xmlWriter.WriteAttributeString( "fullName",destination.PhotoType.fullName );        
				xmlWriter.WriteAttributeString( "noName",destination.PhotoType.noName );          
				xmlWriter.WriteAttributeString( "paramDefaultValus",destination.PhotoType.paramDefaultValus );
				xmlWriter.WriteAttributeString( "paramNames",destination.PhotoType.paramNames );
				xmlWriter.WriteAttributeString( "paramTypes",destination.PhotoType.paramTypes );
				xmlWriter.WriteAttributeString( "phototypeInitExpression",destination.PhotoType.phototypeInitExpression );
				xmlWriter.WriteAttributeString( "phototypeType",destination.PhotoType.phototypeType );
				xmlWriter.WriteAttributeString( "uniqueSignature",destination.PhotoType.uniqueSignature );
			}
				xmlWriter.WriteEndElement(); // Phototypes end
			
				// Get the parameter data

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -