public void Verify(VerificationContext context, ASTNode node)
		{
			// objectType
            var objectTypeName = node.GetAttribute<string>("classType");
            if (objectTypeName != null)
            {
			    var objectType = context.ResolveType(node.GetAttribute<string>("classType")) as ObjectType;

			    // foreach property
			    foreach (var child in ((Node)node).Children)
			    {
					if (child.Name == "element") 
					{
						// Verify the property exists
						var childPropertyType = context.ResolveProperty(objectType, child.GetAttribute<string>("name"));

						// Verify the value
						var value = (ASTNode)child.Children[0];
						Verifier.Verify(context, value);

						// Verify the value type is appropriate for the property type
						context.VerifyType(value.ResultType, childPropertyType);
					}
			    }

			    node.ResultType = objectType;
            }
            else
            {
                var propertyList = new List<PropertyDef>();

                foreach (var child in ((Node)node).Children)
                {
					if (child.Name == "element")
					{
						var value = (ASTNode)child.Children[0];
						Verifier.Verify(context, value);

						var property = new PropertyDef(child.GetAttribute<string>("name"), value.ResultType);
						propertyList.Add(property);
					}
                }

                var objectType = new ObjectType(Guid.NewGuid().ToString(), propertyList);

                node.ResultType = objectType;
            }
		}
		protected override void InternalVerify(VerificationContext context, ASTNode node)
		{
			base.InternalVerify(context, node);

			var dataTypes = new List<DataType>();
			foreach (var child in node.Children)
			{
				if (child.ResultType == null)
				{
					throw new InvalidOperationException(String.Format("Could not determine type of '{0}' expression.", child.Name));
				}

				dataTypes.Add(child.ResultType);
			}

			var op = context.ResolveCall(GetOperatorName(node), new Signature(dataTypes));

			node.ResultType = op.ResultType;
		}
Exemple #3
0
        private static IEnumerable<PropertyDef> ResolveProperties(Type type)
        {
            var properties = new List<PropertyDef>();

            foreach (var property in type.GetProperties())
            {
                // For choice elements, the element names should appear traversible as properties, otherwise there would be no way to access the value
                // (HeD does not have a Cast, and the xsd doesn't actually have a property named Item, which is how choices deserialize)
                var propertyAdded = false;
                foreach (var attribute in property.GetCustomAttributes(typeof(XmlElementAttribute), false).OfType<XmlElementAttribute>())
                {
                    if (!string.IsNullOrEmpty(attribute.ElementName) && attribute.Type != null && attribute.Type != type)
                    {
                        properties.Add(new PropertyDef(attribute.ElementName, ResolveType(attribute.Type)));
                        propertyAdded = true;
                    }
                }

                if (!propertyAdded)
                {
                    properties.Add(new PropertyDef(property.Name, ResolveType(property.PropertyType)));
                }
            }

            return properties;
        }