Ejemplo n.º 1
0
      /// <summary>Loads meta enum data from XML.</summary>
      public static MetaEnum LoadFromXml(XElement xml) {
         try {
            MetaEnum metaEnum = new MetaEnum();
            metaEnum.Name = xml.HasAttribute("name") ? xml.Attribute("name").Value : "";
            metaEnum.CanonicName = xml.HasAttribute("canonicName") ? xml.Attribute("canonicName").Value : "";
            metaEnum.Namespace = xml.HasAttribute("namespace") ? xml.Attribute("namespace").Value : "";
            metaEnum.IsFlags = xml.HasAttribute("isFlags") ? (bool)xml.Attribute("isFlags") : false;
            metaEnum.BaseType = xml.HasAttribute("baseType") ? xml.Attribute("baseType").Value : "";

            // Load Enum Values
            XElement xValues = xml.Element("EnumValues");
            if (xValues != null) {
               foreach (XElement xValue in xValues.Elements("EnumValue")) {
                  string name = xValue.HasAttribute("name") ? xValue.Attribute("name").Value : "";
                  string valu = xValue.HasAttribute("value") ? xValue.Attribute("value").Value : "";
                  string desc = xValue.HasAttribute("description") ? xValue.Attribute("description").Value : "";
                  MetaEnumValue mev = new MetaEnumValue(name, valu, desc);
                  metaEnum.EnumValues.Add(mev);
               }
            }
            return metaEnum;
         } catch (Exception) {
            return null;
         }
      }
Ejemplo n.º 2
0
 /// <summary>Links the primitive enum type to the package.</summary>
 /// <param name="bplPrimitive">The BPL primitive.</param>
 private void linkEnum(BplPrimitive bplPrimitive) {
    MetaEnum metaEnum = new MetaEnum(bplPrimitive);
    MetaPackage mPackage = this.metaModel.GetPackageByName(metaEnum.Namespace);
    if (mPackage == null) {
       throw new Exception(string.Format("Package {0} was not found in the model to link enum: {1}", metaEnum.Namespace, metaEnum.CanonicName));
    } else {
       mPackage.Enums.Add(metaEnum);
    }
 }
Ejemplo n.º 3
0
      /// <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);
                  }
               }
            }
         }
         /*****************************/
      }
Ejemplo n.º 4
0
 /// <summary>Edit meta class in the editor panel.</summary>
 private void EditMetaEnum(MetaEnum mEnum) {
    MetaEnumEditorControl ctrl = new MetaEnumEditorControl();
    ObjectPanel.Children.Add(ctrl);
    ctrl.DataContext = mEnum;
 }      
Ejemplo n.º 5
0
      /// <summary>Generate enum file.</summary>
      private void generateEnumFile(MetaEnum metaEnum, string templateName, string folder, string filePattern) {
         this.notifyAction("Generating enum {0} ...", metaEnum.Name);

         // Verify that enum template exists
         StringTemplate template = this.stGroup.GetInstanceOf(templateName);
         if (template == null) return;

         // Generate enum related source files
         string targetFolder = verifyDirectory(folder, metaEnum.Namespace);
         template.SetAttribute("BplEnum", metaEnum);

         string targetFile = this.ResolveFileName(metaEnum, filePattern);
         string targetPath = Path.Combine(targetFolder, targetFile);
         using (StreamWriter outfile = new StreamWriter(targetPath)) {
            outfile.Write(template.ToString());
         }
      }