/// <summary>Initializes a new instance of the <see cref="MetaEnum"/> class.</summary> public MetaEnum(BplPrimitive bplPrimitive) : this() { // Skip this if the enum is registered //if (Repository.IsEnumExists(bplPrimitive.CanonicName)) return; // Set fields this.Name = bplPrimitive.Name; this.CanonicName = bplPrimitive.CanonicName; this.Namespace = bplPrimitive.CanonicName.Substring(0, bplPrimitive.CanonicName.IndexOf(string.Format(".{0}", bplPrimitive.Name))); Type enumType = bplPrimitive.UnderlyingType; string baseEnumType = Enum.GetUnderlyingType(enumType).ToString(); //this.BaseType = Repository.ResolveType(baseEnumType); this.BaseType = baseEnumType; string[] enumNames = Enum.GetNames(enumType); for (int idx = 0; idx < enumNames.Length; idx++) { string eName = enumNames[idx]; object enumInst = Enum.Parse(enumType, eName); string eVal = this.GetEnumValue(enumInst, baseEnumType, idx); this.EnumValues.Add(new MetaEnumValue(eName, eVal)); } this.Register(); }
/// <summary>Initializes a new instance of the <see cref="MetaPrimitive"/> class.</summary> /// <param name="bplPrimitive">The BPL primitive.</param> public MetaPrimitive(BplPrimitive bplPrimitive) { // Skip this if the primitive is registered if (Repository.IsPrimitiveExists(bplPrimitive.CanonicName)) return; this.IsNullable = bplPrimitive.IsNullable; // Fill primitive level attributes if (bplPrimitive.IsArray) { this.Name = bplPrimitive.Name; this.CanonicName = bplPrimitive.CanonicName; this.TagName = bplPrimitive.TagName.NamespaceName; } else if (bplPrimitive.IsNullable) { this.Name = bplPrimitive.Name; this.CanonicName = bplPrimitive.ItemType.CanonicName; this.TagName = bplPrimitive.TagName.NamespaceName; string fullName = bplPrimitive.ItemType.CanonicName; this.Namespace = fullName.Substring(0, fullName.LastIndexOf(".")); } else { this.Name = bplPrimitive.Name; this.CanonicName = bplPrimitive.CanonicName; this.TagName = bplPrimitive.TagName.NamespaceName; this.Namespace = bplPrimitive.CanonicName.Substring(0, bplPrimitive.CanonicName.LastIndexOf(".")); } this.Register(); //this.BaseType = (this.IsNullable) ? bplPrimitive.ItemType.UnderlyingType.FullName : bplPrimitive.UnderlyingType.FullName; }
// Internal constructor (to prevent direct inheritance by external plugins) internal BplConverter(BplPrimitive primitiveType) { if (primitiveType == null) { BplRuntimeException.Throw("Primitive type is missing"); } PrimitiveType = primitiveType; PrimitiveItemType = PrimitiveType.ItemType; UnderlyingType = primitiveType.UnderlyingType; }
/// <summary>Creates a new <see cref="T:BplArrayConverter"/> instance.</summary> public BplArrayConverter(BplPrimitive primitiveType) : base(primitiveType) { if (!primitiveType.IsArray) { BplRuntimeException.Throw("Primitive type '{0}' must be a BPL array".Substitute(primitiveType)); } var underlyingType = PrimitiveType.UnderlyingType; var createInstance = underlyingType.GetMethod("CreateImmutableCore", BindingFlags.Static | BindingFlags.NonPublic); CreateInstance = createInstance.CreateInvoker<IEnumerable, object>(); _defaultValue = CreateInstance(null, new object[0]); }
/// <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>Add BPL Primitive to the collection.</summary> private void addPrimitive(BplPrimitive primitive) { // Do not include delegate or arrays if (primitive.IsDelegate) return; if (primitive.IsArray) return; if (primitives.Contains(primitive)) return; primitives.Add(primitive); string packageName = primitive.GetPackageName(); getPackage(packageName).Primitives.Add(primitive); if (primitive.IsArray || primitive.IsNullable) { addPrimitive(primitive.ItemType); } }
/// <summary>Creates a new <see cref="T:BplDelegateConverter"/> instance.</summary> public BplDelegateConverter(BplPrimitive primitiveType) : base(primitiveType) { if (!primitiveType.IsDelegate) { BplRuntimeException.Throw("Primitive type '{0}' must be a delegate type".Substitute(primitiveType)); } }
/// <summary>Gets the documentation of the specified BPL primitive.</summary> public BplDocumentationTopic this[BplPrimitive primitive] { get { return new BplDocumentationTopic(primitive); } }
private string QName(BplPrimitive primitive) { if (HideCore) { var xdef = BplLanguage.XmlConverters[primitive].XsdDefinition; if (xdef.IsA<XText>()) { // direct reference to builtin xsd type return ((XText)xdef).Value; } } var name = primitive.Name; var schema = primitive.Schema; var itemType = primitive.ItemType; if (itemType != null) { schema = itemType.Schema; if (primitive.IsArray) { name = itemType.Name + "-Array"; } else if (primitive.IsNullable) { name = itemType.Name + "-Nullable"; } } return QName(schema, name); }
private XElement _generatePrimitive(BplPrimitive primitive) { var itemType = primitive.ItemType; if (primitive.IsEnum) { // special handling of primitive enum type (values may need to be sorted) return BplEnumConverter.XsdInternal(primitive, SortMembers); } else if (HideCore && primitive.IsArray) { // special handling of primitive array type (item type prefix may change) return BplArrayConverter.XsdInternal(itemType.Name+ "-Array", QName(itemType), itemType.TagName); } else if (HideCore && primitive.IsNullable) { // special handling of primitive nullable type (item type prefix may change) return BplNullableConverter.XsdInternal(itemType.Name + "-Nullable", QName(itemType)); } var def = BplLanguage.XmlConverters[primitive].XsdDefinition; if (def.IsA<XElement>()) { // xsd custom datatype return (XElement)def; } else if (!HideCore && def.IsA<XText>()) { // xsd builtin datatype var xsd = XNamespaces.xsd; return new XElement(xsd + "simpleType", new XAttribute("name", primitive.Name), new XElement(xsd + "restriction", new XAttribute("base", ((XText)def).Value)) ); } else { return null; } }
private Inline _formatHyperlink(BplPrimitive primitive) { if (primitive != null) { return _formatHyperlink(primitive.Name, primitive.ToCref()); } return new Span(); }
/// <summary>Creates a new <see cref="T:BplNullableConverter"/> instance.</summary> public BplNullableConverter(BplPrimitive primitiveType) : base(primitiveType) { if (!primitiveType.IsNullable) { BplRuntimeException.Throw("Primitive type '{0}' must be nullable".Substitute(primitiveType)); } }
/// <summary>Add uml extentions for enum and primitive types.</summary> private void AddEnumToolExtensions(BplPrimitive bplPrimitive) { string xmitype = (bplPrimitive.IsEnum) ? "uml:Class" : "uml:PrimitiveType"; string stereotype = (bplPrimitive.IsEnum) ? "uml:Class" : "uml:PrimitiveType"; // Add the element extensions XElement xElementExt = new XElement("element", new XAttribute(xmiNs + "idref", bplPrimitive.GetID()), new XAttribute(xmiNs + "type", "uml:Class"), new XAttribute("name", bplPrimitive.Name), new XAttribute("scope", "public")); xElementExt.Add(new XElement("properties", new XAttribute("documentation", bplPrimitive.CanonicName), new XAttribute("isSpecification", "false"), new XAttribute("sType", "Class"), new XAttribute("scope", "public"), new XAttribute("stereotype", "bplEnum"))); // Add enum values for the the profile extension XElement xAttributes = new XElement("attributes"); // For enums, add all literal values int cnt = 0; foreach (object val in Enum.GetValues(bplPrimitive.UnderlyingType)) { string name = Enum.GetName(bplPrimitive.UnderlyingType, val); string valName = Enum.Format(bplPrimitive.UnderlyingType, val, "d"); XElement xAttribute = new XElement("attribute", new XAttribute(xmiNs + "idref", string.Format("{0}_{1}", bplPrimitive.GetID(), cnt)), new XAttribute("name", name), new XAttribute("value", valName), new XAttribute("scope", "public") ); xAttribute.Add(new XElement("initial", new XAttribute("body", valName))); xAttribute.Add(new XElement("documentation", new XAttribute("value", name))); xAttribute.Add(new XElement("properties", new XAttribute("derived", "0"), new XAttribute("collection", "false"), new XAttribute("length", "0"), new XAttribute("duplicates", "0"), new XAttribute("changeability", "changeable"))); xAttribute.Add(new XElement("bounds", new XAttribute("lower", "1"), new XAttribute("upper", "1"))); xAttribute.Add(new XElement("styleex", new XAttribute("value", "IsLiteral=1;volatile=0;"))); xAttributes.Add(xAttribute); cnt++; } xElementExt.Add(xAttributes); XmiElements.Add(xElementExt); }
/// <summary>Add uml extentions for enum and primitive types.</summary> private void AddToolExtensions(BplPrimitive bplPrimitive) { if (bplPrimitive.IsEnum) { AddEnumToolExtensions(bplPrimitive); return; } // Add the element extensions XElement xElementExt = new XElement("element", new XAttribute(xmiNs + "idref", bplPrimitive.GetID()), new XAttribute(xmiNs + "type", "uml:PrimitiveType"), new XAttribute("name", bplPrimitive.Name), new XAttribute("scope", "public")); xElementExt.Add(new XElement("properties", new XAttribute("documentation", bplPrimitive.CanonicName), new XAttribute("isSpecification", "false"), new XAttribute("sType", "PrimitiveType"), new XAttribute("scope", "public"), new XAttribute("stereotype", "bplPrimitive"))); XmiElements.Add(xElementExt); }
/// <summary>Add uml extentions for enum and primitive types.</summary> private void AddUmlExtensions(BplPrimitive bplPrimitive) { if (bplPrimitive.IsEnum) { AddUmlExtentions("bplEnum", BASE_CLASS, bplPrimitive.GetID()); XmiModel.Add(new XElement(eaNs + "enumeration", new XAttribute(BASE_CLASS, bplPrimitive.GetID()))); } else { AddUmlExtentions("bplPrimitive", BASE_PRIMITIVE, bplPrimitive.GetID()); } }
private void _addPrimitive(BplPrimitive primitive) { if (primitive.IsDelegate) return; if (_primitives.Contains(primitive)) return; _primitives.Add(primitive); if (primitive.IsArray || primitive.IsNullable) { _addPrimitive(primitive.ItemType); } }
private Block _formatPrimitiveSynopsis(BplPrimitive primitive) { var datatype = primitive.UnderlyingType; var synopsis = new TableData(140, "Auto"); Action<string,string> addLine = (name, value) => synopsis.Add(name, value); Action addSpace = () => synopsis.Add(null, null); addLine("Schema:", primitive.Schema.NamespaceName); addLine("Tag Name:", primitive.TagName.LocalName); addSpace(); if (!primitive.IsEnum) { addLine("Xml Type:", BplLanguage.XmlConverters[primitive].XsdDefinition.ToString()); addSpace(); addLine("Json Type:", BplLanguage.JsonConverters[primitive].JsonDefinition.ToString()); addSpace(); addLine("Sql Type:", BplLanguage.SqlConverters[primitive].SqlDefinition.ToString()); if (primitive.UnitSymbol.NotEmpty()) { addSpace(); addLine("Unit:", primitive.UnitSymbol); } if (primitive.NormalizedForm.NotEmpty()) { addSpace(); addLine("Format:", primitive.NormalizedForm); } var operators = _formatDataOperators(datatype); if (operators != null) { addSpace(); synopsis.Add("Operators:", operators); } } return _formatPlainTable(synopsis); }