private int WriteTypeDeclaration(ITypeDeclaration typeDeclaration, ILanguageWriterConfiguration configuration)
        {
            ILanguage language = LanguageManager.ActiveLanguage;
            ITranslator translator = TranslatorManager.CreateDisassembler("Xml", null);

            int exceptions = 0;
            using (StreamWriter streamWriter = CreateTypeDeclarationFile(typeDeclaration))
            {
                INamespace namespaceItem = new Namespace();
                namespaceItem.Name = typeDeclaration.Namespace;

                TextFormatter formatter = new TextFormatter();
                ILanguageWriter writer = language.GetWriter(formatter, configuration);
                try
                {
                    if (language.Translate)
                    {
                        typeDeclaration = translator.TranslateTypeDeclaration(typeDeclaration, true, true);
                    }
                    namespaceItem.Types.Add(typeDeclaration);

                    #region 2010-11-11 lhm  字段, 方法加入完整的命名空间
                    string strnamespace;
                    string strname;
                    string strfield;
                    foreach (IFieldDeclaration fieldDeclaration in typeDeclaration.Fields)
                    {
                        IFieldDeclaration fieldDeclaration2 = translator.TranslateFieldDeclaration(fieldDeclaration);
                        //(((Reflector.CodeModel.Memory.ArrayCreateExpression))((fieldDeclaration).Initializer)).Type
                        if ((fieldDeclaration).Initializer is Reflector.CodeModel.Memory.ArrayCreateExpression) //字段为数组类型并且初始化了值
                        {
                            strnamespace = ((((Reflector.CodeModel.Memory.ArrayCreateExpression)fieldDeclaration.Initializer).Type as Reflector.CodeModel.IType) as ITypeReference).Namespace;
                            strname = ((((Reflector.CodeModel.Memory.ArrayCreateExpression)fieldDeclaration.Initializer).Type as Reflector.CodeModel.IType) as ITypeReference).Name;
                        }
                        else if (((Reflector.CodeModel.Memory.FieldDeclaration)(fieldDeclaration)).FieldType is Reflector.CodeModel.IArrayType)//字段为数组类型无初始化值
                        {
                            strnamespace = ((((Reflector.CodeModel.IArrayType)((((Reflector.CodeModel.Memory.FieldDeclaration)(fieldDeclaration)).FieldType)))).ElementType as ITypeReference).Namespace;
                            strname = ((((Reflector.CodeModel.IArrayType)((((Reflector.CodeModel.Memory.FieldDeclaration)(fieldDeclaration)).FieldType)))).ElementType as ITypeReference).Name;
                        }
                        else
                        {
                            strnamespace = ((((Reflector.CodeModel.Memory.FieldDeclaration)(fieldDeclaration2)).FieldType as Reflector.CodeModel.IType) as ITypeReference).Namespace;
                            strname = ((((Reflector.CodeModel.Memory.FieldDeclaration)(fieldDeclaration2)).FieldType as Reflector.CodeModel.IType) as ITypeReference).Name;
                        }
                        strfield = fieldDeclaration2.Name;
                        streamWriter.WriteLine(string.Format("//#hmstart-{0}.{1} {2}#hmend", strnamespace, strname, strfield));
                    }

                    streamWriter.WriteLine(("//Type: " + typeDeclaration.Namespace + "." + typeDeclaration.Name));

                    foreach (IMethodDeclaration methodDeclaration in typeDeclaration.Methods)
                    {
                        streamWriter.WriteLine(("//Method: " + methodDeclaration));

                        int icount = ((Reflector.CodeModel.Memory.MethodDeclaration)(methodDeclaration)).Parameters.Count;
                        if (icount ==0) continue;
                        foreach (IParameterDeclaration fieldDeclaration in ((Reflector.CodeModel.Memory.MethodDeclaration)(methodDeclaration)).Parameters)
                        {
                            if (fieldDeclaration.ParameterType is Reflector.CodeModel.Memory.ArrayType)
                            {
                                strnamespace = ((((Reflector.CodeModel.Memory.ArrayType)((fieldDeclaration.ParameterType as Reflector.CodeModel.IType)))).ElementType as ITypeReference).Namespace;
                                strname = ((((Reflector.CodeModel.Memory.ArrayType)((fieldDeclaration.ParameterType as Reflector.CodeModel.IType)))).ElementType as ITypeReference).Name;

                            }
                            else if (fieldDeclaration.ParameterType is Reflector.CodeModel.Memory.ReferenceType)
                            {
                                strnamespace = ((((Reflector.CodeModel.Memory.ReferenceType)((fieldDeclaration.ParameterType as Reflector.CodeModel.IType)))).ElementType as ITypeReference).Namespace;
                                strname = ((((Reflector.CodeModel.Memory.ReferenceType)((fieldDeclaration.ParameterType as Reflector.CodeModel.IType)))).ElementType as ITypeReference).Name;
                            }
                            else
                            {
                                strnamespace = ((fieldDeclaration.ParameterType as Reflector.CodeModel.IType) as ITypeReference).Namespace;
                                strname = ((fieldDeclaration.ParameterType as Reflector.CodeModel.IType) as ITypeReference).Name;

                            }
                            strfield = fieldDeclaration.Name;
                            streamWriter.WriteLine(string.Format("//#p_hmstart-{0}.{1} {2}#p_hmend", strnamespace, strname, strfield));
                        }
                    }
                    #endregion
                }
                catch (Exception ex)
                {
                    streamWriter.WriteLine(ex.ToString());
                    WriteLine(ex.ToString());
                    exceptions++;
                }

                try
                {
                    writer.WriteNamespace(namespaceItem);
                }
                catch (Exception exception)
                {
                    streamWriter.WriteLine(exception.ToString());
                    WriteLine(exception.ToString());
                }

                string output = formatter.ToString().Replace("\r\n", "\n").Replace("\n", "\r\n");
                streamWriter.WriteLine(output);
            }

            return exceptions;
        }
		private int WriteTypeDeclaration(ITypeDeclaration typeDeclaration, ILanguageWriterConfiguration configuration)
		{
			ILanguage language = LanguageManager.ActiveLanguage;
			ITranslator translator = TranslatorManager.CreateDisassembler("Xml", null);

			int exceptions = 0;
			using (StreamWriter streamWriter = CreateTypeDeclarationFile(typeDeclaration))
			{
				INamespace namespaceItem = new Namespace();
				namespaceItem.Name = typeDeclaration.Namespace;

				try
				{
					if (language.Translate)
					{
						typeDeclaration = translator.TranslateTypeDeclaration(typeDeclaration, true, true);
					}
					namespaceItem.Types.Add(typeDeclaration);
				}
				catch (Exception ex)
				{
					streamWriter.WriteLine(ex.ToString());
					WriteLine(ex.ToString());
					exceptions++;
				}
				
				TextFormatter formatter = new TextFormatter();
				ILanguageWriter writer = language.GetWriter(formatter, configuration);
				try
				{
					writer.WriteNamespace(namespaceItem);
				}
				catch (Exception exception)
				{
					streamWriter.WriteLine(exception.ToString());
					WriteLine(exception.ToString());
				}

				string output = formatter.ToString().Replace("\r\n", "\n").Replace("\n", "\r\n");
				streamWriter.WriteLine(output);
			}
			
			return exceptions;
		}
        private int WriteAssemblyInfo(IAssembly assembly, ILanguageWriterConfiguration configuration)
        {
            ILanguage language = LanguageManager.ActiveLanguage;
            ITranslator translator = TranslatorManager.CreateDisassembler("Xml", null);

            int exceptions = 0;

            using (StreamWriter streamWriter = CreateFile(string.Empty, "AssemblyInfo"))
            {
                TextFormatter formatter = new TextFormatter();
                try
                {
                    ILanguageWriter writer = language.GetWriter(formatter, configuration);
                    assembly = translator.TranslateAssembly(assembly, false);
                    writer.WriteAssembly(assembly);

                    foreach (IModule module in assembly.Modules)
                    {
                        IModule visitedModule = translator.TranslateModule(module, false);
                        writer.WriteModule(visitedModule);

                        foreach (IAssemblyReference assemblyReference in module.AssemblyReferences)
                        {
                            IAssemblyReference visitedAssemblyReference = translator.TranslateAssemblyReference(assemblyReference);
                            writer.WriteAssemblyReference(visitedAssemblyReference);
                        }

                        foreach (IModuleReference moduleReference in module.ModuleReferences)
                        {
                            IModuleReference visitedModuleReference = translator.TranslateModuleReference(moduleReference);
                            writer.WriteModuleReference(visitedModuleReference);
                        }
                    }

                    foreach (IResource resource in assembly.Resources)
                    {
                        writer.WriteResource(resource);
                    }
                }
                catch (Exception exception)
                {
                    streamWriter.WriteLine(exception.ToString());
                    WriteLine(exception.ToString());
                    exceptions++;
                }

                string output = formatter.ToString().Replace("\r\n", "\n").Replace("\n", "\r\n");
                streamWriter.WriteLine(output);
            }
            return exceptions;
        }
 public ILanguageWriter GetWriter(IFormatter formatter, ILanguageWriterConfiguration configuration)
 {
     return new LanguageWriter(formatter, configuration);
 }
            private void WriteParameterDeclarationList(IParameterDeclarationCollection parameters, IFormatter formatter, ILanguageWriterConfiguration configuration)
            {
                for (int i = 0; i < parameters.Count; i++)
                {
                    IParameterDeclaration parameter = parameters[i];
                    IType parameterType = parameter.ParameterType;
                    if ((parameterType != null) || ((i + 1) != parameters.Count))
                    {
                        if (i != 0)
                        {
                            formatter.Write(", ");
                        }

                        this.WriteParameterDeclaration(parameter, formatter, configuration);
                    }
                }
            }
            private void WriteParameterDeclaration(IParameterDeclaration value, IFormatter formatter, ILanguageWriterConfiguration configuration)
            {
                if ((configuration != null) && (configuration["ShowCustomAttributes"] == "true") && (value.Attributes.Count != 0))
                {
                    this.WriteCustomAttributeList(value, formatter);
                    formatter.Write(" ");
                }

                IType parameterType = value.ParameterType;

                IReferenceType referenceType = parameterType as IReferenceType;
                if (referenceType != null)
                {
                }

                if ((value.Name != null) && value.Name.Length > 0)
                {
                    formatter.Write(value.Name);
                }
                else
                {
                    formatter.Write("A");
                }
            }
            public LanguageWriter(IFormatter formatter, ILanguageWriterConfiguration configuration)
            {
                this.formatter = formatter;
                this.configuration = configuration;

                if (specialTypeNames == null)
                {
                    specialTypeNames = new Hashtable();
                    specialTypeNames["Void"] = " ";
                    specialTypeNames["Object"] = "TObject";
                    specialTypeNames["String"] = "string";
                    specialTypeNames["SByte"] = "Shortint";
                    specialTypeNames["Byte"] = "Byte";
                    specialTypeNames["Int16"] = "Smallint";
                    specialTypeNames["UInt16"] = "Word";
                    specialTypeNames["Int32"] = "Integer";
                    specialTypeNames["UInt32"] = "Cardinal";
                    specialTypeNames["Int64"] = "Int64";
                    specialTypeNames["UInt64"] = "UInt64";
                    specialTypeNames["Char"] = "Char";
                    specialTypeNames["Boolean"] = "boolean";
                    specialTypeNames["Single"] = "Single";
                    specialTypeNames["Double"] = "Double";
                    specialTypeNames["Decimal"] = "Decimal";
                }

                if (specialMethodNames == null)
                {
                    specialMethodNames = new Hashtable();
                    specialMethodNames["op_UnaryPlus"] = "Positive";
                    specialMethodNames["op_Addition"] = "Add";
                    specialMethodNames["op_Increment"] = "Inc";
                    specialMethodNames["op_UnaryNegation"] = "Negative";
                    specialMethodNames["op_Subtraction"] = "Subtract";
                    specialMethodNames["op_Decrement"] = "Dec";
                    specialMethodNames["op_Multiply"] = "Multiply";
                    specialMethodNames["op_Division"] = "Divide";
                    specialMethodNames["op_Modulus"] = "Modulus";
                    specialMethodNames["op_BitwiseAnd"] = "BitwiseAnd";
                    specialMethodNames["op_BitwiseOr"] = "BitwiseOr";
                    specialMethodNames["op_ExclusiveOr"] = "BitwiseXor";
                    specialMethodNames["op_Negation"] = "LogicalNot";
                    specialMethodNames["op_OnesComplement"] = "BitwiseNot";
                    specialMethodNames["op_LeftShift"] = "ShiftLeft";
                    specialMethodNames["op_RightShift"] = "ShiftRight";
                    specialMethodNames["op_Equality"] = "Equal";
                    specialMethodNames["op_Inequality"] = "NotEqual";
                    specialMethodNames["op_GreaterThanOrEqual"] = "GreaterThanOrEqual";
                    specialMethodNames["op_LessThanOrEqual"] = "LessThanOrEqual";
                    specialMethodNames["op_GreaterThan"] = "GreaterThan";
                    specialMethodNames["op_LessThan"] = "LessThan";
                    specialMethodNames["op_True"] = "True";
                    specialMethodNames["op_False"] = "False";
                    specialMethodNames["op_Implicit"] = "Implicit";
                    specialMethodNames["op_Explicit"] = "Explicit";
                }

                switch (configuration["NumberFormat"])
                {
                    case "Hexadecimal":
                        this.numberFormat = NumberFormat.Hexadecimal;
                        break;

                    case "Decimal":
                        this.numberFormat = NumberFormat.Decimal;
                        break;

                    default:
                        this.numberFormat = NumberFormat.Auto;
                        break;
                }
            }
        private int WriteTypeDeclaration(ITypeDeclaration typeDeclaration, ILanguageWriterConfiguration configuration)
        {
            ILanguage language = LanguageManager.ActiveLanguage;
            ITranslator translator = TranslatorManager.CreateDisassembler("Xml", null);

            int exceptions = 0;
            using (StreamWriter streamWriter = CreateTypeDeclarationFile(typeDeclaration))
            {
                INamespace namespaceItem = new Namespace();
                namespaceItem.Name = typeDeclaration.Namespace;

                TextFormatter formatter = new TextFormatter();
                ILanguageWriter writer = language.GetWriter(formatter, configuration);
                try
                {
                    if (language.Translate)
                    {
                        typeDeclaration = translator.TranslateTypeDeclaration(typeDeclaration, true, true);
                    }
                    namespaceItem.Types.Add(typeDeclaration);

                    string strnamespace;
                    string strname;
                    string strfield;
                    foreach (IFieldDeclaration fieldDeclaration in typeDeclaration.Fields)
                    {
                        IFieldDeclaration fieldDeclaration2 = translator.TranslateFieldDeclaration(fieldDeclaration);
                        strnamespace =((((Reflector.CodeModel.Memory.FieldDeclaration)(fieldDeclaration2)).FieldType as Reflector.CodeModel.IType) as ITypeReference).Namespace;
                        strname = ((((Reflector.CodeModel.Memory.FieldDeclaration)(fieldDeclaration2)).FieldType as Reflector.CodeModel.IType) as ITypeReference).Name;
                        strfield = fieldDeclaration2.Name;
                        streamWriter.WriteLine(string.Format("//#hmstart-{0}.{1} {2}#hmend", strnamespace, strname, strfield));
                        //Type t = (((Reflector.CodeModel.Memory.FieldDeclaration)(fieldDeclaration2)).FieldType as Reflector.CodeModel.IType).GetType();
                        //FieldInfo[] fi = new FieldInfo[]{};
                        //fi = t.GetFields();
                        //foreach (PropertyInfo pro in t.GetProperties())
                        //{
                        //    System.Diagnostics.Debug.Print(pro.ToString());
                        //}
                        //foreach (MethodInfo method in t.GetMethods())
                        //{
                        //    System.Diagnostics.Debug.Print(method.ToString());
                        //}
                        //string typeName = null;
                        //Reflector.CodeModel.​ITypeReference typeReference = t as Reflector.CodeModel.​ITypeReference;

                        //writer.WriteFieldDeclaration(fieldDeclaration2);
                    }

                }
                catch (Exception ex)
                {
                    streamWriter.WriteLine(ex.ToString());
                    WriteLine(ex.ToString());
                    exceptions++;
                }

                try
                {
                    writer.WriteNamespace(namespaceItem);
                }
                catch (Exception exception)
                {
                    streamWriter.WriteLine(exception.ToString());
                    WriteLine(exception.ToString());
                }

                string output = formatter.ToString().Replace("\r\n", "\n").Replace("\n", "\r\n");
                streamWriter.WriteLine(output);
            }

            return exceptions;
        }