예제 #1
0
        private static void ConvertUnknownProperties(IPropertyProvider myPropertyProvider, IBaseType myBaseType)
        {
            if (myPropertyProvider.UnknownProperties != null)
            {
                foreach (var unknownProp in myPropertyProvider.UnknownProperties)
                {
                    //ASK: What's about binary properties?
                    if (myBaseType.HasProperty(unknownProp.Key))
                    {
                        var propDef = myBaseType.GetPropertyDefinition(unknownProp.Key);

                        try
                        {
                            var converted = unknownProp.Value.ConvertToIComparable(propDef.BaseType);
                            myPropertyProvider.AddStructuredProperty(unknownProp.Key, converted);
                        }
                        catch (InvalidCastException)
                        {
                            //TODO: better exception
                            throw new Exception("Type of property does not match.");
                        }
                    }
                    else
                    {
                        myPropertyProvider.AddUnstructuredProperty(unknownProp.Key, unknownProp.Value);
                    }
                }
                myPropertyProvider.ClearUnknown();
            }
        }
예제 #2
0
        protected static void ConvertUnknownProperties(IPropertyProvider myPropertyProvider,
                                                       IBaseType myBaseType)
        {
            if (myPropertyProvider.UnknownProperties != null)
            {
                foreach (var unknownProp in myPropertyProvider.UnknownProperties)
                {
                    //ASK: What's about binary properties?
                    if (myBaseType.HasProperty(unknownProp.Key))
                    {
                        var propDef = myBaseType.GetPropertyDefinition(unknownProp.Key);

                        try
                        {
                            IComparable converted = null;

                            if (propDef.Multiplicity == PropertyMultiplicity.List ||
                                propDef.Multiplicity == PropertyMultiplicity.Set)
                            {
                                converted = unknownProp.Value.ConvertToIComparableList(propDef.BaseType);
                            }
                            else
                            {
                                if (propDef.BaseType.IsSubclassOf(typeof(AUserdefinedDataType)))
                                {
                                    var userdefType = (AUserdefinedDataType)Activator.CreateInstance(propDef.BaseType, new object[] { unknownProp.Value.ConvertToIComparable(typeof(String)) as String });

                                    if (userdefType != null)
                                    {
                                        converted = userdefType;
                                    }
                                }
                                else
                                {
                                    converted = unknownProp.Value.ConvertToIComparable(propDef.BaseType);
                                }
                            }

                            myPropertyProvider.AddStructuredProperty(unknownProp.Key, converted);
                        }
                        catch (InvalidCastException)
                        {
                            //TODO: better exception
                            throw new Exception("Type of property does not match.");
                        }
                    }
                    else
                    {
                        IComparable converted = null;

                        try
                        {
                            if (unknownProp.Value is IEnumerable <Object> )
                            {
                                if (((IEnumerable <Object>)unknownProp.Value).Count() > 1)
                                {
                                    converted = unknownProp.Value.ConvertToIComparableList(typeof(object));
                                }
                                else
                                {
                                    converted = unknownProp.Value.ConvertToIComparable(typeof(object));
                                }
                            }
                            else
                            {
                                converted = unknownProp.Value.ConvertToIComparable(typeof(object));
                            }

                            myPropertyProvider.AddUnstructuredProperty(unknownProp.Key, converted);
                        }
                        catch (InvalidCastException)
                        {
                            myPropertyProvider.AddUnstructuredProperty(unknownProp.Key, unknownProp.Value);
                        }
                    }
                }
                myPropertyProvider.ClearUnknown();
            }
        }
예제 #3
0
        protected static void ConvertUnknownProperties(IPropertyProvider myPropertyProvider,
                                                        IBaseType myBaseType)
        {
            if (myPropertyProvider.UnknownProperties != null)
            {
                foreach (var unknownProp in myPropertyProvider.UnknownProperties)
                {
                    //ASK: What's about binary properties?
                    if (myBaseType.HasProperty(unknownProp.Key))
                    {
                        var propDef = myBaseType.GetPropertyDefinition(unknownProp.Key);

                        try
                        {
                            IComparable converted = null;

                            if (propDef.Multiplicity == PropertyMultiplicity.List ||
                                propDef.Multiplicity == PropertyMultiplicity.Set)
                                converted = unknownProp.Value.ConvertToIComparableList(propDef.BaseType);
                            else
                                converted = unknownProp.Value.ConvertToIComparable(propDef.BaseType);

                            myPropertyProvider.AddStructuredProperty(unknownProp.Key, converted);
                        }
                        catch (InvalidCastException)
                        {
                            //TODO: better exception
                            throw new Exception("Type of property does not match.");
                        }
                    }
                    else
                    {
                        IComparable converted = null;

                        try
                        {
                            if (unknownProp.Value is IEnumerable<Object>)
                                if (((IEnumerable<Object>)unknownProp.Value).Count() > 1)
                                    converted = unknownProp.Value.ConvertToIComparableList(typeof(object));
                                else
                                    converted = unknownProp.Value.ConvertToIComparable(typeof(object));
                            else
                                converted = unknownProp.Value.ConvertToIComparable(typeof(object));

                            myPropertyProvider.AddUnstructuredProperty(unknownProp.Key, converted);
                        }
                        catch (InvalidCastException)
                        {
                            myPropertyProvider.AddUnstructuredProperty(unknownProp.Key, unknownProp.Value);
                        }
                    }
                }
                myPropertyProvider.ClearUnknown();
            }
        }