Esempio n. 1
0
        public void TestGetOpenType()
        {
            CompositeType type = CreateSampleType();

            Assert.AreEqual(SimpleType.Integer, type.GetOpenType("ItemName1"));
            Assert.AreEqual(SimpleType.Double, type.GetOpenType("ItemName2"));
            Assert.AreEqual(null, type.GetOpenType("ItemName3"));
        }
Esempio n. 2
0
        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());
        }
Esempio n. 3
0
        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"]);
        }
Esempio n. 4
0
        private static CompositeType MakeElementType(CompositeType rowType)
        {
            List <string>   names        = new List <string>();
            List <string>   descriptions = new List <string>();
            List <OpenType> types        = new List <OpenType>();

            foreach (string itemName in rowType.KeySet)
            {
                if (itemName != CollectionIndexColumnName)
                {
                    names.Add(itemName);
                    descriptions.Add(rowType.GetDescription(itemName));
                    types.Add(rowType.GetOpenType(itemName));
                }
            }
            return(new CompositeType(rowType.TypeName, rowType.Description, names, descriptions, types));
        }
Esempio n. 5
0
        private static CompositeType MakeRowType(CompositeType elementType)
        {
            List <string>   names        = new List <string>();
            List <string>   descriptions = new List <string>();
            List <OpenType> types        = new List <OpenType>();

            names.Add(CollectionIndexColumnName);
            descriptions.Add("Index of a collection");
            types.Add(SimpleType.Integer);

            foreach (string itemName in elementType.KeySet)
            {
                names.Add(itemName);
                descriptions.Add(elementType.GetDescription(itemName));
                types.Add(elementType.GetOpenType(itemName));
            }
            return(new CompositeType(elementType.TypeName, elementType.Description, names, descriptions, types));
        }
Esempio n. 6
0
        public object MapValue(Type plainNetType, OpenType mappedType, object value, MapValueDelegate mapNestedValueCallback)
        {
            if (value == null)
            {
                return(null);
            }

            CompositeType compositeType = (CompositeType)mappedType;
            Type          valueType     = value.GetType();

            List <string> names  = new List <string>();
            List <object> values = new List <object>();

            foreach (string itemName in compositeType.KeySet)
            {
                PropertyInfo propertyInfo       = valueType.GetProperty(itemName, BindingFlags.Public | BindingFlags.Instance);
                object       propValue          = propertyInfo.GetValue(value, new object[] {});
                OpenType     mappedPropertyType = compositeType.GetOpenType(itemName);
                values.Add(mapNestedValueCallback(propertyInfo.PropertyType, mappedPropertyType, propValue));
                names.Add(itemName);
            }
            return(new CompositeDataSupport(compositeType, names, values));
        }
Esempio n. 7
0
 private static ICompositeData ExtractCompositeValue(CompositeType openType, CompositeData compositeData)
 {
     return(new CompositeDataSupport(openType,
                                     compositeData.Properties.Select(x => x.Name),
                                     compositeData.Properties.Select(x => ExtractSimpleValue(openType.GetOpenType(x.Name), x.Value))));
 }
Esempio n. 8
0
 private static CompositeData FormatCompositeValue(CompositeType compositeType, ICompositeData compositeData)
 {
     return(new CompositeData(compositeType.KeySet.Select(x => new CompositeDataProperty(x, FormatSimpleValue(compositeType.GetOpenType(x), compositeData[x])))));
 }
Esempio n. 9
0
        public CompositeDataType_Type(CompositeType value)
            : base(value)
        {
            List <CompositeDataField> fields = new List <CompositeDataField>();

            foreach (string fieldName in value.KeySet)
            {
                fields.Add(new CompositeDataField(fieldName, value.GetDescription(fieldName), Serialize(value.GetOpenType(fieldName))));
            }
            CompositeDataField = fields.ToArray();
        }