public virtual void Add(CSharpConstruct construct) { if (construct == this) { throw new InvalidOperationException(); } if (construct is Property property) { if (!Properties.Contains(property)) { Properties.Add(property); } } if (construct is Method method) { if (!Methods.Contains(method)) { Methods.Add(method); } } if (construct is Object @object) { if (!InnerObjects.Contains(@object)) { InnerObjects.Add(@object); } } }
public Type GetByName(string name) { if (name.Equals(Name)) { return(this); } return(InnerObjects.SingleOrDefault(cl => cl.Name.Equals(name))); }
public List <ObjectMDM> GetAllObjects() { if (InnerObjects == null) { return(null); } var resObjs = InnerObjects.ToList(); foreach (var item in InnerObjects) { var innerObjs = item.GetAllObjects(); if (innerObjs != null) { resObjs.AddRange(innerObjs); } } return(resObjs); }
public virtual void Remove(CSharpConstruct construct) { if (construct == this) { throw new InvalidOperationException(); } if (construct is Property property) { Properties.Remove(property); } if (construct is Method method) { Methods.Remove(method); } if (construct is Object @object) { InnerObjects.Remove(@object); } }
public bool Equals(TestModel?other) { if (ReferenceEquals(null, other)) { return(false); } if (ReferenceEquals(this, other)) { return(true); } // ReSharper disable AssignNullToNotNullAttribute return(Id.Equals(other.Id) && Name == other.Name && Numbers.SequenceEqual(other.Numbers) && Strings.SequenceEqual(other.Strings) && InnerObjects.SequenceEqual(other.InnerObjects) && ((Attributes.HasValue && other.Attributes.HasValue && Attributes.Value.IsEquivalentTo(other.Attributes.Value)) || (!Attributes.HasValue && !other.Attributes.HasValue))); // ReSharper restore AssignNullToNotNullAttribute }
/// <summary> /// Определение вложенных объектов /// </summary> /// <param name="level">Уровень вложенности по типу объекта</param> internal void DefineInners(DbSet <Object_cascade> objCascade, ObjectTypeEnum level, ref List <ObjectMDM> levelObjects) { if (ObjectType > level) { return; } if (ObjectType == level) { levelObjects.Add(this); return; } var innersObjDB = objCascade.Where(w => w.Object_id_parent == Id); foreach (var item in innersObjDB) { var innerObj = new ObjectMDM(item, this); InnerObjects.Add(innerObj); innerObj.DefineInners(objCascade, level, ref levelObjects); } }
public override void PreConvert() { //add implicit converter foreach (var io in InnerObjects.ToList().Concat(EnumeratedTypes.ToList())) { new Method(this, "", AccessSpecifier.Public, new ImplicitType(null, Name), true, new List <MethodParameter>() { new MethodParameter(null, io.UnderlyingType, "value") }) { Body = $"{{ return new {Name}(value); }}" }; } new Method(this, Name, AccessSpecifier.Public, null, false, new List <MethodParameter>() { new MethodParameter(null, new Type(this, "object"), "value") }) { Body = $"{{ Value = value; }}" }; Extends.Add(new Type(null, "Enumerated")); }
public override void Write(ICSharpFormatter formatter, bool comment = true) { if (comment) { if (Comment != null) { Comment.Write(formatter); } } PreObjectWrite(formatter); formatter.Write(Definition); WriteObjectConstraint(formatter); formatter.WriteLine(""); formatter.WriteLine("{"); foreach (var m in InnerObjects.Distinct()) { m.Write(formatter, comment); } List <ICSharpSyntax> generatedFields = new List <ICSharpSyntax>(); List <string> generatedNames = new List <string>(); int ix = 1; foreach (var m in Variables) { if (!generatedFields.Any(f => f.Equals(m))) { string originalName = m.Name; string name = m.Name; if (generatedNames.Contains(name)) { //name += ix++; //m.Attributes.Add($"Name(\"{originalName}\")"); //m.Name = name; } m.Write(formatter, comment); generatedNames.Add(name); generatedFields.Add(m); } } ix = 1; foreach (var property in Properties) { if (!generatedFields.Any(f => f.Equals(property))) { string originalName = property.Name; string name = property.Name; if (generatedNames.Contains(name)) { //name += ix++; //property.Attributes.Add($"Name(\"{originalName}\")"); //property.Name = name; } property.Write(formatter, comment); generatedNames.Add(name); generatedFields.Add(property); } } ix = 1; foreach (var m in Methods) { if (!generatedFields.Any(f => f.Equals(m))) { string originalName = m.Name; string name = m.Name; if (generatedNames.Contains(name) && !m.IsConstructor) { //name += ix++; //m.Attributes.Add($"Name(\"{originalName}\")"); //m.Name = name; } m.Write(formatter, comment); generatedNames.Add(name); generatedFields.Add(m); } } WriteObjectFields(formatter, comment); formatter.WriteLine("}"); }