public virtual bool IsSuperType(DataType other) { while (other != null) { if (EquivalentTo(other)) { return true; } other = other.BaseType; } return false; }
public virtual bool IsSubType(DataType other) { var currentType = this; while (currentType != null) { if (currentType.EquivalentTo(other)) { return true; } currentType = currentType.BaseType; } return false; }
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; }
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; }
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; }
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(); }
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); }
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; } }
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) }; }
/// <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); }
/// <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); }
/// <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; }
public virtual bool EquivalentTo(DataType other) { return other != null && Name == other.Name; }
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; }
public DataType(DataType baseType) { _baseType = baseType; }
public ScalarType(string name, DataType baseType) : base(baseType) { if (String.IsNullOrEmpty(name)) { throw new ArgumentNullException("name"); } _name = name; }
public override bool EquivalentTo(DataType other) { var otherIntervalType = other as IntervalType; return otherIntervalType != null && PointType.EquivalentTo(otherIntervalType.PointType); }
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; }