AddRange() public méthode

public AddRange ( CodeTypeDeclaration value ) : void
value CodeTypeDeclaration
Résultat void
		public void Constructor1_Deny_Unrestricted ()
		{
			CodeTypeDeclarationCollection coll = new CodeTypeDeclarationCollection (array);
			coll.CopyTo (array, 0);
			Assert.AreEqual (1, coll.Add (ctd), "Add");
			Assert.AreSame (ctd, coll[0], "this[int]");
			coll.AddRange (array);
			coll.AddRange (coll);
			Assert.IsTrue (coll.Contains (ctd), "Contains");
			Assert.AreEqual (0, coll.IndexOf (ctd), "IndexOf");
			coll.Insert (0, ctd);
			coll.Remove (ctd);
		}
 static CodeTypeDeclarationCollection BuildEntities(EntityMetadata[] entityMetadata, ServiceProvider serviceProvider)
 {
     Trace.TraceInformation("Entering {0}", new object[] {MethodBase.GetCurrentMethod().Name});
     var declarations = new CodeTypeDeclarationCollection();
     foreach (var metadata in from metadata in entityMetadata
                                         orderby metadata.LogicalName
                                         select metadata)
     {
         if (serviceProvider.CodeFilterService.GenerateEntity(metadata, serviceProvider))
         {
             declarations.AddRange(BuildEntity(metadata, serviceProvider));
         }
         else
         {
             Trace.TraceInformation("Skipping Entity {0} from being generated.", new object[] {metadata.LogicalName});
         }
     }
     Trace.TraceInformation("Exiting {0}", new object[] {MethodBase.GetCurrentMethod().Name});
     return declarations;
 }
 static CodeTypeDeclarationCollection BuildMessages(SdkMessages sdkMessages, ServiceProvider serviceProvider)
 {
     Trace.TraceInformation("Entering {0}", new object[] {MethodBase.GetCurrentMethod().Name});
     var declarations = new CodeTypeDeclarationCollection();
     foreach (var message in sdkMessages.MessageCollection.Values)
     {
         if (serviceProvider.CodeMessageFilterService.GenerateSdkMessage(message, serviceProvider))
         {
             declarations.AddRange(BuildMessage(message, serviceProvider));
         }
         else
         {
             Trace.TraceInformation("Skipping SDK Message {0} from being generated.", new object[] {message.Name});
         }
     }
     Trace.TraceInformation("Exiting {0}", new object[] {MethodBase.GetCurrentMethod().Name});
     return declarations;
 }
		protected override byte[] GenerateCode(string fileName, string FileContents)
		{
			InitializeTool();
			try
			{
				if (mOutLog != null) 
				{
					mOutLog.Clear();
				}
				string DefaultNameSpace = this.GetDefaultNameSpace(fileName);

				// Load FileContents into XML Doc
				XmlDocument inXDoc = new XmlDocument();

				inXDoc.PreserveWhitespace = false;
				inXDoc.LoadXml(FileContents);
                       
				// Get the path to the WSDL
				XmlNode wsdln = inXDoc.DocumentElement.SelectSingleNode("//WSDLFile/text()");
				if (wsdln == null || wsdln.Value == String.Empty)
				{
					//Console.WriteLine("WSDL not found in Document <configuration><WSDLFile>http://value.wsdl</WSDLFile></configuration>\n");
					if (mOutLog != null) 
					{
						mOutLog.OutputString("WSDL not found in Document <configuration><WSDLFile>http://value.wsdl</WSDLFile></configuration>\n");
					}
					else 
					{
						Console.WriteLine("WSDL not found in Document <configuration><WSDLFile>http://value.wsdl</WSDLFile></configuration>\n");
					}
					return null;
				}

				string WSDLPath = wsdln.Value;
				if (mOutLog != null) 
				{
					mOutLog.OutputString("Generating Proxy Class File\n");
					mOutLog.OutputString("NameSpace: " + DefaultNameSpace + "\n");
					mOutLog.OutputString("WSDL Path: " + WSDLPath + "\n");
				}
				else 
				{
					Console.WriteLine("Generating Proxy Class File\n");
					Console.WriteLine("NameSpace: " + DefaultNameSpace + "\n");
					Console.WriteLine("WSDL Path: " + WSDLPath + "\n");
				}

				// Load WSDL
                XmlTextReader xtr = new XmlTextReader(WSDLPath);
                ServiceDescription serviceDescription = ServiceDescription.Read(xtr);
				CodeCompileUnit codeUnit = new CodeCompileUnit();

				CodeNamespace codeNamespace = new CodeNamespace(DefaultNameSpace);
				codeUnit.Namespaces.Add(codeNamespace);

				codeNamespace.Comments.Add(new CodeCommentStatement("Generator version 1.1"));
				codeNamespace.Comments.Add(new CodeCommentStatement(""));
				codeNamespace.Comments.Add(new CodeCommentStatement("Copyright: ?2000-2008 eBay Inc."));
				codeNamespace.Comments.Add(new CodeCommentStatement(""));
				codeNamespace.Comments.Add(new CodeCommentStatement("Date: " + DateTime.Now.ToString()));
				codeNamespace.Comments.Add(new CodeCommentStatement(""));

				//
				// Set up the service importer that eventually generate the DOM
				// for client proxy.
				//
				ServiceDescriptionImporter serviceImporter = new ServiceDescriptionImporter();
			
				// Resolve any Imports
				
                DiscoveryClientProtocol dcp = new DiscoveryClientProtocol();
				dcp.DiscoverAny(WSDLPath);
				dcp.ResolveAll();

				foreach (object osd in dcp.Documents.Values)
				{
					if (osd is ServiceDescription) serviceImporter.AddServiceDescription((ServiceDescription)osd, String.Empty, String.Empty);;
					if (osd is XmlSchema) serviceImporter.Schemas.Add((XmlSchema)osd);
				}

				// Configure the Importer
				serviceImporter.ProtocolName = "Soap";
				serviceImporter.Style = ServiceDescriptionImportStyle.Client;

                //serviceImporter.CodeGenerationOptions = System.Xml.Serialization.CodeGenerationOptions.EnableDataBinding
                //                                      | serviceImporter.CodeGenerationOptions;
            
				ServiceDescriptionImportWarnings warnings = serviceImporter.Import(codeNamespace, codeUnit);

				if (mOutLog != null) 
				{
					if ((warnings & ServiceDescriptionImportWarnings.NoMethodsGenerated) != 0)
						mOutLog.OutputString("Warning: no methods were generated.\n");
					if ((warnings & ServiceDescriptionImportWarnings.OptionalExtensionsIgnored) != 0)
						mOutLog.OutputString("Warning: one or more optional WSDL extension elements were ignored.\n");
					if ((warnings & ServiceDescriptionImportWarnings.OptionalExtensionsIgnored) != 0)
						mOutLog.OutputString("Warning: one or more optional WSDL extension elements were ignored.\n");
					if ((warnings & ServiceDescriptionImportWarnings.RequiredExtensionsIgnored) != 0)
						mOutLog.OutputString("Warning: one or more required WSDL extension elements were ignored.\n");
					if ((warnings & ServiceDescriptionImportWarnings.UnsupportedBindingsIgnored) != 0)
						mOutLog.OutputString("Warning: one or more bindings were skipped.\n");
					if ((warnings & ServiceDescriptionImportWarnings.UnsupportedOperationsIgnored) != 0)
						mOutLog.OutputString("one or more operations were skipped.\n");
					if ((warnings & ServiceDescriptionImportWarnings.NoCodeGenerated) != 0)
					{
						mOutLog.OutputString("Warning: no classes were generated.\n");
						return null;
					}
					if (warnings != 0)
						mOutLog.OutputString("Warnings were encountered. Review generated source comments for more details.\n");
				}
				else 
				{
					if ((warnings & ServiceDescriptionImportWarnings.NoMethodsGenerated) != 0)
						Console.WriteLine("Warning: no methods were generated.\n");
					if ((warnings & ServiceDescriptionImportWarnings.OptionalExtensionsIgnored) != 0)
						Console.WriteLine("Warning: one or more optional WSDL extension elements were ignored.\n");
					if ((warnings & ServiceDescriptionImportWarnings.OptionalExtensionsIgnored) != 0)
						Console.WriteLine("Warning: one or more optional WSDL extension elements were ignored.\n");
					if ((warnings & ServiceDescriptionImportWarnings.RequiredExtensionsIgnored) != 0)
						Console.WriteLine("Warning: one or more required WSDL extension elements were ignored.\n");
					if ((warnings & ServiceDescriptionImportWarnings.UnsupportedBindingsIgnored) != 0)
						Console.WriteLine("Warning: one or more bindings were skipped.\n");
					if ((warnings & ServiceDescriptionImportWarnings.UnsupportedOperationsIgnored) != 0)
						Console.WriteLine("one or more operations were skipped.\n");
					if ((warnings & ServiceDescriptionImportWarnings.NoCodeGenerated) != 0)
					{
						Console.WriteLine("Warning: no classes were generated.\n");
						return null;
					}
					if (warnings != 0)
						Console.WriteLine("Warnings were encountered. Review generated source comments for more details.\n");
				}

                // change the base class
                CodeTypeDeclaration ctDecl = codeNamespace.Types[0];
                codeNamespace.Types.Remove(ctDecl);
                ctDecl.BaseTypes[0] = new CodeTypeReference(DefaultNameSpace + ".SoapHttpClientProtocolEx");
                codeNamespace.Types.Add(ctDecl);

                codeNamespace.Imports.Add(new CodeNamespaceImport("System.Collections"));
                CodeTypeDeclarationCollection codeTypeColl = new CodeTypeDeclarationCollection();
                ArrayList colList = new ArrayList();
                ArrayList allMembers = new ArrayList();

                //added by william, workaround to fix the code
                FixCode(codeNamespace);

                foreach (CodeTypeDeclaration codeType in codeNamespace.Types)
                {

                    allMembers.Clear();
                    foreach (CodeTypeMember codeMember in codeType.Members)
                    {
                        allMembers.Add(codeMember.Name);
                    }

                    CodeTypeMemberCollection codeMemberColl = new CodeTypeMemberCollection();

                    //
                    // Collect the public fields of the type.
                    //

                    foreach (CodeTypeMember codeMember in codeType.Members)
                    {
                        CodeMemberMethod codeMethod = codeMember as CodeMemberMethod;

                        if (codeMethod != null)
                        {
                            if ((codeMethod.Attributes & MemberAttributes.Public) == MemberAttributes.Public)
                            {
                                foreach (CodeAttributeDeclaration cadt in codeMethod.CustomAttributes)
                                {
                                    if (cadt.Name.EndsWith("SoapDocumentMethodAttribute"))
                                    {
                                        codeMethod.CustomAttributes.Add(new CodeAttributeDeclaration(DefaultNameSpace + ".SoapExtensionExAttribute"));
                                        break;
                                    }
                                }
                            }
                        }
                        else
                        {
                            CodeMemberField codeField = codeMember as CodeMemberField;
                            if (codeField != null)
                            {   
                                if ((codeField.Attributes & MemberAttributes.Public) == MemberAttributes.Public)
                                {
                                    codeField.Comments.Clear();

                                    CodeTypeReference codeFieldRef = codeField.Type.ArrayElementType as CodeTypeReference;

                                    //skip 'System.Byte'
                                    if (codeFieldRef != null && !"System.Byte".Equals(codeFieldRef.BaseType))
                                    {
                                        string name = codeFieldRef.BaseType;
                                        //Debug.WriteLine("Array BaseType name : " + name);

                                        string[] splstr = name.Split('.');

                                        if (splstr.Length > 1)
                                        {
                                            string ns = String.Join(".", splstr, 0, splstr.Length - 1);
                                            codeNamespace.Imports.Add(new CodeNamespaceImport(ns));
                                            name = (string)splstr.GetValue(splstr.Length - 1);
                                        }

                                        if (!colList.Contains(name))
                                        {
                                            codeTypeColl.Add(this.CreateCollectionType(name));
                                            colList.Add(name);
                                        }
                                        codeField.Type = new CodeTypeReference(name + "Collection");

                                    }

                                    int val = allMembers.IndexOf(codeField.Name + "Specified");
                                    codeMemberColl.Add(this.CreateProperty(codeField, val != -1));
                                }
                            }
                        }
                    }

                    // add the newly created public properties
                    codeType.Members.AddRange(codeMemberColl);
                }

                codeNamespace.Types.AddRange(codeTypeColl);
                codeNamespace.Types.Add(CreateSoapHttpClientProtocolEx());
                codeNamespace.Types.Add(CreateSoapExtensionExAttribute());
                codeNamespace.Types.Add(CreateSoapExtensionEx());

				if (this.mProjItem != null) 
				{
					MemoryStream mem = new MemoryStream();
					StreamWriter outputWriter = new StreamWriter(mem);
					CodeProvider.GenerateCodeFromCompileUnit(codeUnit, outputWriter, new CodeGeneratorOptions());
                    outputWriter.Flush();
					mOutLog.OutputString("Code Generation Completed Successfully\n");
					return mem.ToArray();
				}
				else 
				{
                    CodeDomProvider generator = null;
					string fileExt = null;
					if (mLang.Equals(VB))
					{
						generator = new Microsoft.VisualBasic.VBCodeProvider();
						fileExt = VB;
					}
						//j# is not available.
						//else if (mLang.Equals(JS))
						//{	
						//	generator = new Microsoft.JScript.JScriptCodeProvider().CreateGenerator();
						//}
					else 
					{
						generator = new Microsoft.CSharp.CSharpCodeProvider();
						fileExt = CS;
					}

					if (mOutputOneFileOption == true) 
					{
						MemoryStream mem = new MemoryStream();
						StreamWriter outputWriter = new StreamWriter(mem);
						CodeGeneratorOptions options = new CodeGeneratorOptions();
						options.BlankLinesBetweenMembers = false;
						generator.GenerateCodeFromCompileUnit(codeUnit, outputWriter, options);;
						outputWriter.Flush();

						byte [] output = mem.ToArray();
						BinaryWriter writer = new BinaryWriter(File.Open(mOutputPath + fileName, FileMode.Create));
						writer.Write(output);	
						writer.Close();
					}
					else
					{
						CodeTypeDeclarationCollection coll = new CodeTypeDeclarationCollection();
						coll.AddRange(codeNamespace.Types);

						foreach (CodeTypeDeclaration codeType in coll) 
						{
							codeNamespace.Types.Clear();				
							CodeTypeDeclarationCollection types = new CodeTypeDeclarationCollection();
							codeNamespace.Types.Add(codeType);
							MemoryStream mem = new MemoryStream();
							StreamWriter outputWriter = new StreamWriter(mem);

							CodeGeneratorOptions options = new CodeGeneratorOptions();
							options.BlankLinesBetweenMembers = false;
							generator.GenerateCodeFromCompileUnit(codeUnit, outputWriter, options);;
							outputWriter.Flush();

							byte [] output = mem.ToArray();
							string clsName = codeType.Name + "." + fileExt;
							BinaryWriter writer = new BinaryWriter(File.Open(mOutputPath + clsName, FileMode.Create));
							writer.Write(output);	
							writer.Close();
						}
					}
					Console.WriteLine("Code Generation Completed Successfully\n");
					return null;
				}
			}
			catch (Exception ex)
			{
				Console.WriteLine(ex.Message + "\n");
				return null;
			}
		}
		public void AddRange_Self ()
		{
			CodeTypeDeclarationCollection coll = new CodeTypeDeclarationCollection ();
			coll.Add (new CodeTypeDeclaration ());
			Assert.AreEqual (1, coll.Count, "#1");
			coll.AddRange (coll);
			Assert.AreEqual (2, coll.Count, "#2");
		}
		public void AddRange_Null_Collection ()
		{
			CodeTypeDeclarationCollection coll = new CodeTypeDeclarationCollection ();
			coll.AddRange ((CodeTypeDeclarationCollection) null);
		}
		public void AddRange_Null_Item ()
		{
			CodeTypeDeclarationCollection coll = new CodeTypeDeclarationCollection ();
			coll.AddRange (new CodeTypeDeclaration[] { null });
		}
		public void AddRange ()
		{
			CodeTypeDeclaration td1 = new CodeTypeDeclaration ();
			CodeTypeDeclaration td2 = new CodeTypeDeclaration ();
			CodeTypeDeclaration td3 = new CodeTypeDeclaration ();

			CodeTypeDeclarationCollection coll1 = new CodeTypeDeclarationCollection ();
			coll1.Add (td1);
			coll1.Add (td2);

			CodeTypeDeclarationCollection coll2 = new CodeTypeDeclarationCollection ();
			coll2.Add (td3);
			coll2.AddRange (coll1);
			Assert.AreEqual (3, coll2.Count, "#1");
			Assert.AreEqual (1, coll2.IndexOf (td1), "#2");
			Assert.AreEqual (2, coll2.IndexOf (td2), "#3");
			Assert.AreEqual (0, coll2.IndexOf (td3), "#4");

			CodeTypeDeclarationCollection coll3 = new CodeTypeDeclarationCollection ();
			coll3.Add (td3);
			coll3.AddRange (new CodeTypeDeclaration[] { td1, td2 });
			Assert.AreEqual (3, coll2.Count, "#5");
			Assert.AreEqual (1, coll2.IndexOf (td1), "#6");
			Assert.AreEqual (2, coll2.IndexOf (td2), "#7");
			Assert.AreEqual (0, coll2.IndexOf (td3), "#8");
		}