Ejemplo n.º 1
0
        public static List <String> MapInterfaces(Class c, string ownerNs)
        {
            List <String> retVal = new List <string>();

            // Find which interfaces this class implements
            foreach (var iface in s_heuristicData.Interfaces)
            {
                bool        matches        = true;
                Enumeration supplierDomain = null;
                foreach (var prop in iface.Properties)
                {
                    Property p = c.Content.Find(o => (o is Property) && (o as Property).Type.Name != null &&
                                                (o as Property).Type.Name.ToLower() + "." + o.Name.ToLower() == prop.DataType.ToLower() + "." + prop.Name.ToLower() &&
                                                (o.MaxOccurs == "1" || o.MaxOccurs != "1" && prop.Name.StartsWith("LIST"))) as Property;
                    matches &= p != null;
                    if (matches)
                    {
                        supplierDomain = p.SupplierDomain;
                    }
                }

                // Determine if match was found
                if (matches)
                {
                    if (!String.IsNullOrEmpty(iface.GenericParameter))
                    {
                        string rv = iface.Name;
                        if (supplierDomain != null &&
                            !String.IsNullOrEmpty(EnumerationRenderer.WillRender(supplierDomain)))
                        {
                            if (retVal.Contains(rv))
                            {
                                retVal.Remove(rv);
                            }

                            rv += String.Format("<{1}>", ownerNs, EnumerationRenderer.WillRender(supplierDomain));
                            retVal.Add(rv);
                        }
                    }
                    else
                    {
                        retVal.Add(iface.Name);
                    }
                }
            }

            return(retVal);
        }
Ejemplo n.º 2
0
        public static List <String> MapInterfaces(Class c)
        {
            List <String> retVal = new List <string>();

            // Find which interfaces this class implements
            foreach (KeyValuePair <Type, List <String> > kv in interfaces)
            {
                bool        matches        = true;
                Enumeration supplierDomain = null;
                foreach (String s in kv.Value)
                {
                    Property p = c.Content.Find(o => (o is Property) &&
                                                ((o as Property).Type.Name != null && (o as Property).Type.Name.ToLower() + "." + o.Name.ToLower() == s.ToLower()) &&
                                                (o.MaxOccurs == "1" || o.MaxOccurs != "1" && s.StartsWith("LIST"))) as Property;
                    matches &= p != null;
                    if (matches && p.SupplierStrength == Property.CodingStrengthKind.CodedNoExtensions)
                    {
                        supplierDomain = p.SupplierDomain;
                    }
                }

                // Determine if match was found
                if (matches)
                {
                    if (kv.Key.FullName.Contains("`"))
                    {
                        string rv = kv.Key.FullName.Substring(0, kv.Key.FullName.IndexOf("`"));
                        if (supplierDomain != null &&
                            !String.IsNullOrEmpty((EnumerationRenderer.WillRender(supplierDomain))))
                        {
                            if (retVal.Contains(rv))
                            {
                                retVal.Remove(rv);
                            }

                            rv += "<" + EnumerationRenderer.WillRender(supplierDomain) + ">";
                            retVal.Add(rv);
                        }
                    }
                    else
                    {
                        retVal.Add(kv.Key.FullName);
                    }
                }
            }

            return(retVal);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Get overridden setters
        /// </summary>
        public static SetterOverrideData[] GetOverrideSetters(TypeReference tr, Property p, string ownerPackage)
        {
            // Not a datatype so we won't need overrides
            if (tr.Class != null)
            {
                return(new SetterOverrideData[0]);
            }

            // Get all the setter overrides
            var dataType = s_heuristicData.Datatypes.Find(o => o.MifDatatype == tr.Name);

            // Sanity check
            if (dataType == null || dataType.SetterOverride.Count == 0)
            {
                return(new SetterOverrideData[0]);
            }

            // Set generic paramaters
            Dictionary <String, String> bind = new Dictionary <string, string>();
            string fillParameter             = dataType.TemplateParameter;

            if (!String.IsNullOrEmpty(dataType.TemplateParameter))
            {
                int i = 0;
                foreach (string s in dataType.TemplateParameter.Split(','))
                {
                    TypeReference bindTypeRef = null;
                    if (tr.GenericSupplier != null) // Generic Supplier
                    {
                        bindTypeRef = tr.GenericSupplier.Find(o => o is TypeParameter && (o as TypeParameter).ParameterName == s);
                        if (bindTypeRef == null)
                        {
                            bindTypeRef = tr.GenericSupplier[i++];
                        }
                    }
                    else if (p != null && p.SupplierDomain != null && !String.IsNullOrEmpty(EnumerationRenderer.WillRender(p.SupplierDomain)))
                    {
                        string vocabName     = Util.Util.MakeFriendly(EnumerationRenderer.WillRender(p.SupplierDomain));
                        string containerName = p.Container is Choice ? (p.Container as Choice).Container.Name : p.Container.Name;
                        if (vocabName.Equals(containerName))
                        {
                            vocabName = String.Format("{0}.vocabulary.{1}", ownerPackage, vocabName);
                        }
                        bindTypeRef = new TypeReference()
                        {
                            Name = String.Format("{0}", vocabName)
                        };
                    }
                    else
                    {
                        bindTypeRef = new TypeReference()
                        {
                            Name = dataType.DefaultBind
                        }
                    };

                    // Add Binding
                    bind.Add(s, ClassRenderer.CreateDatatypeRef(bindTypeRef ?? new TypeReference()
                    {
                        Name = null
                    }, null, ownerPackage));
                    fillParameter = fillParameter.Replace(s, bind[s]);
                }
            }

            // Create setter override and return
            List <SetterOverrideData> overrides = new List <SetterOverrideData>(dataType.SetterOverride.Count);

            foreach (var sod in dataType.SetterOverride)
            {
                // Correct parameters
                SetterOverrideData templatedSod = new SetterOverrideData();
                templatedSod.Parameters = new List <PropertyInfoData>();
                foreach (var parameterData in sod.Parameters)
                {
                    string dt = String.Empty;
                    if (!bind.TryGetValue(parameterData.DataType, out dt))
                    {
                        dt = parameterData.DataType;
                    }


                    templatedSod.Parameters.Add(new PropertyInfoData()
                    {
                        Name = parameterData.Name, DataType = dt.Replace(string.Format("<{0}>", dataType.TemplateParameter), String.Format("<{0}>", fillParameter))
                    });
                }

                // Correct Body
                templatedSod.Throws        = new List <ThrowsData>(sod.Throws);
                templatedSod.SetterText    = sod.SetterText.Replace(string.Format("<{0}>", dataType.TemplateParameter), String.Format("<{0}>", fillParameter));
                templatedSod.ValueInstance = sod.ValueInstance;
                overrides.Add(templatedSod);
            }

            return(overrides.ToArray());
        }