本文整理汇总了C#中ObjectCollection.Add方法的典型用法代码示例。如果您正苦于以下问题:C# ObjectCollection.Add方法的具体用法?C# ObjectCollection.Add怎么用?C# ObjectCollection.Add使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ObjectCollection
的用法示例。
在下文中一共展示了ObjectCollection.Add方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: Ctor_ExecuteBothOverloads_MatchExpectation
public void Ctor_ExecuteBothOverloads_MatchExpectation()
{
// Use default validator
ObjectCollection<string> c = new ObjectCollection<string>();
c.Add("value1");
c.Insert(0, "value2");
Assert.Throws<ArgumentNullException>(() => { c.Add(null); });
Assert.Throws<ArgumentNullException>(() => { c[0] = null; });
Assert.Equal(2, c.Count);
Assert.Equal("value2", c[0]);
Assert.Equal("value1", c[1]);
// Use custom validator
c = new ObjectCollection<string>(item =>
{
if (item == null)
{
throw new InvalidOperationException("custom");
}
});
c.Add("value1");
c[0] = "value2";
Assert.Throws<InvalidOperationException>(() => { c.Add(null); });
Assert.Throws<InvalidOperationException>(() => { c[0] = null; });
Assert.Equal(1, c.Count);
Assert.Equal("value2", c[0]);
}
示例3: AreEqualCollections_UseSetOfEqualCollections_ReturnsTrue
public void AreEqualCollections_UseSetOfEqualCollections_ReturnsTrue()
{
ObjectCollection<NameValueHeaderValue> x = new ObjectCollection<NameValueHeaderValue>();
ObjectCollection<NameValueHeaderValue> y = new ObjectCollection<NameValueHeaderValue>();
Assert.True(HeaderUtilities.AreEqualCollections(x, y));
x.Add(new NameValueHeaderValue("a"));
x.Add(new NameValueHeaderValue("c"));
x.Add(new NameValueHeaderValue("b"));
x.Add(new NameValueHeaderValue("c"));
y.Add(new NameValueHeaderValue("c"));
y.Add(new NameValueHeaderValue("c"));
y.Add(new NameValueHeaderValue("b"));
y.Add(new NameValueHeaderValue("a"));
Assert.True(HeaderUtilities.AreEqualCollections(x, y));
Assert.True(HeaderUtilities.AreEqualCollections(y, x));
}
示例4: PointSelector
public PointSelector()
{
markerChart.SetBinding(Panel.ZIndexProperty, new Binding("(Panel.ZIndex)") { Source = this });
// initializing built-in commands
removePointCommand = new LambdaCommand((param) => RemovePointExecute(param), RemovePointCanExecute);
changeModeCommand = new LambdaCommand((param) => ChangeModeExecute(param), ChangeModeCanExecute);
addPointCommand = new LambdaCommand((param) => AddPointExecute(param), AddPointCanExecute);
InitializeComponent();
// adding context menu binding to markers
markerChart.AddPropertyBinding(DefaultContextMenu.PlotterContextMenuProperty, data =>
{
ObjectCollection menuItems = new ObjectCollection();
MenuItem item = new MenuItem { Header = UIResources.PointSelector_RemovePoint, Command = PointSelectorCommands.RemovePoint, CommandTarget = this };
item.SetBinding(MenuItem.CommandParameterProperty, new Binding());
menuItems.Add(item);
return menuItems;
});
// loading marker template
var markerTemplate = (DataTemplate)Resources["markerTemplate"];
markerChart.MarkerBuilder = new TemplateMarkerGenerator(markerTemplate);
markerChart.ItemsSource = points;
// adding bindings to commands from PointSelectorCommands static class
CommandBinding removePointBinding = new CommandBinding(
PointSelectorCommands.RemovePoint,
RemovePointExecute,
RemovePointCanExecute
);
CommandBindings.Add(removePointBinding);
CommandBinding changeModeBinding = new CommandBinding(
PointSelectorCommands.ChangeMode,
ChangeModeExecute,
ChangeModeCanExecute);
CommandBindings.Add(changeModeBinding);
CommandBinding addPointBinding = new CommandBinding(
PointSelectorCommands.AddPoint,
AddPointExecute,
AddPointCanExecute);
CommandBindings.Add(addPointBinding);
// init add point menu item
addPointMenuItem.Click += addPointMenuItem_Click;
points.CollectionChanged += points_CollectionChanged;
}
示例5: AllControls
/// <summary>
/// Initializes a new instance of the AllControls class.
/// </summary>
public AllControls()
{
InitializeComponent();
LayoutUpdated += OnLayoutUpdated;
SampleDataGrid.ItemsSource = Employee.Executives;
SampleAutoComplete.ItemsSource = Catalog.VacationMediaItems;
TripsList.ItemsSource = Catalog.PlannedVacationMediaItems;
VacationImage.Source = Catalog.VacationCatalog.CatalogImage.Source;
VactionTreeView.LayoutUpdated += OnTreeViewLayoutUpdated;
ObjectCollection collection = new ObjectCollection();
collection.Add(Catalog.VacationCatalog);
VactionTreeView.ItemsSource = collection;
ExpanderImage.Source = SharedResources.GetImage("SilverlightThemesLogo.jpg").Source;
System.Windows.Threading.DispatcherTimer myDispatcherTimer = new System.Windows.Threading.DispatcherTimer();
myDispatcherTimer.Interval = new TimeSpan(0, 0, 0, 0, 4000);
myDispatcherTimer.Tick += new EventHandler(OnTick);
myDispatcherTimer.Start();
}
示例6: GetNameValueListLength
// Returns the length of a name/value list, separated by 'delimiter'. E.g. "a=b, c=d, e=f" adds 3
// name/value pairs to 'nameValueCollection' if 'delimiter' equals ','.
internal static int GetNameValueListLength(string input, int startIndex, char delimiter,
ObjectCollection<NameValueHeaderValue> nameValueCollection)
{
Contract.Requires(nameValueCollection != null);
Contract.Requires(startIndex >= 0);
if ((string.IsNullOrEmpty(input)) || (startIndex >= input.Length))
{
return 0;
}
int current = startIndex + HttpRuleParser.GetWhitespaceLength(input, startIndex);
while (true)
{
NameValueHeaderValue parameter = null;
int nameValueLength = NameValueHeaderValue.GetNameValueLength(input, current,
s_defaultNameValueCreator, out parameter);
if (nameValueLength == 0)
{
return 0;
}
nameValueCollection.Add(parameter);
current = current + nameValueLength;
current = current + HttpRuleParser.GetWhitespaceLength(input, current);
if ((current == input.Length) || (input[current] != delimiter))
{
// We're done and we have at least one valid name/value pair.
return current - startIndex;
}
// input[current] is 'delimiter'. Skip the delimiter and whitespaces and try to parse again.
current++; // skip delimiter.
current = current + HttpRuleParser.GetWhitespaceLength(input, current);
}
}
示例7: ItemsSourceChangeObjects
public void ItemsSourceChangeObjects()
{
DataPointSeries series = DefaultSeriesToTest;
ObjectCollection objectCollection = new ObjectCollection();
objectCollection.Add(new object());
objectCollection.Add(new object());
series.ItemsSource = objectCollection;
Assert.AreSame(objectCollection, series.ItemsSource);
}
示例8: 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));
}
//.........这里部分代码省略.........
示例9: DeviceBase
/// <summary>
/// Конструктор
/// </summary>
internal DeviceBase(IProfile profile)
{
_Profile = profile;
_LocationName = String.Empty;
_NodeId = 1;
_PollingInterval = 1;
_Status = DeviceStatus.Stopped;
// Создаём устройство на основе профиля
_DeviceType = profile.DeviceType;
// Создаём словарь объектов устройства
_ObjectDictionary = new ObjectCollection(this);
foreach (ObjectInfo info in profile.ObjectInfoList)
{
_ObjectDictionary.Add(new DataObject(info));
}
// Устанавливаем версии ПО и аппаратуры
ProductVersion version = new ProductVersion();
version.Version = profile.SoftwareVersion;
SetObject(0x2001, version);
version.Version = profile.HardwareVersion;
SetObject(0x2002, version);
// Пересчитвываем CRC16
VisitingCard vc = VisitingCard;
ushort crc = vc.GetCRC16();
vc.CRC16 = crc;
}
示例10: select_OnPreSelect
void select_OnPreSelect(ref object PreSelectEntity, out bool DoHighlight, ref ObjectCollection MorePreSelectEntities, SelectionDeviceEnum SelectionDevice, Inventor.Point ModelPosition, Point2d ViewPosition, Inventor.View View)
{
DoHighlight = true;
//���õ������ѡ�Ķ�������ã�����ǰ�涨��Ĺ�����������֪���ö���һ����һ����
Edge edge;
edge = (Edge)PreSelectEntity;
//ȷ���Ƿ�����ñ����в����ӵı�
EdgeCollection edges;
edges = edge.TangentiallyConnectedEdges;
if (edges.Count > 1)
{
//�������������ߵĶ���
MorePreSelectEntities = ThisApplication.TransientObjects.CreateObjectCollection(null);
for (int i = 1; i <= edges.Count; i++)
{
MorePreSelectEntities.Add(edges[i]);
}
}
}