public CodeContextEntityWraperMember(WXMLCodeDomGeneratorSettings settings, EntityDefinition entity) { _settings = settings; m_entity = entity; string entityName = entity.Name; if (entityName.EndsWith("s")) { entityName += "es"; } else if (entityName.EndsWith("y")) { entityName += "ies"; } else { entityName += "s"; } Attributes = MemberAttributes.Public | MemberAttributes.Final; Name = (entity.EntitySpecificNamespace ?? string.Empty) + entityName; var entityTypeReference = new CodeTypeReference(new WXMLCodeDomGeneratorNameHelper(_settings).GetEntityClassName(Entity, true)); Type = new CodeTypeReference("Worm.Linq.QueryWrapperT", entityTypeReference); SetStatements.Clear(); GetStatements.Add( new CodeMethodReturnStatement( new CodeMethodInvokeExpression( new CodeMethodReferenceExpression( new CodeThisReferenceExpression(), "CreateQueryWrapper", entityTypeReference) ) ) ); }
/// <summary> /// Write Source /// </summary> /// <param name="writer"></param> internal override void WriteSource(System.IO.StreamWriter writer, TsGeneratorOptions options, TsWriteInformation info) { //write base stuff base.WriteSource(writer, options.Clone(options.IndentString, false), info); //sec check if (info.ForType != TsElementTypes.Class) { throw new Exception("TsCodeMemberProperty can only be defined for class"); } if (!Types.Any()) { throw new Exception("TsCodeMemberProperty type not defined"); } //prepare source var source = options.GetPreLineIndentString(info.Depth); //add attributres if (Attributes != TsMemberAttributes.None) { source += TsMemberAttributeMappings.TypeMappings[Attributes] + TsDomConstants.ATTRIBUTE_SEPEARATOR; } //if there is no setter and getter this is a bit useless if (!HasSet && !HasGet) { throw new Exception("TsCodeMemberProperty there is no setter and getter for MemberProperty" + Name); } //if we have a getter write getter if (HasGet) { var getSource = source + string.Format(TsDomConstants.GETTER_FORMAT, Name, GetTypeSource()) + TsDomConstants.STATEMENT_BRACKET_BEGIN; //write begin line writer.WriteLine(getSource); //write statemetns GetStatements.ToList().ForEach(el => el.WriteSource(writer, options, info.Clone(info.Depth + 1))); //write end source writer.WriteLine(GetStatementEnd(options, info.Depth)); } //as setter if (HasSet) { var setSource = source + string.Format(TsDomConstants.SETTER_FORMAT, Name, SetParameterName, GetTypeSource()) + TsDomConstants.STATEMENT_BRACKET_BEGIN; //write begin line writer.WriteLine(setSource); //write statemetns SetStatements.ToList().ForEach(el => el.WriteSource(writer, options, info.Clone(info.Depth + 1))); //write end source writer.WriteLine(GetStatementEnd(options, info.Depth)); } }