public override bool Equals(object obj) { ICompositeData other = obj as ICompositeData; return(other != null && CompositeType.Equals(other.CompositeType) && GetAll(CompositeType.KeySet.OrderBy(x => x)).SequenceEqual(other.GetAll(CompositeType.KeySet.OrderBy(x => x)))); }
public bool ContainsValue(ICompositeData value) { if (value == null) { throw new ArgumentNullException("value"); } return(_rows.ContainsValue(value)); }
public void Put(ICompositeData value) { IndexEntry entry = new IndexEntry(CalculateIndex(value)); if (_rows.ContainsKey(entry)) { throw new KeyAlreadyExistsException(entry.Items); } _rows.Add(entry, value); }
private bool ContainsSameValues(IEnumerable <ICompositeData> otherRows) { foreach (ICompositeData otherRow in otherRows) { IEnumerable <object> otherKey = CalculateIndex(otherRow); ICompositeData thisRow = this[otherKey]; if (!otherRow.Equals(thisRow)) { return(false); } } return(true); }
public void PlainNetMapperCanHandleComplexTypes() { OpenTypeKind mapsTo; Assert.IsTrue(mapper.CanHandle(typeof(OuterType), out mapsTo, CanHandle)); Assert.AreEqual(OpenTypeKind.CompositeType, mapsTo); OpenType outerType = mapper.MapType(typeof(OuterType), MapType); Assert.AreEqual(OpenTypeKind.CompositeType, outerType.Kind); CompositeType outerCompositeType = (CompositeType)outerType; Assert.AreEqual("OuterType", outerCompositeType.TypeName); Assert.AreEqual("OuterType", outerCompositeType.Description); Assert.IsTrue(outerCompositeType.ContainsKey("Inner")); Assert.AreEqual(1, outerCompositeType.KeySet.Count); OpenType innerType = outerCompositeType.GetOpenType("Inner"); Assert.AreEqual(OpenTypeKind.CompositeType, innerType.Kind); CompositeType innerCompositeType = (CompositeType)innerType; Assert.AreEqual("InnerType", innerCompositeType.TypeName); Assert.AreEqual("InnerType", innerCompositeType.Description); Assert.IsTrue(innerCompositeType.ContainsKey("Value")); Assert.AreEqual(SimpleType.String, innerCompositeType.GetOpenType("Value")); Assert.AreEqual(1, outerCompositeType.KeySet.Count); OuterType value = new OuterType(); value.Inner = new InnerType(); value.Inner.Value = "Inner text value"; object mappedValue = mapper.MapValue(typeof(OuterType), outerType, value, MapValue); Assert.IsTrue(mappedValue is ICompositeData); ICompositeData outerCompositeData = (ICompositeData)mappedValue; Assert.IsTrue(outerCompositeType.IsValue(outerCompositeData)); Assert.IsTrue(outerCompositeData.ContainsKey("Inner")); Assert.AreEqual(1, outerCompositeData.Values.Count()); Assert.IsTrue(outerCompositeData["Inner"] is ICompositeData); ICompositeData innerCompositeData = (ICompositeData)outerCompositeData["Inner"]; Assert.IsTrue(innerCompositeData.ContainsKey("Value")); Assert.AreEqual(1, innerCompositeData.Values.Count()); Assert.AreEqual(value.Inner.Value, innerCompositeData["Value"]); }
private static ICompositeData MakeRowValue(ICompositeData elementValue, int index, CompositeType rowType) { List <string> names = new List <string>(); List <object> values = new List <object>(); names.Add(CollectionIndexColumnName); values.Add(index); foreach (string itemName in elementValue.CompositeType.KeySet) { names.Add(itemName); values.Add(elementValue[itemName]); } return(new CompositeDataSupport(rowType, names, values)); }
public IList <object> CalculateIndex(ICompositeData value) { if (value == null) { throw new ArgumentNullException("value"); } if (!_tabularType.RowType.IsValue(value)) { throw new InvalidOpenTypeException(_tabularType.RowType, value); } List <object> results = new List <object>(); foreach (string indexItem in _tabularType.IndexNames) { results.Add(value[indexItem]); } return(results); }
public void SetAttribute(string attributeName, object value) { switch (attributeName) { case "Tabular": _tabularValue = (ITabularData)value; break; case "Array": _arrayValue = (decimal[])value; break; case "Composite": _compositeValue = (ICompositeData)value; break; default: throw new NotSupportedException(); } }
public void CollectionMapperCanHandleMappingCollectionToTabular() { OpenType mappedType = mapper.MapType(typeof(IEnumerable <TestCollectionElement>), MapType); Assert.AreEqual(OpenTypeKind.TabularType, mappedType.Kind); TabularType tabuarType = (TabularType)mappedType; Assert.AreEqual(tabuarType.IndexNames.Count, 1); Assert.IsTrue(tabuarType.IndexNames.Contains("CollectionIndex")); Assert.AreEqual(3, tabuarType.RowType.KeySet.Count); Assert.IsTrue(tabuarType.RowType.ContainsKey("IntValue")); Assert.IsTrue(tabuarType.RowType.ContainsKey("StringValue")); Assert.IsTrue(tabuarType.RowType.ContainsKey("CollectionIndex")); Assert.AreEqual(SimpleType.Integer, tabuarType.RowType.GetOpenType("IntValue")); Assert.AreEqual(SimpleType.String, tabuarType.RowType.GetOpenType("StringValue")); Assert.AreEqual(SimpleType.Integer, tabuarType.RowType.GetOpenType("CollectionIndex")); List <TestCollectionElement> value = new List <TestCollectionElement>(); value.Add(new TestCollectionElement(1, "1")); value.Add(new TestCollectionElement(2, "2")); value.Add(new TestCollectionElement(3, "3")); object mappedValue = mapper.MapValue(typeof(IEnumerable <TestCollectionElement>), mappedType, value, MapValue); Assert.IsTrue(mappedValue is ITabularData); ITabularData table = (ITabularData)mappedValue; Assert.AreEqual(3, table.Count); ICompositeData el = table[new object[] { 0 }]; Assert.AreEqual(1, el["IntValue"]); Assert.AreEqual("1", el["StringValue"]); el = table[new object[] { 1 }]; Assert.AreEqual(2, el["IntValue"]); Assert.AreEqual("2", el["StringValue"]); el = table[new object[] { 2 }]; Assert.AreEqual(3, el["IntValue"]); Assert.AreEqual("3", el["StringValue"]); }
public object MapValue(Type plainNetType, OpenType mappedType, object value, MapValueDelegate mapNestedValueCallback) { if (value == null) { return(null); } Type elementType = GetElementType(plainNetType); if (mappedType.Kind == OpenTypeKind.ArrayType) { if (value.GetType().IsArray) { return(value); } else { ArrayList result = new ArrayList(); IEnumerable enumerableValue = (IEnumerable)value; foreach (object o in enumerableValue) { result.Add(o); } return(result.ToArray(elementType)); } } else { TabularType tabularType = (TabularType)mappedType; ITabularData result = new TabularDataSupport(tabularType, 0); IEnumerable enumerableValue = (IEnumerable)value; int index = 0; foreach (object o in enumerableValue) { ICompositeData element = (ICompositeData)mapNestedValueCallback(elementType, MakeElementType(tabularType.RowType), o); result.Put(MakeRowValue(element, index, tabularType.RowType)); index++; } return(result); } }
public void PlainNetMapperCanHandleSimpleFlatTypes() { OpenTypeKind mapsTo; Assert.IsTrue(mapper.CanHandle(typeof(SimpleFlatType), out mapsTo, CanHandle)); Assert.AreEqual(OpenTypeKind.CompositeType, mapsTo); OpenType mappedType = mapper.MapType(typeof(SimpleFlatType), MapType); Assert.AreEqual(OpenTypeKind.CompositeType, mappedType.Kind); CompositeType compositeType = (CompositeType)mappedType; Assert.AreEqual("SimpleFlatType", compositeType.TypeName); Assert.AreEqual("SimpleFlatType", compositeType.Description); Assert.IsTrue(compositeType.ContainsKey("IntValue")); Assert.IsTrue(compositeType.ContainsKey("StringValue")); Assert.AreEqual(2, compositeType.KeySet.Count); Assert.AreEqual(SimpleType.Integer, compositeType.GetOpenType("IntValue")); Assert.AreEqual(SimpleType.String, compositeType.GetOpenType("StringValue")); SimpleFlatType value = new SimpleFlatType(); value.IntValue = 5; value.StringValue = "A text"; object mappedValue = mapper.MapValue(typeof(SimpleFlatType), mappedType, value, MapValue); Assert.IsTrue(mappedValue is ICompositeData); ICompositeData compositeData = (ICompositeData)mappedValue; Assert.IsTrue(compositeType.IsValue(compositeData)); Assert.IsTrue(compositeData.ContainsKey("IntValue")); Assert.IsTrue(compositeData.ContainsKey("StringValue")); Assert.AreEqual(value.IntValue, compositeData["IntValue"]); Assert.AreEqual(value.StringValue, compositeData["StringValue"]); Assert.AreEqual(2, compositeData.Values.Count()); }
public void SetComposite(int id, string name) { _compositeValue = new CompositeDataSupport(_tabularType.RowType, new[] { "ID", "Name" }, new object[] { id, name }); }
public void SetAttribute(string attributeName, object value) { switch (attributeName) { case "Tabular": _tabularValue = (ITabularData)value; break; case "Array": _arrayValue = (decimal[]) value; break; case "Composite": _compositeValue = (ICompositeData) value; break; default: throw new NotSupportedException(); } }
public CompositeDataValueType(ICompositeData value) { CompositeDataType = new CompositeDataType_Type(value.CompositeType); Values = value.Values.Select(x => new GenericValueType(x)).ToArray(); }
private static ICompositeData MakeRowValue(ICompositeData elementValue, int index, CompositeType rowType) { List<string> names = new List<string>(); List<object> values = new List<object>(); names.Add(CollectionIndexColumnName); values.Add(index); foreach (string itemName in elementValue.CompositeType.KeySet) { names.Add(itemName); values.Add(elementValue[itemName]); } return new CompositeDataSupport(rowType, names, values); }
private static CompositeData FormatCompositeValue(CompositeType compositeType, ICompositeData compositeData) { return new CompositeData(compositeType.KeySet.Select(x => new CompositeDataProperty(x, FormatSimpleValue(compositeType.GetOpenType(x), compositeData[x])))); }
public sealed override bool IsValue(object value) { ICompositeData composite = value as ICompositeData; return(composite != null && composite.CompositeType.Equals(this)); }
private static CompositeData FormatCompositeValue(CompositeType compositeType, ICompositeData compositeData) { return(new CompositeData(compositeType.KeySet.Select(x => new CompositeDataProperty(x, FormatSimpleValue(compositeType.GetOpenType(x), compositeData[x]))))); }