Esempio n. 1
0
        public virtual bool IsSuperType(DataType other)
        {
            while (other != null)
            {
                if (EquivalentTo(other))
                {
                    return true;
                }
                other = other.BaseType;
            }

            return false;
        }
Esempio n. 2
0
        public virtual bool IsSubType(DataType other)
        {
            var currentType = this;
            while (currentType != null)
            {
                if (currentType.EquivalentTo(other))
                {
                    return true;
                }
                currentType = currentType.BaseType;
            }

            return false;
        }
Esempio n. 3
0
		public Symbol(string name, DataType dataType)
		{
			if (string.IsNullOrEmpty(name))
			{
				throw new ArgumentNullException("name");
			}

			if (dataType == null)
			{
				throw new ArgumentNullException("dataType");
			}

			_name = name;
			_dataType = dataType;
		}
Esempio n. 4
0
		public Operator(string name, Signature signature, DataType resultType)
		{
			if (String.IsNullOrEmpty(name))
			{
				throw new ArgumentNullException("name");
			}

			if (signature == null)
			{
				throw new ArgumentNullException("signature");
			}

			_name = name;
			_signature = signature;
			_resultType = resultType;
		}
Esempio n. 5
0
        public override bool EquivalentTo(DataType other)
        {
            var otherObjectType = other as ObjectType;

            if (otherObjectType != null)
            {
                if (String.Compare(_name, otherObjectType.Name, false, CultureInfo.InvariantCulture) == 0)
                {
                    return true;
                }

                if (otherObjectType.Properties.Count == _properties.Count)
                {
                    var properties = GetSortedProperties();
                    var otherProperties = otherObjectType.GetSortedProperties();

                    for (int i = 0; i < properties.Count; i++)
                    {
                        if (!properties[i].EquivalentTo(otherProperties[i]))
                        {
                            return false;
                        }
                    }

                    return true;
                }
            }

            return false;
        }
Esempio n. 6
0
        public ObjectType(string name, DataType baseType, IEnumerable<PropertyDef> properties)
            : base(baseType)
        {
            if (String.IsNullOrEmpty(name))
            {
                throw new ArgumentNullException("name");
            }

            if (properties == null)
            {
                throw new ArgumentNullException("properties");
            }

            _name = name;
            _properties = properties.ToList();
        }
Esempio n. 7
0
 public override bool IsSubType(DataType other)
 {
     // List covariance works because lists are immutable
     var otherList = other as ListType;
     return otherList != null && _elementType.IsSubType(otherList.ElementType);
 }
Esempio n. 8
0
 public override bool EquivalentTo(DataType other)
 {
     var otherList = other as ListType;
     return otherList != null && _elementType.EquivalentTo(otherList.ElementType);
 }
 private DataType ResolveIndexerType(DataType currentType, string pn)
 {
     var currentListType = currentType as ListType;
     if (currentListType == null)
     {
         throw new InvalidOperationException(String.Format("Could not index into property '{0}' of type '{1}' because it is not a list type.", pn, currentType.Name));
     }
     else
     {
         return currentListType.ElementType;
     }
 }
Esempio n. 10
0
        public IntervalType(DataType pointType)
            : base(DataTypes.Any)
        {
            if (pointType == null)
            {
                throw new ArgumentNullException("pointType");
            }

            _pointType = pointType;

            // All interval types have these properties
            _properties =
                new List<PropertyDef>
                {
                    new PropertyDef("begin", pointType),
                    new PropertyDef("end", pointType),
                    new PropertyDef("beginOpen", DataTypes.Boolean),
                    new PropertyDef("endOpen", DataTypes.Boolean),

                    // Added to support access to the properties using both begin/end as well as the cdsdt-style low/high
                    // NOTE: This was not possible before due to the inconsistent naming of interval types in cdsdt;
                    // those issues have been corrected as part of vMR-R2.
                    new PropertyDef("low", pointType),
                    new PropertyDef("high", pointType),
                    new PropertyDef("lowClosed", DataTypes.Boolean),
                    new PropertyDef("highClosed", DataTypes.Boolean)
                };
        }
Esempio n. 11
0
 /// <summary>
 /// Compares two data type instances for super-type.
 /// </summary>
 /// <returns>True if the first type is a supertype (or the same type) as the second type, false otherwise.</returns>
 public static bool SuperTypeOf(DataType a, DataType b)
 {
     return a != null && b != null && a.IsSuperType(b);
 }
Esempio n. 12
0
 /// <summary>
 /// Compares two DataType instances for equivalence.
 /// </summary>
 /// <returns>True if the DataTypes are equivalent, false otherwise.</returns>
 /// <remarks>
 /// <para>
 /// Data type equivalence is looser than data type equality. So two data types
 /// are equivalent if they are equal, or, in the case of object types, if they
 /// have the same set of properties, by name and property type equivalence.
 /// </para>
 /// </remarks>
 public static bool Equivalent(DataType a, DataType b)
 {
     return a != null && b != null && a.EquivalentTo(b);
 }
Esempio n. 13
0
 /// <summary>
 /// Compares two DataType instances for equality.
 /// </summary>
 /// <returns>True if the DataTypes are equal, false otherwise.</returns>
 /// <remarks>
 /// <para>
 /// Data type equality is based on the notion of names, not instances, meaning
 /// that two different instances of the ScalarType named Boolean will be considered 
 /// equal.
 /// </para>
 /// <para>
 /// Two scalar types are equal if they have the same name.
 /// </para>
 /// <para>
 /// Two list types are equal if their element types are equal.
 /// </para>
 /// <para>
 /// Two interval types are equal if their point types are equal.
 /// </para>
 /// <para>
 /// Two object types are equal if they have the same name.
 /// </para>
 /// </remarks>
 public static bool Equal(DataType a, DataType b)
 {
     return a != null && b != null && a.Equals(b);
 }
		public void VerifyType(DataType actualType, DataType expectedType)
		{
            if (!DataTypes.SubTypeOf(actualType, expectedType))
			//if (!DataTypes.Equivalent(actualType, expectedType))
			{
				throw 
					new InvalidOperationException
					(
						String.Format
						(
							"Expected an expression of type '{0}', but found an expression of type '{1}'.", 
							expectedType != null ? expectedType.ToString() : "<unknown>", 
							actualType != null ? actualType.ToString() : "<unknown>"
						)
					);
			}
		}
		public DataType ResolveProperty(DataType dataType, string path)
		{
            // TODO: Need to handle this scenario: contained[medication.reference].Medication.code.coding[1]
            // The use of Split here incorrectly splits on the path within the indexer
			var propertyNames = path.Split('.');
			DataType currentType = dataType;
			foreach (var propertyName in propertyNames)
			{
                var pn = propertyName;
                var isIndexer = ProcessIndexer(ref pn);
				var currentIntervalType = currentType as IntervalType;
				if (currentIntervalType != null)
				{
					var propertyDef = currentIntervalType.Properties.FirstOrDefault(p => String.Compare(p.Name, pn, true) == 0);
					if (propertyDef == null)
					{
						throw new InvalidOperationException(String.Format("Could not resolve property name '{0}' on interval type '{1}'.", pn, currentIntervalType.Name));
					}

					currentType = propertyDef.PropertyType;

                    if (isIndexer)
                    {
                        currentType = ResolveIndexerType(currentType, pn);
                    }
				}
				else
				{
					var currentObjectType = currentType as ObjectType;
					if (currentObjectType == null)
					{
						throw new InvalidOperationException(String.Format("Could not resolve property path '{0}'.", path));
					}

                    PropertyDef propertyDef = null;
                    while (currentObjectType != null)
                    {
					    propertyDef = currentObjectType.Properties.FirstOrDefault(p => String.Compare(p.Name, pn, true) == 0);
                        if (propertyDef != null)
                        {
                            break;
                        }

                        currentObjectType = currentObjectType.BaseType as ObjectType;
                    }

					if (propertyDef == null)
					{
						throw new InvalidOperationException(String.Format("Could not resolve property name '{0}'.", pn));
					}

					currentType = propertyDef.PropertyType;

                    if (isIndexer)
                    {
                        currentType = ResolveIndexerType(currentType, pn);
                    }
				}
			}

			return currentType;
		}
Esempio n. 16
0
 public virtual bool EquivalentTo(DataType other)
 {
     return other != null && Name == other.Name;
 }
Esempio n. 17
0
        public PropertyDef(string name, DataType propertyType)
        {
            if (String.IsNullOrEmpty(name))
            {
                throw new ArgumentNullException("name");
            }

            if (propertyType == null)
            {
                throw new ArgumentNullException("propertyType");
            }

            _name = name;
            _propertyType = propertyType;
        }
Esempio n. 18
0
 public DataType(DataType baseType)
 {
     _baseType = baseType;
 }
Esempio n. 19
0
        public ScalarType(string name, DataType baseType)
            : base(baseType)
        {
            if (String.IsNullOrEmpty(name))
            {
                throw new ArgumentNullException("name");
            }

            _name = name;
        }
Esempio n. 20
0
 public override bool EquivalentTo(DataType other)
 {
     var otherIntervalType = other as IntervalType;
     return otherIntervalType != null && PointType.EquivalentTo(otherIntervalType.PointType);
 }
Esempio n. 21
0
        public ListType(DataType elementType)
            : base(null)
        {
            if (elementType == null)
            {
                throw new ArgumentNullException("elementType");
            }

            _elementType = elementType;
        }
        public DataType ResolveProperty(DataType dataType, string path)
        {
            var propertyNames = path.Split('.');
            DataType currentType = dataType;
            foreach (var propertyName in propertyNames)
            {
                var pn = propertyName;
                var isIndexer = ProcessIndexer(ref pn);
                var currentIntervalType = currentType as IntervalType;
                if (currentIntervalType != null)
                {
                    var propertyDef = currentIntervalType.Properties.FirstOrDefault(p => p.Name == pn);
                    if (propertyDef == null)
                    {
                        throw new InvalidOperationException(String.Format("Could not resolve property name '{0}' on interval type '{1}'.", pn, currentIntervalType.Name));
                    }

                    currentType = propertyDef.PropertyType;

                    if (isIndexer)
                    {
                        currentType = ResolveIndexerType(currentType, pn);
                    }
                }
                else
                {
                    var currentObjectType = currentType as ObjectType;
                    if (currentObjectType == null)
                    {
                        throw new InvalidOperationException(String.Format("Could not resolve property path '{0}'.", path));
                    }

                    PropertyDef propertyDef = null;
                    while (currentObjectType != null)
                    {
                        propertyDef = currentObjectType.Properties.FirstOrDefault(p => p.Name == pn);
                        if (propertyDef != null)
                        {
                            break;
                        }

                        currentObjectType = currentObjectType.BaseType as ObjectType;
                    }

                    if (propertyDef == null)
                    {
                        throw new InvalidOperationException(String.Format("Could not resolve property name '{0}'.", pn));
                    }

                    currentType = propertyDef.PropertyType;

                    if (isIndexer)
                    {
                        currentType = ResolveIndexerType(currentType, pn);
                    }
                }
            }

            return currentType;
        }