KAOSTools.Core.EntityAttribute GetOrCreateAttribute(ParsedAttributeReferenceExpression pref, Entity entity, GivenType type) { if (entity != null) { if (pref.AttributeSignature is NameExpression) { var attribute = entity.Attributes().SingleOrDefault(x => x.Name == pref.AttributeSignature.Value); if (attribute == null) { attribute = new KAOSTools.Core.EntityAttribute(model) { Name = pref.AttributeSignature.Value, TypeIdentifier = type?.Identifier, Implicit = true }; attribute.SetEntity(entity); model.Add(attribute); } else { } return(attribute); } else if (pref.AttributeSignature is IdentifierExpression) { var attribute = entity.model.Attributes().SingleOrDefault(x => x.Identifier == pref.AttributeSignature.Value && x.EntityIdentifier == entity.Identifier); if (attribute == null) { attribute = new KAOSTools.Core.EntityAttribute(model) { Identifier = pref.AttributeSignature.Value, TypeIdentifier = type?.Identifier, Implicit = true }; attribute.SetEntity(entity); model.Add(attribute); } return(attribute); } else { throw new NotImplementedException(pref.AttributeSignature.GetType() + " is not yet supported"); } } else { throw new Exception(string.Format("Entity '{0}' not found", entity.Identifier)); } }
KAOSTools.MetaModel.Attribute GetOrCreateAttribute(ParsedAttributeReferenceExpression pref, KAOSTools.MetaModel.Entity entity) { Console.WriteLine (">> " + pref.AttributeSignature.Value + " <<"); if (entity != null) { if (pref.AttributeSignature is NameExpression) { var attribute = entity.Attributes().SingleOrDefault (x => x.Name == pref.AttributeSignature.Value); if (attribute == null) { attribute = new KAOSTools.MetaModel.Attribute (model) { Name = pref.AttributeSignature.Value, Implicit = true } ; attribute.SetEntity (entity); model.Add (attribute); Declarations.Add (attribute, new List<Declaration> () { new Declaration (pref.Line, pref.Col, pref.Filename, relativePath, DeclarationType.Reference) }); } else { Declarations[attribute].Add ( new Declaration (pref.Line, pref.Col, pref.Filename, relativePath, DeclarationType.Reference) ); } return attribute; } else if (pref.AttributeSignature is IdentifierExpression) { var attribute = entity.model.Attributes().SingleOrDefault (x => x.Identifier == entity.Identifier + "." +pref.AttributeSignature.Value); if (attribute == null) { attribute = new KAOSTools.MetaModel.Attribute (model) { Identifier = entity.Identifier + "." + pref.AttributeSignature.Value, Implicit = true } ; attribute.SetEntity (entity); model.Add (attribute); Declarations.Add (attribute, new List<Declaration> () { new Declaration (pref.Line, pref.Col, pref.Filename, relativePath, DeclarationType.Reference) }); } else { Declarations[attribute].Add ( new Declaration (pref.Line, pref.Col, pref.Filename, relativePath, DeclarationType.Reference) ); } return attribute; } else throw new NotImplementedException (pref.AttributeSignature.GetType() + " is not yet supported"); } else { throw new Exception (string.Format("Entity '{0}' not found", pref.Variable)); } }