/// <summary>Links the primitive type to the package.</summary> /// <param name="bplPrimitive">The BPL primitive.</param> private void linkPrimitive(BplPrimitive bplPrimitive) { MetaPrimitive metaPrimitive = new MetaPrimitive(bplPrimitive); MetaPackage mPackage = this.metaModel.GetPackageByName(metaPrimitive.Namespace); if (mPackage == null) { throw new Exception(string.Format("Package {0} was not found in the model to link primitive: {1}", metaPrimitive.Namespace, metaPrimitive.CanonicName)); } else { mPackage.Primitives.Add(metaPrimitive); } }
/// <summary>Loads meta primitive data from XML.</summary> public static MetaPrimitive LoadFromXml(XElement xml) { try { MetaPrimitive prim = new MetaPrimitive(); prim.Name = xml.HasAttribute("name") ? xml.Attribute("name").Value : ""; prim.CanonicName = xml.HasAttribute("canonicName") ? xml.Attribute("canonicName").Value : ""; prim.Namespace = xml.HasAttribute("namespace") ? xml.Attribute("namespace").Value : ""; prim.IsNullable = xml.HasAttribute("isNullable") ? (bool)xml.Attribute("isNullable") : false; prim.TagName = xml.HasAttribute("tagName") ? xml.Attribute("tagName").Value : ""; //prim.BaseType = xml.HasAttribute("baseType") ? xml.Attribute("baseType").Value : ""; return prim; } catch (Exception) { return null; } }
/// <summary>Initializes a new instance of the <see cref="BplProperty"/> class.</summary> public MetaProperty(BplProperty bplProperty) { // Fill class level attributes this.Name = bplProperty.Name; this.CanonicName = bplProperty.CanonicName; this.IsScalar = !(bplProperty.IsArray || bplProperty.IsCollection); this.IsArray = bplProperty.IsArray; this.IsCollection = bplProperty.IsCollection; this.IsPrimitive = bplProperty.IsPrimitive; if (this.IsArray || this.IsCollection) { this.DataType = Repository.ResolveType(bplProperty.UnderlyingItemType.FullName); } else { this.DataType = Repository.ResolveType(bplProperty.UnderlyingType.FullName); } if (this.DataType.Contains("[[")) { this.DataType = bplProperty.IsNullable ? string.Format("{0}?", bplProperty.UnderlyingItemType.FullName) : bplProperty.UnderlyingItemType.FullName; } this.IsReadOnly = bplProperty.IsCalculated; var documentation = BplLanguage.Documentation[bplProperty].Content; if (documentation != null) { this.Documentation = new Documentation(documentation); } // Register primitive type /*****************************/ if (bplProperty.IsPrimitive) { if (bplProperty.PrimitiveType.IsEnum) { MetaEnum me = new MetaEnum(bplProperty.PrimitiveType); } else { if (this.IsScalar) { if (!Repository.TypesMapper.ContainsKey(bplProperty.UnderlyingType.FullName)) { MetaPrimitive mp = new MetaPrimitive(bplProperty.PrimitiveType); } } else { if (!Repository.TypesMapper.ContainsKey(bplProperty.UnderlyingItemType.FullName)) { MetaPrimitive mp = new MetaPrimitive(bplProperty.PrimitiveType.ItemType); } } } } /*****************************/ }
/// <summary>Edit meta primitive in the editor panel.</summary> private void EditMetaPrimitive(MetaPrimitive mPrimitive) { MetaPrimitiveEditorControl ctrl = new MetaPrimitiveEditorControl(); ObjectPanel.Children.Add(ctrl); ctrl.DataContext = mPrimitive; }
/// <summary>Generate primitive file.</summary> private void generatePrimitiveFile(MetaPrimitive metaPrimitive, string templateName, string folder, string filePattern) { // If primitive is in the mapper list, don't generate it if (this.TemplateInfo.TypesMap.ContainsKey(metaPrimitive.CanonicName)) return; this.notifyAction("Generating primitive {0} ...", metaPrimitive.Name); // Verify that primitive template exists StringTemplate template = this.stGroup.GetInstanceOf(templateName); if (template == null) return; // Generate primitive related source files string targetFolder = verifyDirectory(folder, metaPrimitive.Namespace); template.SetAttribute("BplPrimitive", metaPrimitive); string targetFile = this.ResolveFileName(metaPrimitive, filePattern); string targetPath = Path.Combine(targetFolder, targetFile); using (StreamWriter outfile = new StreamWriter(targetPath)) { outfile.Write(template.ToString()); } }