string WriteTryGetTraitMethod(CodeGenerationTypeData typeData) { k_WriteBuilder.Clear(); var type = typeData.Type; WriteSummary($"Get the value for a trait of type {type} in this query"); WriteLine($"public bool TryGetTrait(string traitName, out {type.FullName} value)"); WriteLine("{"); WriteLine($" if(!{GetBackingFieldName(typeData)}.TryGetValue(this, out var typeValues))"); WriteLine(" {"); WriteLine(" value = default;"); WriteLine(" return false;"); WriteLine(" }"); WriteLine(); WriteLine(" if(!typeValues.TryGetValue(traitName, out value))"); WriteLine(" {"); WriteLine(" value = default;"); WriteLine(" return false;"); WriteLine(" }"); WriteLine(); WriteLine(" return true;"); WriteLine("}"); return(DumpBufferContents()); }
string WriteBackingCollection(CodeGenerationTypeData typeData) { WriteSummary($"All Conditions of type {typeData.Type.Name} associated with this context"); WriteLine($"{GetConditionTypeInterface(typeData.Type)}[] {GetBackingFieldName(typeData)};"); return(DumpBufferContents()); }
string WriteGetMatching(CodeGenerationTypeData typeData) { const string getMatching = "componentFilter.GetMatchingComponents"; WriteLine($" {GetBackingFieldName(typeData)} = {getMatching}<{GetConditionTypeInterface(typeData.Type)}>();"); return(DumpBufferContents()); }
string WriteTypeCountMethod(CodeGenerationTypeData typeData) { WriteSummary($"Get the number of conditions of type {typeData.Type.Name} associated with this context"); WriteLine($"public int GetTypeCount(out {GetConditionTypeInterface(typeData.Type)}[] conditions)"); WriteLine("{"); WriteLine(" return !TryGetType(out conditions) ? 0 : conditions.Length;"); WriteLine("}"); return(DumpBufferContents()); }
string WriteGetMatching(CodeGenerationTypeData typeData) { const string getMatching = "componentFilter.GetMatchingComponents"; var backing = GetBackingFieldName(typeData); WriteLine($" {backing} = {getMatching}<{GetRelationTypeInterface(typeData.Type)}>();"); WriteLine($" Count += {backing}.Length;"); return(DumpBufferContents()); }
/* * each type is backed by a static dictionary-of-dictionaries, like * static readonly Dictionary<QueryMatchID, Dictionary<string, T>> {TypeName}Values */ string WriteBackingCollection(CodeGenerationTypeData typeData) { k_WriteBuilder.Clear(); var type = typeData.Type; var concreteType = $"Dictionary<QueryResult, Dictionary<string, {type.FullName}>>"; WriteSummary($"Values for all matched queries' results of type {type.Name}"); WriteLine($"internal static readonly {concreteType} {GetBackingFieldName(typeData)} = "); WriteLine($" new {concreteType}();"); return(DumpBufferContents()); }
string WriteTryGetType(CodeGenerationTypeData typeData) { var type = typeData.Type; var backingField = GetBackingFieldName(typeData); WriteLine($"public bool TryGetType(out {GetConditionTypeInterface(type)}[] conditions)"); WriteLine("{"); WriteLine($" conditions = {backingField};"); WriteLine(" return conditions != null;"); WriteLine("}"); return(DumpBufferContents()); }
string WriteTryGetType(CodeGenerationTypeData data) { k_WriteBuilder.Clear(); var type = data.Type; var backingField = GetBackingFieldName(data); WriteLine($"public bool TryGetType(out {GetRelationTypeInterface(type)}[] relations)"); WriteLine("{"); WriteLine($" relations = {backingField};"); WriteLine(" return relations != null;"); WriteLine("}"); return(DumpBufferContents()); }
static string GetBacking(CodeGenerationTypeData data) { return($"{data.MemberPrefix}Results"); }
static string GetBackingFieldName(CodeGenerationTypeData typeData) { return($"{typeData.MemberPrefix}Values"); }
static string GetChildTraitsType(CodeGenerationTypeData typeData) { return($"List<ChildTraits<{typeData.Type.FullName}>>"); }
static string GetBackingFieldName(CodeGenerationTypeData data) { return($"{data.MemberPrefix}Collections"); }