本文整理汇总了C#中ObjectCollection.Clear方法的典型用法代码示例。如果您正苦于以下问题:C# ObjectCollection.Clear方法的具体用法?C# ObjectCollection.Clear怎么用?C# ObjectCollection.Clear使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ObjectCollection
的用法示例。
在下文中一共展示了ObjectCollection.Clear方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AreEqualCollections_UseSetOfNotEqualCollections_ReturnsFalse
public void AreEqualCollections_UseSetOfNotEqualCollections_ReturnsFalse()
{
ObjectCollection<NameValueHeaderValue> x = new ObjectCollection<NameValueHeaderValue>();
ObjectCollection<NameValueHeaderValue> y = new ObjectCollection<NameValueHeaderValue>();
Assert.True(HeaderUtilities.AreEqualCollections(x, y), "Expected '<empty>' == '<empty>'");
x.Add(new NameValueHeaderValue("a"));
x.Add(new NameValueHeaderValue("c"));
x.Add(new NameValueHeaderValue("b"));
x.Add(new NameValueHeaderValue("c"));
y.Add(new NameValueHeaderValue("a"));
y.Add(new NameValueHeaderValue("b"));
y.Add(new NameValueHeaderValue("c"));
y.Add(new NameValueHeaderValue("d"));
Assert.False(HeaderUtilities.AreEqualCollections(x, y));
Assert.False(HeaderUtilities.AreEqualCollections(y, x));
y.Clear();
y.Add(new NameValueHeaderValue("a"));
y.Add(new NameValueHeaderValue("b"));
y.Add(new NameValueHeaderValue("b"));
y.Add(new NameValueHeaderValue("c"));
Assert.False(HeaderUtilities.AreEqualCollections(x, y));
Assert.False(HeaderUtilities.AreEqualCollections(y, x));
}
示例2: GenerateClasses
public ObjectCollection GenerateClasses(XmlSchema schema)
{
#region Generate the CodeDom from the XSD
CodeNamespace codeNamespace = new CodeNamespace("TestNameSpace");
XmlSchemas xmlSchemas = new XmlSchemas();
xmlSchemas.Add(schema);
XmlSchemaImporter schemaImporter = new XmlSchemaImporter(xmlSchemas);
XmlCodeExporter codeExporter = new XmlCodeExporter(
codeNamespace,
new CodeCompileUnit(),
CodeGenerationOptions.GenerateProperties);
foreach (XmlSchemaElement element in schema.Elements.Values)
{
try
{
XmlTypeMapping map = schemaImporter.ImportTypeMapping(element.QualifiedName);
codeExporter.ExportTypeMapping(map);
}
catch (Exception ex)
{
throw new Exception("Error Loading Schema: ", ex);
}
}
#endregion
#region Modify the CodeDom
foreach (ICodeModifier codeModifier in m_codeModifiers)
codeModifier.Execute(codeNamespace);
#endregion
#region Generate the code
CodeCompileUnit compileUnit = new CodeCompileUnit();
compileUnit.Namespaces.Add(codeNamespace);
CodeDomProvider provider = CodeDomProvider.CreateProvider("CSharp");
#if DEBUG
StringWriter sw = new StringWriter();
CodeGeneratorOptions options = new CodeGeneratorOptions();
options.VerbatimOrder = true;
provider.GenerateCodeFromCompileUnit(compileUnit, sw, options);
m_codeString = sw.ToString();
#endif
#endregion
#region Compile an assembly
CompilerParameters compilerParameters = new CompilerParameters();
#region add references to assemblies
// reference for
// System.CodeDom.Compiler
// System.CodeDom
// System.Diagnostics
compilerParameters.ReferencedAssemblies.Add("System.dll");
compilerParameters.ReferencedAssemblies.Add("mscorlib.dll");
// System.Xml
compilerParameters.ReferencedAssemblies.Add("system.xml.dll");
// reference to this assembly for the custom collection editor
compilerParameters.ReferencedAssemblies.Add(Assembly.GetExecutingAssembly().Location);
compilerParameters.ReferencedAssemblies.Add("System.Drawing.dll");
// System.ComponentModel
#endregion
compilerParameters.GenerateExecutable = false;
compilerParameters.GenerateInMemory = true;
CompilerResults results = provider.CompileAssemblyFromDom(compilerParameters, new CodeCompileUnit[] { compileUnit });
// handle the errors if there are any
if (results.Errors.HasErrors)
{
m_errorStrings = new StringCollection();
m_errorStrings.Add("Error compiling assembly:\r\n");
foreach (CompilerError error in results.Errors)
m_errorStrings.Add(error.ErrorText + "\r\n");
return null;
}
#endregion
#region Find the exported classes
Assembly assembly = results.CompiledAssembly;
Type[] exportedTypes = assembly.GetExportedTypes();
// try to create an instance of the exported types
ObjectCollection objectCollection = new ObjectCollection();
objectCollection.Clear();
foreach (Type type in exportedTypes)
{
object obj = Activator.CreateInstance(type);
objectCollection.Add(new ObjectItem(type.Name, obj));
}
//.........这里部分代码省略.........