public static void WriteGetContentsGenericMethod(CodeTypeDeclaration type) { var method = GetGenericResourceListMethod(Strings.GetResourcesMethodName); method.Comments.AddRange(CompilerUtil.CreateDocsComment(Strings.GetContentsGenericCommentSummary, Strings.GetContentsGenericCommentReturns)); method.Statements.Add( new CodeMethodReturnStatement( new CodeSnippetExpression( "global::TypeSafe.TypeSafeUtil.GetResourcesOfType<TResource>(GetContents())"))); type.Members.Add(method); }
public static void CreateGetContentsMethod(CodeTypeDeclaration type) { var method = new CodeMemberMethod { Name = Strings.GetResourcesMethodName, ReturnType = GetIResourceIListType(), Attributes = MemberAttributes.Public | MemberAttributes.Static }; method.Comments.AddRange(CompilerUtil.CreateDocsComment(Strings.GetContentsCommentSummary, Strings.GetContentsCommentReturns)); method.Statements.Add( new CodeMethodReturnStatement(new CodeFieldReferenceExpression(null, CollectionMemberName))); type.Members.Add(method); }
public static void WriteUnloadAllRecursiveMethod(CodeTypeDeclaration type) { var method = new CodeMemberMethod { Name = Strings.UnloadAllRecursiveMethodName }; method.Comments.AddRange(CompilerUtil.CreateDocsComment(Strings.UnloadAllRecursiveCommentSummary)); method.Statements.Add( new CodeMethodInvokeExpression( new CodeTypeReferenceExpression(new CodeTypeReference("TypeSafe.TypeSafeUtil") { Options = CodeTypeReferenceOptions.GlobalReference }), "UnloadAll", new CodeSnippetExpression("GetContentsRecursive()"))); type.Members.Add(method); }
public static void CreateGetContentsRecursiveMethod(CodeTypeDeclaration type, ResourceFolder folder) { var cache = new CodeMemberField(GetIResourceIListType(), RecursiveLookupCacheName) { Attributes = MemberAttributes.Static | MemberAttributes.Private }; type.Members.Add(cache); var method = new CodeMemberMethod { Attributes = MemberAttributes.Static | MemberAttributes.Public, Name = Strings.GetResourcesRecursiveMethodName, ReturnType = GetIResourceIListType() }; method.Comments.AddRange(CompilerUtil.CreateDocsComment(Strings.GetContentsRecursiveCommentSummary, Strings.GetContentsRecursiveCommentReturns)); method.Statements.Add( new CodeConditionStatement( new CodeBinaryOperatorExpression( new CodeFieldReferenceExpression(null, RecursiveLookupCacheName), CodeBinaryOperatorType.IdentityInequality, new CodePrimitiveExpression(null) ), new CodeMethodReturnStatement(new CodeFieldReferenceExpression(null, RecursiveLookupCacheName)))); // Create list method.Statements.Add(new CodeVariableDeclarationStatement(GetIResourceListType(), "tmp", new CodeObjectCreateExpression(GetIResourceListType()))); // Add any resources from this folder method.Statements.Add(new CodeMethodInvokeExpression(new CodeVariableReferenceExpression("tmp"), "AddRange", new CodeMethodInvokeExpression(new CodeMethodReferenceExpression(null, Strings.GetResourcesMethodName)))); // Add any resources from subfolders foreach (var f in folder.Folders) { var name = CompilerUtil.GetSafeName(f.Name, true); // Skip if this folder hasn't been added to the type for some reason if (!CompilerUtil.IsDuplicate(name, type)) { continue; } // Add any resources from this folder method.Statements.Add(new CodeMethodInvokeExpression(new CodeVariableReferenceExpression("tmp"), "AddRange", new CodeMethodInvokeExpression( new CodeMethodReferenceExpression(new CodeSnippetExpression(name), Strings.GetResourcesRecursiveMethodName)))); } method.Statements.Add( new CodeAssignStatement(new CodeFieldReferenceExpression(null, RecursiveLookupCacheName), new CodeVariableReferenceExpression("tmp"))); method.Statements.Add( new CodeMethodReturnStatement(new CodeFieldReferenceExpression(null, RecursiveLookupCacheName))); type.Members.Add(method); }