📄 data2xml.cs
字号:
{
itemData.PhotoType.fullName = xmlReader.Value;
}
else if( xmlReader.Name == "noName" )
{
itemData.PhotoType.noName = xmlReader.Value;
}
else if( xmlReader.Name == "paramDefaultValus" )
{
itemData.PhotoType.paramDefaultValus = xmlReader.Value;
}
else if( xmlReader.Name == "paramNames" )
{
itemData.PhotoType.paramNames = xmlReader.Value;
}
else if( xmlReader.Name == "paramTypes" )
{
itemData.PhotoType.paramTypes = xmlReader.Value;
}
else if( xmlReader.Name == "phototypeInitExpression" )
{
itemData.PhotoType.phototypeInitExpression = xmlReader.Value;
}
else if( xmlReader.Name == "phototypeType" )
{
itemData.PhotoType.phototypeType = xmlReader.Value;
}
else if( xmlReader.Name == "uniqueSignature" )
{
itemData.PhotoType.uniqueSignature = xmlReader.Value;
}
}
// Read the </PhotoType> tag
xmlReader.Read();
if( xmlReader.NodeType != XmlNodeType.EndElement )
throw new Exception( "Unexpected end of Phototype tag!" );
}
else throw new Exception( "After property data must be Phototype data" );
// Next parse
{
bool bJumpHigher = false;
do
{
bJumpHigher = DispatchReadAction( xmlReader, propertyData );
}while( bJumpHigher == false );
}
}
/// <summary>
/// Read the element data ( attribute )
/// </summary>
/// <param name="xmlReader">XMLTextReader class</param>
/// <param name="elementData">ElementData class</param>
private static void ReadStruct( XmlTextReader xmlReader, ElementData elementData )
{
if( xmlReader.AttributeCount <= 0 )
throw new Exception( "Struct Item attribute cannot be zero! This is not my fault" );
StructData structData = new StructData();
elementData.AddMember( structData );
structData.Parent = elementData;
// here i should be 4
for( int i = 0 ; i < xmlReader.AttributeCount ; i ++ )
{
xmlReader.MoveToAttribute(i);
if( xmlReader.Name == "Name" )
{
structData.Name = xmlReader.Value;
}
else if( xmlReader.Name == "AccessType" )
{
structData.AccessType = AssignAccessType ( xmlReader.Value );
}
else if( xmlReader.Name == "Comment" )
{
structData.DocComment = xmlReader.Value;
}
else if( xmlReader.Name == "IsAbstract" )
{
structData.IsAbstract = xmlReader.Value == "true" ? true : false;
}
else if( xmlReader.Name == "BaseClass" )
{
structData.BaseList.Add( xmlReader.Value );
}
}
// Next parse
{
bool bJumpHigher = false;
do
{
bJumpHigher = DispatchReadAction( xmlReader, structData );
}while( bJumpHigher == false );
}
}
/// <summary>
/// Read the element data ( attribute )
/// </summary>
/// <param name="xmlReader">XMLTextReader class</param>
/// <param name="elementData">ElementData class</param>
private static void ReadVariable( XmlTextReader xmlReader, ElementData elementData )
{
if( xmlReader.AttributeCount <= 0 )
throw new Exception( "VariableData Item attribute cannot be zero! This is not my fault" );
VariableData variableData = new VariableData();
elementData.AddMember( variableData );
variableData.Parent = elementData;
for( int i = 0 ; i < xmlReader.AttributeCount ; i ++ )
{
xmlReader.MoveToAttribute(i);
if( xmlReader.Name == "Name" )
{
variableData.Name = xmlReader.Value;
}
else if( xmlReader.Name == "AccessType" )
{
variableData.AccessType = AssignAccessType ( xmlReader.Value );
}
else if( xmlReader.Name == "InitExpression" )
{
variableData.InitExpression = xmlReader.Value;
}
else if( xmlReader.Name == "IsShared" )
{
variableData.IsShared = xmlReader.Value == "true" ? true : false;
}
else if( xmlReader.Name == "IsConstant" )
{
variableData.IsConstant = xmlReader.Value == "true" ? true : false;
}
else if( xmlReader.Name == "Comment" )
{
variableData.DocComment = xmlReader.Value;
}
}
// This are MUST be PhotoTypes, otherwise send exception error message
xmlReader.Read();
VariableData itemData = variableData;
if( xmlReader.Name == "Phototypes" )
{
for( int i = 0 ; i < xmlReader.AttributeCount ; i ++ )
{
xmlReader.MoveToAttribute(i);
if( xmlReader.Name == "ClassName" )
{
itemData.PhotoType.className = xmlReader.Value;
}
else if( xmlReader.Name == "fullName" )
{
itemData.PhotoType.fullName = xmlReader.Value;
}
else if( xmlReader.Name == "noName" )
{
itemData.PhotoType.noName = xmlReader.Value;
}
else if( xmlReader.Name == "paramDefaultValus" )
{
itemData.PhotoType.paramDefaultValus = xmlReader.Value;
}
else if( xmlReader.Name == "paramNames" )
{
itemData.PhotoType.paramNames = xmlReader.Value;
}
else if( xmlReader.Name == "paramTypes" )
{
itemData.PhotoType.paramTypes = xmlReader.Value;
}
else if( xmlReader.Name == "phototypeInitExpression" )
{
itemData.PhotoType.phototypeInitExpression = xmlReader.Value;
}
else if( xmlReader.Name == "phototypeType" )
{
itemData.PhotoType.phototypeType = xmlReader.Value;
}
else if( xmlReader.Name == "uniqueSignature" )
{
itemData.PhotoType.uniqueSignature = xmlReader.Value;
}
}
// Read the </PhotoType> tag
xmlReader.Read();
if( xmlReader.NodeType != XmlNodeType.EndElement )
throw new Exception( "Unexpected end of Phototype tag!" );
}
else throw new Exception( "After Variable data must be Phototype data" );
// Next parse
{
bool bJumpHigher = false;
do
{
bJumpHigher = DispatchReadAction( xmlReader, variableData );
}while( bJumpHigher == false );
}
}
/// <summary>
/// Read a element and dispatch to curresponding function
/// </summary>
/// <param name="xmlReader">XmlTextRader Object</param>
/// <param name="elementData">ElementData class</param>
private static bool DispatchReadAction( XmlTextReader xmlReader, ElementData elementData )
{
// Read first element
if( xmlReader.Read() == false )
return true;
// ************************************************************//
// Changed 07/10/2002 //
// Don't use elementType as a return type //
// used to return current type //
//*************************************************************//
enumElementType elementType = enumElementType.elementTypeUnknow;
// Here we use bool to identify whether jump to higher level
// If xmlReader read the node type as EndElement, it's time
// to jump to higher level
bool endElement = false;
if( xmlReader.NodeType == XmlNodeType.EndElement )
return true;
else if( xmlReader.NodeType != XmlNodeType.Element )
return endElement;
// if xmlReader.IsStartElement == true
// That's mean's this object must belong's
// upper object
// otherwise use object.parent as a parameter
//if( !xmlReader.IsStartElement() )
//{
// elementData = (ElementData) elementData.Parent;
//}
if( xmlReader.Name == "Project" )
{
ReadProject( xmlReader, elementData );
elementType = enumElementType.elementTypeProject;
}
else if( xmlReader.Name == "ProjectItem" )
{
ReadProjectItem( xmlReader, elementData );
elementType = enumElementType.elementTypeProjectItem;
}
else if( xmlReader.Name == "Namespace" )
{
ReadNameSpace( xmlReader, elementData );
elementType = enumElementType.elementTypeNameSpace;
}
else if( xmlReader.Name == "Class" )
{
ReadClass( xmlReader, elementData );
elementType = enumElementType.elementTypeClass;
}
else if( xmlReader.Name == "Delegate" )
{
ReadDelegate( xmlReader, elementData );
elementType = enumElementType.elementTypeDelegate;
}
else if( xmlReader.Name == "Interface" )
{
ReadInterface( xmlReader, elementData );
elementType = enumElementType.elementTypeInterface;
}
else if( xmlReader.Name == "Enum" )
{
ReadEnum( xmlReader, elementData );
elementType = enumElementType.elementTypeEnum;
}
else if( xmlReader.Name == "Parameter" )
{
ReadParameter( xmlReader, elementData );
elementType = enumElementType.elementTypeParameter;
}
else if( xmlReader.Name == "Property" )
{
ReadProperty( xmlReader, elementData );
elementType = enumElementType.elementTypeProperty;
}
else if( xmlReader.Name == "Struct" )
{
ReadStruct( xmlReader, elementData );
elementType = enumElementType.elementTypeStruct;
}
else if( xmlReader.Name == "Variable" )
{
ReadVariable( xmlReader, elementData );
elementType = enumElementType.elementTypeVariable;
}
else if( xmlReader.Name == "Function" )
{
ReadFunction( xmlReader, elementData );
elementType = enumElementType.elementTypeFunction;
}
return endElement;
}
/// <summary>
/// Help function
/// Convert String to enumElementAccessType
/// </summary>
/// <param name="strType"></param>
/// <returns></returns>
private static enumElementAccessType AssignAccessType( String strType )
{
enumElementAccessType accessType = enumElementAccessType.accessTypeUnknow;
if( strType == "accessTypePublic" )
accessType = enumElementAccessType.accessTypePublic;
if( strType == "accessTypePrivate" )
accessType = enumElementAccessType.accessTypePrivate;
if( strType == "accessTypeProject" )
accessType = enumElementAccessType.accessTypeProject;
if( strType == "accessTypeProtected" )
accessType = enumElementAccessType.accessTypeProtected;
if( strType == "accessTypeProjectOrProtected" )
accessType = enumElementAccessType.accessTypeProjectOrProtected;
if( strType == "accessTypeDefault" )
accessType = enumElementAccessType.accessTypeDefault;
if( strType == "accessTypeAssemblyOrFamily" )
accessType = enumElementAccessType.accessTypeAssemblyOrFamily;
return accessType;
}
/// <summary>
/// Help function
/// Convert String to enumFunctionType
/// </summary>
/// <param name="strType"></param>
/// <returns></returns>
private static enumFunctionType AssignFunctionType( String strType )
{
enumFunctionType functionType = enumFunctionType.functionTypeUnknow;
if( strType == "functionTypeConstructor" )
functionType = enumFunctionType.functionTypeConstructor;
if( strType == "functionTypePropertyGet" )
functionType = enumFunctionType.functionTypePropertyGet;
if( strType == "functionTypePropertyLet" )
functionType = enumFunctionType.functionTypePropertyLet;
if( strType == "functionTypePropertySet" )
functionType = enumFunctionType.functionTypePropertySet;
if( strType == "functionTypePutRef" )
functionType = enumFunctionType.functionTypePutRef;
if( strType == "functionTypePropertyAssign" )
functionType = enumFunctionType.functionTypePropertyAssign;
if( strType == "functionTypeSub" )
functionType = enumFunctionType.functionTypeSub;
if( strType == "functionTypeFunction" )
functionType = enumFunctionType.functionTypeFunction;
if( strType == "functionTypeTopLevel" )
functionType = enumFunctionType.functionTypeTopLevel;
if( strType == "functionTypeDestructor" )
functionType = enumFunctionType.functionTypeDestructor;
if( strType == "functionTypeOperatior" )
functionType = enumFunctionType.functionTypeOperatior;
if( strType == "functionTypeVirtual" )
functionType = enumFunctionType.functionTypeVirtual;
if( strType == "functionTypePure" )
functionType = enumFunctionType.functionTypePure;
if( strType == "functionTypeConstant" )
functionType = enumFunctionType.functionTypeConstant;
if( strType == "functionTypeShared" )
functionType = enumFunctionType.functionTypeShared;
if( strType == "functionTypeInline" )
functionType = enumFunctionType.functionTypeInline;
return functionType;
}
#endregion // End Reader
/// <summary>
/// Used only for output debug info
/// Describes wheather output the object information to the xml files
/// </summary>
private static bool IsWriteObjectInfo = false;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -