private void CreatePropertyForField(CodeTypeDeclaration file, EAPAttribute attribute, CodeMemberField att, bool get, bool set) { CodeMemberProperty prop = new CodeMemberProperty(); prop.Attributes = MemberAttributes.Public | MemberAttributes.Final; if (attribute.TypeCode != "") { if (attribute.TypeCode.Equals("Enum") || attribute.TypeCode.Equals("Class")) { prop.Type = new CodeTypeReference(attribute.MeasurementType); } } else { if (attribute.MeasurementType != "") { string dataType = StringManipulationManager.GetSystemType(attribute.MeasurementType); prop.Type = new CodeTypeReference(dataType); } } prop.Name = StringManipulationManager.CreateHungarianNotation(att.Name); if (prop.Name.Equals(file.Name)) { prop.Name = prop.Name + "P"; } if (get) { prop.HasGet = true; prop.GetStatements.Add(new CodeSnippetExpression("return this." + att.Name)); } if (set) { prop.HasSet = true; prop.SetStatements.Add(new CodeSnippetExpression("this." + att.Name + " = value")); } file.Members.Add(prop); }
private CodeCompileUnit CreateClass(EAPModel model, EAPClass classPom, bool flagDb) { CodeCompileUnit unit = new CodeCompileUnit(); //namespace CodeNamespace nameSpace = new CodeNamespace("Default_Namespace"); unit.Namespaces.Add(nameSpace); //namespace imports nameSpace.Imports.Add(new CodeNamespaceImport("System")); CodeTypeDeclaration file = new CodeTypeDeclaration(); file.IsClass = true; file.Name = classPom.Name; file.TypeAttributes = TypeAttributes.Public; file.Attributes = MemberAttributes.Public; if (classPom.Parent != null) { file.BaseTypes.Add(new CodeTypeReference(classPom.Parent)); nameSpace.Imports.Add(new CodeNamespaceImport("Default_Namespace")); } else { //if class doesn't have a parent, //it should extend IDClass as the root of hierarhy - for rdf:ID file.BaseTypes.Add(new CodeTypeReference("IDClass")); nameSpace.Imports.Add(new CodeNamespaceImport("Default_Namespace")); } if (!string.IsNullOrEmpty(classPom.Description)) { file.Comments.Add(new CodeCommentStatement(classPom.Description, true)); } //Generate constructor without param CodeConstructor baseStringConstructorSimple = new CodeConstructor(); baseStringConstructorSimple.Attributes = MemberAttributes.Public; //Gererating constuctor with param CodeConstructor baseStringConstructor = new CodeConstructor(); baseStringConstructor.Attributes = MemberAttributes.Public; baseStringConstructor.BaseConstructorArgs.Add(new CodeVariableReferenceExpression("globalId")); baseStringConstructor.Parameters.Add(new CodeParameterDeclarationExpression("System.Int64", "globalId")); file.Members.Add(baseStringConstructorSimple); file.Members.Add(baseStringConstructor); List <EAPAttribute> attributes = new List <EAPAttribute>(); if (classPom.Attributes.Count > 0) { foreach (EAPAttribute attribut in classPom.Attributes) { CodeMemberField att = null; if (attribut.MeasurementType != "") { if (Enum.IsDefined(typeof(MeasurementType), attribut.MeasurementType.ToUpper()) || attribut.MeasurementType.Contains("List<") || attribut.TypeCode.Equals("Enum") || attribut.TypeCode.Equals("Class")) { if (attribut.Max == "*") { nameSpace.Imports.Add(new CodeNamespaceImport("System.Collections.Generic")); string fieldName = attribut.Name; att = new CodeMemberField(new CodeTypeReference("List", new CodeTypeReference[] { new CodeTypeReference(attribut.MeasurementType.Split('<', '>')[1]) }), fieldName); att.Attributes = MemberAttributes.Private | MemberAttributes.Final; att.InitExpression = new CodeObjectCreateExpression(new CodeTypeReference("List", new CodeTypeReference[] { new CodeTypeReference(attribut.MeasurementType.Split('<', '>')[1]) })); if (!string.IsNullOrEmpty(attribut.Description)) { att.Comments.Add(new CodeCommentStatement(attribut.Description, true)); } file.Members.Add(att); CreatePropertyForField(file, att, true, true); } else { string fieldName = attribut.Name; string type = attribut.MeasurementType; // att = new CodeMemberField(StringManipulationManager.GetSystemType(type), fieldName); if (attribut.TypeCode != null && attribut.TypeCode != "") { if (attribut.TypeCode.Equals("Enum")) { att = new CodeMemberField(attribut.MeasurementType, fieldName); } if (attribut.TypeCode.Equals("Class")) { att = new CodeMemberField(attribut.MeasurementType, fieldName); } } else { att = new CodeMemberField(StringManipulationManager.GetSystemType(type), fieldName); } att.Attributes = MemberAttributes.Private | MemberAttributes.Final; if (!string.IsNullOrEmpty(attribut.Description)) { att.Comments.Add(new CodeCommentStatement(attribut.Description, true)); } if (type.Equals("long") && attribut.IsReference == true) { att.InitExpression = new CodeSnippetExpression("0"); } file.Members.Add(att); //property for the field CreatePropertyForField(file, attribut, att, true, true); } } else { continue; } } } if (IsDbSelected && flagDb == false) { GenerateIDForDb(file, classPom.Name); // generate id if db checbox is selected } if (flagDb) { GenerateEqualsMethod(file, classPom); GenerateHashCodeMethod(file, classPom); GenerateGetProperty(file, classPom); GenerateHasPropertyMethod(file, classPom); GenerateSetPropertyMethod(file, classPom); GenerateIsReferencedProperty(file, classPom); GenerateGetReferencesMethod(file, classPom); GenerateAddreferenceMethod(file, classPom); GenerateRemoveReferencMethod(file, classPom); } } else { if (flagDb) { GenerateEqualsMethod(file, classPom); GenerateHashCodeMethod(file, classPom); GenerateGetProperty(file, classPom); GenerateHasPropertyMethod(file, classPom); GenerateSetPropertyMethod(file, classPom); GenerateGetReferencesMethod(file, classPom); } } nameSpace.Types.Add(file); return(unit); }