Beispiel #1
0
        /// <summary>
        /// Initializes a new instance of the ModelTemplateModel class.
        /// </summary>
        /// <param name="source">The object to create model from.</param>
        /// <param name="serviceClient">The service client.</param>
        public ModelTemplateModel(CompositeType source, ServiceClient serviceClient)
        {
            this.LoadFrom(source);
            PropertyTemplateModels = new List<PropertyTemplateModel>();
            source.Properties.ForEach(p => PropertyTemplateModels.Add(new PropertyTemplateModel(p)));

            if (source.BaseModelType != null)
            {
                parent = new ModelTemplateModel(source.BaseModelType, serviceClient);
            }
        }
        /// <summary>
        /// Initializes a new instance of the ModelTemplateModel class.
        /// </summary>
        /// <param name="source">The object to create model from.</param>
        /// <param name="allTypes">The list of all model types; Used to implement polymorphism.</param>
        public ModelTemplateModel(CompositeType source, ISet<CompositeType> allTypes)
        {
            this.LoadFrom(source);
            PropertyTemplateModels = new List<PropertyTemplateModel>();
            source.Properties.ForEach(p => PropertyTemplateModels.Add(new PropertyTemplateModel(p)));

            if (!string.IsNullOrEmpty(source.PolymorphicDiscriminator))
            {
                if (!source.Properties.Any(p => p.Name == source.PolymorphicDiscriminator))
                {
                    var polymorphicProperty = new Property
                    {
                        IsRequired = true,
                        Name = source.PolymorphicDiscriminator,
                        SerializedName = source.PolymorphicDiscriminator,
                        Documentation = "Polymorhpic Discriminator",
                        Type = new PrimaryType(KnownPrimaryType.String)
                    };
                    source.Properties.Add(polymorphicProperty);
                }
            }

            if (source.BaseModelType != null)
            {
                this.parent = new ModelTemplateModel(source.BaseModelType, allTypes);
            }

            this.allTypes = allTypes;
        }
        /// <summary>
        /// Initializes a new instance of the ModelTemplateModel class.
        /// </summary>
        /// <param name="source">The object to create model from.</param>
        /// <param name="allTypes">The list of all model types; Used to implement polymorphism.</param>
        public ModelTemplateModel(CompositeType source, ISet<CompositeType> allTypes)
        {
            this.LoadFrom(source);
            PropertyTemplateModels = new List<PropertyTemplateModel>();
            source.Properties.ForEach(p => PropertyTemplateModels.Add(new PropertyTemplateModel(p)));

            if (source.BaseModelType != null)
            {
                this.parent = new ModelTemplateModel(source.BaseModelType, allTypes);
            }

            this.allTypes = allTypes;
        }