Beispiel #1
0
        internal static string CreateDatatypeRef(TypeReference tr, Property p)
        {
            tr = HeuristicEngine.Datatypes.MapDatatype(tr);
            string retVal = tr is TypeParameter && tr.Name == null ? Util.Util.MakeFriendly((tr as TypeParameter).ParameterName) : 
                tr.Class == null ? tr.Name : String.Format("{0}.{1}", tr.Class.ContainerName, Util.Util.PascalCase(tr.Class.Name));
            
            // Domain for a code?
            if (p != null &&
                p.SupplierDomain != null &&
                Datatypes.IsCodeType(tr)
                && !String.IsNullOrEmpty(EnumerationRenderer.WillRender(p.SupplierDomain as Enumeration)) &&
                p.SupplierStrength == Property.CodingStrengthKind.CodedNoExtensions )
            {
                EnumerationRenderer.MarkAsUsed(p.SupplierDomain);

                // Since we are going to reference it, we better ensure that any value we use will have it in the
                // domain
                if (p.FixedValue != null && p.FixedValue.Length > 0 &&
                    (p.SupplierDomain as Enumeration).GetEnumeratedLiterals().Find(o => o.Name == p.FixedValue) == null)
                {
                    Enumeration.EnumerationValue ev = new Enumeration.EnumerationValue();
                    ev.Name = p.FixedValue;
                    ev.Documentation = new Documentation();
                    ev.Documentation.Description = new List<string>() { "Added automatically because a property's fixed value referenced this mnemonic" };
                    (p.SupplierDomain as Enumeration).GetEnumeratedLiterals().Add(ev);
                }

                // Bind if appropriate
                if(!String.IsNullOrEmpty(HeuristicEngine.Datatypes.GetBuiltinVocabulary(p.SupplierDomain.Name)))
                    retVal += "<" + HeuristicEngine.Datatypes.GetBuiltinVocabulary(p.SupplierDomain.Name) + ">";
                else
                    retVal += "<Vocabulary." + Util.Util.MakeFriendly(EnumerationRenderer.WillRender(p.SupplierDomain)) + ">";
            }


            // Generics?
            if (tr.Class != null && tr.Class.TypeParameters != null)
            {
                retVal += "<";
                foreach (var parm in tr.Class.TypeParameters)
                {
                    List<TypeReference> tp = tr.GenericSupplier == null ? null : tr.GenericSupplier.FindAll(o => (o as TypeParameter).ParameterName.Equals(parm.ParameterName));
                    if (tp == null || tp.Count != 1) // nothing is bound to a property reference
                    {
                        var objRef = new TypeReference() { Name = "System.Object" };
                        retVal += CreateDatatypeRef(objRef, p) + ",";
                    }
                    else
                        retVal += CreateDatatypeRef(tp[0], p) + ",";
                }

                retVal = retVal.Substring(0, retVal.Length - 1);
                retVal += ">";
            }
            else if(tr.GenericSupplier != null && tr.GenericSupplier.Count > 0 && !retVal.Contains("<"))
            {
                retVal += "<";
                foreach (TypeReference gr in tr.GenericSupplier)
                    retVal += CreateDatatypeRef(gr, p) + ",";
                retVal = retVal.Substring(0, retVal.Length - 1);
                retVal += ">";
            }

            return retVal;
        }
Beispiel #2
0
        /// <summary>
        /// Get supplier domain reference for the type
        /// </summary>
        private static string GetSupplierDomain(TypeReference tr, Property p, string ownerPackage)
        {
            tr = HeuristicEngine.Datatypes.MapDatatype(tr);
            if(p != null &&
                p.SupplierDomain != null &&
                new List<String>(new String[] { "CS", 
                    "CV", 
                    "CE", 
                    "CR", 
                    "CD" }).Contains(tr.Name)
                && !String.IsNullOrEmpty(EnumerationRenderer.WillRender(p.SupplierDomain)))
            {

                EnumerationRenderer.MarkAsUsed(p.SupplierDomain);

                // Since we are going to reference it, we better ensure that any value we use will have it in the
                // domain
                if (p.FixedValue != null && p.FixedValue.Length > 0 &&
                    p.SupplierDomain.Literals.Find(o => o.Name == p.FixedValue) == null)
                {
                    Enumeration.EnumerationValue ev = new Enumeration.EnumerationValue();
                    ev.Name = p.FixedValue;
                    p.SupplierDomain.Literals.Add(ev);
                }

                return Util.Util.MakeFriendly(EnumerationRenderer.WillRender(p.SupplierDomain));
            }
            return null;
        }