public static Dictionary <string, ISemanticType> BuildSemanticTypes(List <SemanticTypeDecl> decls, List <SemanticTypeStruct> structs) { Dictionary <string, ISemanticType> semanticTypes = new Dictionary <string, ISemanticType>(); decls.ForEach(decl => { // Given a SemanticTypeDecl: // The supporting SemanticTypeStruct is identified by the Value value of the attribute named "Name". // Must exist. An exception is thrown otherwise. Assert.ErrorMessage = "Decl is missing a Name attribute"; var structName = decl.AttributeValues.Single(attrValue => attrValue.Name == "Name").Value; // This gives us the SemanticTypeStruct: Assert.ErrorMessage = "Struct " + structName + " does not have a declaration."; var ststruct = structs.Single(s => s.DeclTypeName == structName); // The OfType struct in the decl is the same as the DeclType of a SemanticTypeStruct Assert.ErrorMessage = "Struct " + decl.OfTypeName + " does not have a declaration."; var ofType = structs.Single(s => s.DeclTypeName == decl.OfTypeName); Assert.ErrorMessage = null; // Set the cross-reference instances: ststruct.DeclType = decl; decl.OfType = ststruct; // The semantic type cannot exist. Assert.That(!semanticTypes.ContainsKey(structName), "Duplicate SemanticTypeStruct: " + structName); // The decl's of-type struct's native types must match the decl's attribute value names. // This is a validation process. Match(ofType, decl.AttributeValues); ISemanticType st = new SemanticType() { Decl = decl, Struct = ststruct }; semanticTypes[structName] = st; }); // Populate Element instances. structs.ForEach(s => { s.SemanticElements.ForEach(elem => elem.Element = semanticTypes[elem.Name]); }); return(semanticTypes); }
/// <summary> /// Initializes the native types of a semantic type to the attribute values specified in the markup. /// TODO: This needs to be recursive and also to parse dotted notation when drilling into multiple levels of types. /// </summary> public static void InitializeNativeTypes(SemanticType st, List <INativeType> nativeTypes, StringBuilder sb, string prefix = "") { foreach (NativeType ntype in nativeTypes) { // Attribute may not be initialized, in which case it defaults to the native implementation's default. st.Decl.AttributeValues.Find(t => t.Name == ntype.Name).IfNotNull(t => { if (t.Value != null) { string qualifiedName = (prefix.IsEmpty() ? t.Name : prefix + "." + t.Name); if (ntype.ImplementingType == "string") { sb.AppendLine("\t\t\t" + qualifiedName + " = \"" + t.Value + "\";"); } else { sb.AppendLine("\t\t\t" + qualifiedName + " = " + t.Value + ";"); } } }); } }
public static Dictionary<string, ISemanticType> BuildSemanticTypes(List<SemanticTypeDecl> decls, List<SemanticTypeStruct> structs) { Dictionary<string, ISemanticType> semanticTypes = new Dictionary<string, ISemanticType>(); decls.ForEach(decl => { // Given a SemanticTypeDecl: // The supporting SemanticTypeStruct is identified by the Value value of the attribute named "Name". // Must exist. An exception is thrown otherwise. Assert.ErrorMessage = "Decl is missing a Name attribute"; var structName = decl.AttributeValues.Single(attrValue => attrValue.Name == "Name").Value; // This gives us the SemanticTypeStruct: Assert.ErrorMessage = "Struct " + structName + " does not have a declaration."; var ststruct = structs.Single(s => s.DeclTypeName == structName); // The OfType struct in the decl is the same as the DeclType of a SemanticTypeStruct Assert.ErrorMessage = "Struct " + decl.OfTypeName + " does not have a declaration."; var ofType = structs.Single(s => s.DeclTypeName == decl.OfTypeName); Assert.ErrorMessage = null; // Set the cross-reference instances: ststruct.DeclType = decl; decl.OfType = ststruct; // The semantic type cannot exist. Assert.That(!semanticTypes.ContainsKey(structName), "Duplicate SemanticTypeStruct: " + structName); // The decl's of-type struct's native types must match the decl's attribute value names. // This is a validation process. Match(ofType, decl.AttributeValues); ISemanticType st = new SemanticType() { Decl = decl, Struct = ststruct }; semanticTypes[structName] = st; }); // Populate Element instances. structs.ForEach(s => { s.SemanticElements.ForEach(elem => elem.Element = semanticTypes[elem.Name]); }); return semanticTypes; }
/// <summary> /// Initializes the native types of a semantic type to the attribute values specified in the markup. /// TODO: This needs to be recursive and also to parse dotted notation when drilling into multiple levels of types. /// </summary> public static void InitializeNativeTypes(SemanticType st, List<INativeType> nativeTypes, StringBuilder sb, string prefix="") { foreach (NativeType ntype in nativeTypes) { // Attribute may not be initialized, in which case it defaults to the native implementation's default. st.Decl.AttributeValues.Find(t => t.Name == ntype.Name).IfNotNull(t => { if (t.Value != null) { string qualifiedName = (prefix.IsEmpty() ? t.Name : prefix + "." + t.Name); if (ntype.ImplementingType == "string") { sb.AppendLine("\t\t\t" + qualifiedName + " = \"" + t.Value + "\";"); } else { sb.AppendLine("\t\t\t" + qualifiedName + " = " + t.Value + ";"); } } }); } }