Exemplo n.º 1
0
        public bool ContainsPropertiesInCompositeType()
        {
            var sample = ComposedProperties.FirstOrDefault(p =>
                                                           p.Type is CompositeType || p.Type is SequenceType && (p.Type as SequenceType).ElementType is CompositeType);

            return(sample != null);
        }
 public bool ContainsDurationProperty()
 {
     Core.Model.Property prop = ComposedProperties.FirstOrDefault(p =>
                                                                  (p.ModelType is PrimaryTypeTS && (p.ModelType as PrimaryTypeTS).KnownPrimaryType == KnownPrimaryType.TimeSpan) ||
                                                                  (p.ModelType is Core.Model.SequenceType && (p.ModelType as Core.Model.SequenceType).ElementType.IsPrimaryType(KnownPrimaryType.TimeSpan)) ||
                                                                  (p.ModelType is Core.Model.DictionaryType && (p.ModelType as Core.Model.DictionaryType).ValueType.IsPrimaryType(KnownPrimaryType.TimeSpan)));
     return(prop != null);
 }
        public bool ContainsPropertiesInSequenceType()
        {
            var sample = ComposedProperties.FirstOrDefault(p =>
                                                           p.ModelType is Core.Model.SequenceType ||
                                                           p.ModelType is Core.Model.DictionaryType && (p.ModelType as Core.Model.DictionaryType).ValueType is Core.Model.SequenceType);

            return(sample != null);
        }
Exemplo n.º 4
0
        public bool ContainsDurationProperty()
        {
            Property prop = ComposedProperties.FirstOrDefault(p =>
                                                              (p.Type is PrimaryType && (p.Type as PrimaryType) == PrimaryType.TimeSpan) ||
                                                              (p.Type is SequenceType && (p.Type as SequenceType).ElementType == PrimaryType.TimeSpan) ||
                                                              (p.Type is DictionaryType && (p.Type as DictionaryType).ValueType == PrimaryType.TimeSpan));

            return(prop != null);
        }
Exemplo n.º 5
0
        public virtual string SuperParameterDeclaration()
        {
            List <string> combinedDeclarations = new List <string>();

            foreach (var property in ComposedProperties.Except(Properties).Except(ReadOnlyAttributes).Where(each => !each.IsPolymorphicDiscriminator))
            {
                combinedDeclarations.Add(string.Format(CultureInfo.InvariantCulture, "{0}={0}", property.Name));
            }
            return(string.Join(", ", combinedDeclarations));
        }
Exemplo n.º 6
0
        /// <remarks>
        /// Used in Python 3, Python 2 doesn't have typehing * syntax
        /// </remarks>
        public virtual string ModelParameterDeclaration()
        {
            List <string> declarations         = new List <string>();
            List <string> requiredDeclarations = new List <string>();
            List <string> combinedDeclarations = new List <string>();

            foreach (var property in ComposedProperties.Except(ReadOnlyAttributes).Where(each => !each.IsPolymorphicDiscriminator))
            {
                if (this.BaseIsPolymorphic)
                {
                    if (property.Name == this.BasePolymorphicDiscriminator)
                    {
                        continue;
                    }
                }

                string typeHint = ClientModelExtensions.GetPythonTypeHint(property.ModelType) ?? "";
                if (typeHint != "")
                {
                    typeHint = ": " + typeHint;
                }
                if (property.IsRequired && property.DefaultValue.RawValue.IsNullOrEmpty())
                {
                    requiredDeclarations.Add($"{property.Name}{typeHint}");
                }
                else
                {
                    declarations.Add($"{property.Name}{typeHint}={property.DefaultValue}");
                }
            }

            if (requiredDeclarations.Any())
            {
                combinedDeclarations.Add(string.Join(", ", requiredDeclarations));
            }
            if (declarations.Any())
            {
                combinedDeclarations.Add(string.Join(", ", declarations));
            }

            if (!combinedDeclarations.Any())
            {
                return(", **kwargs");
            }
            return(", *, " + string.Join(", ", combinedDeclarations) + ", **kwargs");
        }
Exemplo n.º 7
0
        public virtual string SuperParameterDeclaration()
        {
            List <string> combinedDeclarations = new List <string>();

            foreach (var property in ComposedProperties.Except(Properties))
            {
                if (this.IsPolymorphic)
                {
                    if (property.Name == this.BasePolymorphicDiscriminator)
                    {
                        continue;
                    }
                }

                combinedDeclarations.Add(string.Format(CultureInfo.InvariantCulture, "{0}={0}", property.Name));
            }
            return(string.Join(", ", combinedDeclarations));
        }
Exemplo n.º 8
0
        /// <summary>
        /// Determines whether the specified model type is structurally equal to this object.
        /// </summary>
        /// <param name="other">The object to compare with this object.</param>
        /// <returns>true if the specified object is functionally equal to this object; otherwise, false.</returns>
        public override bool StructurallyEquals(IModelType other)
        {
            if (ReferenceEquals(other as CompositeType, null))
            {
                return(false);
            }
            if (ReferenceEquals(other as CompositeType, this))
            {
                return(true);
            }

            return(base.StructurallyEquals(other) &&
                   ComposedProperties.SequenceEqual((other as CompositeType).ComposedProperties,
                                                    new Utilities.EqualityComparer <Property>((a, b) =>
                                                                                              a.Name == b.Name &&
                                                                                              a.ModelType.StructurallyEquals(b.ModelType) &&
                                                                                              a.IsReadOnly == b.IsReadOnly &&
                                                                                              a.IsConstant == b.IsConstant &&
                                                                                              a.IsRequired == b.IsRequired)));
        }
Exemplo n.º 9
0
        public virtual string MethodParameterDeclaration()
        {
            List <string> declarations         = new List <string>();
            List <string> requiredDeclarations = new List <string>();
            List <string> combinedDeclarations = new List <string>();

            foreach (var property in ComposedProperties.Except(ReadOnlyAttributes).Where(each => !each.IsPolymorphicDiscriminator))
            {
                if (this.BaseIsPolymorphic)
                {
                    if (property.Name == this.BasePolymorphicDiscriminator)
                    {
                        continue;
                    }
                }

                if (property.IsRequired && property.DefaultValue.RawValue.IsNullOrEmpty())
                {
                    requiredDeclarations.Add(property.Name);
                }
                else
                {
                    declarations.Add($"{property.Name}={property.DefaultValue}");
                }
            }

            if (requiredDeclarations.Any())
            {
                combinedDeclarations.Add(string.Join(", ", requiredDeclarations));
            }
            if (declarations.Any())
            {
                combinedDeclarations.Add(string.Join(", ", declarations));
            }

            if (!combinedDeclarations.Any())
            {
                return(string.Empty);
            }
            return(", " + string.Join(", ", combinedDeclarations));
        }
Exemplo n.º 10
0
        public virtual string MethodParameterDeclaration()
        {
            List <string> declarations         = new List <string>();
            List <string> requiredDeclarations = new List <string>();
            List <string> combinedDeclarations = new List <string>();

            foreach (var property in ComposedProperties.Except(ReadOnlyAttributes))
            {
                if (this.IsPolymorphic)
                {
                    if (property.Name == this.BasePolymorphicDiscriminator)
                    {
                        continue;
                    }
                }

                if (property.IsRequired && property.DefaultValue == PythonConstants.None)
                {
                    requiredDeclarations.Add(property.Name);
                }
                else
                {
                    declarations.Add(string.Format(CultureInfo.InvariantCulture, "{0}={1}", property.Name, property.DefaultValue));
                }
            }

            if (requiredDeclarations.Any())
            {
                combinedDeclarations.Add(string.Join(", ", requiredDeclarations));
            }
            if (declarations.Any())
            {
                combinedDeclarations.Add(string.Join(", ", declarations));
            }

            if (!combinedDeclarations.Any())
            {
                return(string.Empty);
            }
            return(", " + string.Join(", ", combinedDeclarations));
        }
        public bool ContainsPropertiesInCompositeType()
        {
            var sample = ComposedProperties.FirstOrDefault(p => ContainsCompositeType(p.ModelType));

            return(sample != null);
        }
Exemplo n.º 12
0
        public bool ContainsPropertiesInSequenceType()
        {
            var sample = ComposedProperties.FirstOrDefault(p => p.Type is SequenceType);

            return(sample != null);
        }