logo of C#Refactoring on the GPT Store

C#Refactoring on the GPT Store

Use C#Refactoring on ChatGPT Use C#Refactoring on 302.AI

GPT Description

C#代码重构专家AI助手,专注于C#编程与代码重构的开发者,负责审查和改进代码,以增强其可读性、可测试性、可扩展性和可维护性。

GPT Prompt Starters

  • Open/Closed Principle (OCP)示例代码: ```abstract class AdapterBase { protected string Name; public string GetName() { return Name; } } class AjaxAdapter : AdapterBase { public AjaxAdapter() { Name = "ajaxAdapter"; } } class NodeAdapter : AdapterBase { public NodeAdapter() { Name = "nodeAdapter"; } } class HttpRequester : AdapterBase { private readonly AdapterBase Adapter; public HttpRequester(AdapterBase adapter) { Adapter = adapter; } public bool Fetch(string url) { var adapterName = Adapter.GetName(); if (adapterName == "ajaxAdapter") { return MakeAjaxCall(url); } else if (adapterName == "httpNodeAdapter") { return MakeHttpCall(url); } } private bool MakeAjaxCall(string url) { // request and return promise } private bool MakeHttpCall(string url) { // request and return promise } }```
  • 重构方法GetRanks中的SQL Server的语句,提高可读性和性能,输出优化的建议和问题,输出优化后的代码 ``` /// <summary> /// Gets the ranks. /// </summary> /// <param name="query">The query.</param> /// <param name="activity">The activity.</param> /// <returns>List&lt;NMGTravelScoreRankInfo&gt;.</returns> public List<NMGTravelScoreRankInfo> GetRanks(TravelScoreRankQuery query, NMGTravelRule activity) { DateTime startTime, endTime; (startTime, endTime) = activity.GetActivityTime(); string costFlowTableName = GetMargeTableName<VipCostFlow>(query.CustId); string vipTableName = GetMargeTableName<VipInfo>(query.CustId); if (string.IsNullOrWhiteSpace(query.AreaName) || query.AreaName == "all") { return GetSumRanks(query,activity); } string sql = string.Format(@" with T1 as ( --汇总消费总金额+卡号 select CardNo,sum(ReduceAmt) as Score from " + costFlowTableName + @" where CustId=@CustId and OperDate>@StartTime and OperDate<@EndTime and BranchNo in (select BranchNo from BranchInfo where CustID=@CustId and City in ({0}) ) group by CardNo ), T2 as ( --合并用户所属省份 select T1.*,UserArea.Province from T1 left join ( SELECT tmpTable.CardNo,tmpTable.Province,tmpTable.RowNum FROM ( SELECT cf.*,ROW_NUMBER() OVER( PARTITION BY cf.CardNo ORDER BY cf.OperDate) AS RowNum,bi.City as Province FROM " + costFlowTableName + @" cf INNER JOIN BranchInfo bi ON bi.CustId=cf.CustID AND bi.BranchNo = cf.BranchNo WHERE cf.CustId=@CustId and cf.OperDate>@StartTime and cf.BranchNo in (select BranchNo from BranchInfo where CustID=@CustId and City in ({0}) ) ) AS tmpTable WHERE tmpTable.RowNum=1 ) as UserArea on T1.CardNo=UserArea.CardNo ), T22 as ( --汇总二维码积分 select isnull(T2.CardNo,sumTable.CardNo) as CardNo,(isnull(T2.Score,0)+isnull(sumTable.TravelScore,0)) as Score,T2.Province from T2 full outer join NMGTravelScoreQRCodeSum as sumTable on T2.CardNo=sumTable.CardNo and sumTable.CustId=@CustId AND sumTable.ActivityId=@ActivityId ), T3 as ( --获取 手机号信息 select T22.*,vi.Mobile from T22 left join " + vipTableName + @" as vi on vi.CardNo=T22.CardNo and vi.CustID=@CustId ), T4 as ( select row_number() over (order by Score desc) as Rank,T3.* from T3 where T3.Province ='{1}' ) select top {2} Rank,CardNo,Mobile,Score,Province from T4 where T4.Score>0 order by Rank ", activity.ActArea, query.AreaName, activity.TopRankSize); var param = new { CustId = query.CustId, StartTime = startTime, EndTime = endTime, ActivityId = activity.Id }; return DBDataSourceHelper.ExecuteReaderReturnListT<NMGTravelScoreRankInfo>( Conn_Catering, sql, param); } ```
  • 单一职责原则 Single Responsibility Principle(SRP)示例代码: ```csharp class UserSettings { private User User; public UserSettings(User user) { User = user; } public void ChangeSettings(Settings settings) { if (verifyCredentials()) { // ... } } private bool VerifyCredentials() { // ... } } ```
  • 深入分析代码业务逻辑,为了提高代码的可读性、可维护性和健壮性,根据Martin Fowler的重构建议和.NET/.NET Core的Clean Code原则对以下的代码进行一系列的优化: 1. 方法分离:将不同的职责操作提取到单独的方法中,以提高代码的可读性和可维护性。 2. 避免过度拆分方法:在方法分离的过程中,注意避免过度拆分,以保持代码的简洁性。 3. 使用简洁更具描述性的变量名:使变量名更加直观,符合业务逻辑。 4. 避免重复代码:提取公共逻辑以减少代码重复。 5. 增加XML格式的中文文档注释:为重构后的代码添加详细的XML注释。 ```csharp /// <summary> /// 验券并返回券对应的优惠金额 /// </summary> /// <param name="orderInput">The order input.</param> /// <param name="tickets">代金券集合</param> /// <param name="orderAmount">订单应付金额</param> /// <param name="discountSetting">满减满折活动设置</param> /// <param name="discountAmount">满减满折活动优惠金额</param> /// <param name="isReconfiguration">是否是新结算页面</param> /// <returns></returns> private static KmmResult<Dictionary<string, decimal>> CheckTicketsByOrder(OrderInput orderInput, List<TicketInfo> tickets, decimal orderAmount, DiscountSetting discountSetting, decimal discountAmount, bool isReconfiguration = false) { if (orderInput.Detail.IsAny()) { //给每个菜赋值点单号,方便回写代金券每个菜折扣了多少钱 for (int index = 0; index < orderInput.Detail.Count; index++) { orderInput.Detail[index].FoodBill = index.ToString(); } } KmmResult<Dictionary<string, decimal>> kmmResult = new KmmResult<Dictionary<string, decimal>>(); Dictionary<string, decimal> couponDiscountMapping = new Dictionary<string, decimal>(); //过滤套餐子项和使用菜品券 IEnumerable<FoodOrderDetail> foodOrderDetails = orderInput.Detail.FindAll(a => a.IsMeal != FoodTypeConstant.PackageSide && (a.MadeRealPrice + a.RealPrice) > 0); if (foodOrderDetails.IsEmpty()) { return kmmResult.ErrorMsg("没有可使用代金券的菜品"); } List<MeituanCoupon> meituanCoupons = orderInput.MeituanCoupons; MeituanCouponRequest meituanCouponRequest = orderInput.MeituanCouponRequest; List<Basic.Data.Ticket.FoodItem> foods = null; foreach (var ticketInfo in tickets) { if (discountAmount <= 0) { foods = foodOrderDetails.Select(item => GetTicketFoodItem(orderInput, item, null)).ToList(); } else { if (discountSetting == null || discountSetting.CouponNoList.IsEmpty()) { SysLogHelper.Error(nameof(CheckTicketsByOrder), "折扣和立减的优惠活动设置有误", strAddition: $"折扣和立减的优惠活动设置:{discountSetting?.ToString()}"); return kmmResult.Error(KmHttpError.SubmitOrderError, "折扣和立减的优惠活动设置有误"); } foods = new List<Basic.Data.Ticket.FoodItem>(); foreach (var detail in foodOrderDetails) { var foodItem = GetTicketFoodItem(orderInput, detail, discountSetting); foodItem.TotalAmountAfterDiscount = foodItem.TotalAmount; foods.Add(foodItem); } decimal couponOrderAmount = foods.Where(a => a.HasCoupon())?.Sum(a => a.TotalAmount) ?? 0M; if (couponOrderAmount <= 0) { return kmmResult.ErrorMsg("没有可使用代金券的菜品"); } } if (couponLogic.IsMeituanCoupon(ticketInfo.TicketNo)) { if (meituanCoupons.IsEmpty() || orderInput.MeituanCouponRequest==null) { return kmmResult.ErrorMsg("请重新刷新页面下单"); } string code = GetCouponCode(ticketInfo.TicketNo); if (code.IsEmpty()) { return kmmResult.ErrorMsg("请重新刷新页面下单"); } var coupon = meituanCoupons.FirstOrDefault(x => x.Code == code); if (coupon == null||coupon.TicketCls==null) { return kmmResult.ErrorMsg("请重新刷新页面下单"); } decimal tmpOrderAmount = orderAmount; decimal tmpDeliveryFee = orderInput.Master.DeliveryFee; if (isReconfiguration) { tmpOrderAmount -= tmpDeliveryFee; tmpDeliveryFee = 0.0M; } CheckCouponDto couponDto = new CheckCouponDto(tmpOrderAmount,0.0M,0.0M, foods, coupon, tmpDeliveryFee); var validateResult= couponLogic.ValidateOrderCoupon(couponDto); if (!validateResult.IsOk) { return kmmResult.Error(validateResult.code, validateResult.msg); } if (validateResult.data.DiscountFoods.IsAny()) { ApplyCouponOrderDetails(orderInput, ticketInfo.TicketType, validateResult.data.DiscountFoods); } decimal couponDiscountAmount=validateResult.data.DiscountAmount; couponDiscountMapping.Add(ticketInfo.TicketNo, couponDiscountAmount); orderAmount = orderAmount - couponDiscountAmount; //消费金额需要减去已核销金额 } else { var ticketValidationResult = ValidateOrderTicket(orderInput, ticketInfo, orderAmount, foods, isReconfiguration); if (!ticketValidationResult.IsOk) { return kmmResult.Error(ticketValidationResult.Code, ticketValidationResult.Message?.ToString()); } var ticketFoods = JsonHelper.JsonConvertDeserialize<List<Basic.Data.Ticket.FoodItem>>(ticketValidationResult.ApplyItems); if (ticketFoods.IsAny()) { ApplyCouponOrderDetails(orderInput, ticketInfo.TicketType, ticketFoods); } couponDiscountMapping.Add(ticketInfo.TicketNo, ticketValidationResult.CostAmount.ToRMB()); orderAmount = orderAmount - ticketValidationResult.CostAmount.ToRMB(); //消费金额需要减去已核销金额 huangzhc 2022-11-15 } } return kmmResult.Success(couponDiscountMapping); } ```
  • 最新知识库:深入分析“重构改善既有代码的设计(第2版)”,列出其中的所有重构原则,并用简单易懂的语言详细解释每个原则。为了帮助用户更好地理解,请提供以下内容: 1. 重构原则的完整列表: - 逐条列出书中提到的所有重构原则。 - 用通俗易懂的方式解释每个原则,强调其在代码改进中的重要性。 2.C#电子商务系统示例: - 每个原则后附带C#电子商务系统中的实际应用示例,展示该原则在实际项目中的使用场景。 - 提供重构前的代码示例,详细指出其中的问题或缺点。 - 提供重构后的代码示例,展示如何应用该原则来改进代码。 3.代码对比: - 用代码片段展示重构前后的对比,清晰说明改进后的代码如何提高了可读性、可维护性或性能。 - 解释改进后的具体优势,如减少重复代码、提高逻辑清晰度等。 请确保所有示例都基于C#语言,并与电子商务系统的实际功能(如订单处理、用户管理、库存更新等)相关,帮助开发者在实践中理解和应用这些重构原则。
  • 最新知识库:请深入分析“编程的原则:改善代码质量的101个方法”,列出其中的10个最重要改善代码的方法,并用简单易懂的语言详细解释每个方法。为了帮助用户更好地理解,请提供以下内容: ``` 1. 改善代码的方法: - 逐条列出书中提到的改善代码的方法。 - 用通俗易懂的方式解释每个方法,强调其在代码改进中的重要性。 2.C#电子商务系统示例: - 每个原则后附带C#电子商务系统中的实际应用示例,展示该原则在实际项目中的使用场景。 - 提供改善前的代码示例,详细指出其中的问题或缺点。 - 提供改善后的代码示例,展示如何应用该方法来改进代码。 3.代码对比: - 用代码片段展示改善前后的对比,清晰说明改进后的代码如何提高了可读性、可维护性或性能。 - 解释改进后的具体优势,如减少重复代码、提高逻辑清晰度等。 ``` 请确保所有示例都基于C#语言,并与电子商务系统的实际功能(如订单处理、用户管理、库存更新等)相关,帮助开发者在实践中理解和应用这些改善代码的方法。
Use C#Refactoring on 302.AI

C#Refactoring GPT FAQs

Currently, access to this GPT requires a ChatGPT Plus subscription.
Visit the largest GPT directory GPTsHunter.com, search to find the current GPT: "C#Refactoring", click the button on the GPT detail page to navigate to the GPT Store. Follow the instructions to enter your detailed question and wait for the GPT to return an answer. Enjoy!
We are currently calculating its ranking on the GPT Store. Please check back later for updates.

More custom GPTs by @noob92533838 on the GPT Store

MermaidDiagrams

将用户描述转化为Mermaid图表代码

90+

MermaidDiagrams on the GPT Store

C#Naming

基于用户需求提供符合C#命名规范的建议,助力提升代码的可读性和维护性。

40+

C#Naming on the GPT Store

C#UnitTest

致力于使用NUnit、XUnit或MSTest中的任一测试框架,设计和执行单元测试

40+

C#UnitTest on the GPT Store

WBS(Work Breakdown Structure)

专注于用户需求分析与项目管理,擅长将复杂需求转化为具体的开发子任务,并提供优先级和依赖关系分析。

30+

WBS(Work Breakdown Structure) on the GPT Store

StructuredPromptOptimize

基于用户输入的结构化Prompt分析并重构Prompt,以更准确地表达用户意图

8+

StructuredPromptOptimize on the GPT Store

DBAAssistant

将用户需求转化为SQL Server或MySQL的SQL语句和数据库设计需求列表的AI助手

6+

DBAAssistant on the GPT Store

DocToCSharpCode

根据用户输入的文档内容转换C#类定义

6+

DocToCSharpCode on the GPT Store

JavaScriptRefactoring

专注于Javascript编程与代码重构,精通jQuery、knockout、vuejs等开源库和Typescript。旨在通过审查和改进代码来增强其可读性、可测试性、可扩展性和可维护性。

5+

JavaScriptRefactoring on the GPT Store

PromptEngineer

专门将常规Prompt转化为遵循[CRISPE提示框架]的高效Prompt,并进一步优化为结构化Prompt。旨在提高输出的回复质量和达到预期目标。

4+

PromptEngineer on the GPT Store

RespJsonToMarkdown

将Json格式的响应数据结构体以Markdown呈现

3+

RespJsonToMarkdown on the GPT Store

BOREPrompt工程师

将用户的描述转换为B.O.R.E提示框架的Prompt

3+

BOREPrompt工程师 on the GPT Store

FullStackEngineer

作为负责设计、开发和维护网络应用程序的前端和后端的全栈工程师AI助手,具备广泛的技术和编程语言知识。

3+

FullStackEngineer on the GPT Store

JenkinsGroovyRefactoring

专注于Groovy编程和代码重构的AI助手,旨在Jenkins环境下审查与改进Groovy代码。目标是增强代码的可读性、可测试性、可扩展性和可维护性,同时确保优化后的代码在Jenkins中能够正确执行。

3+

JenkinsGroovyRefactoring on the GPT Store

TestEngineer

解读功能需求和制定测试用例

2+

TestEngineer on the GPT Store

SQLToC#Code

SQL语句转换为C#代码

2+

SQLToC#Code on the GPT Store

CSharpDDD

基于DDD为客户需求生成高质量的代码,并提供具有清晰领域模型的方案

2+

CSharpDDD on the GPT Store

C#CodeRefactoring

C# 代码重构专家

2+

C#CodeRefactoring on the GPT Store

BuildAdminHtml

根据用户需求构建后台页面

2+

BuildAdminHtml on the GPT Store

ReqJsonToMarkdown

将Json格式的请求数据结构以Markdown表格方式展示

2+

ReqJsonToMarkdown on the GPT Store

JsonToCSharpCode

将Json数据中的结构转换为C#代码

1+

JsonToCSharpCode on the GPT Store

PowerShellRefactoring

专注于PowerShell编程与代码重构的AI助手,负责审查和改进PowerShell脚本。通过重构提升脚本的可读性、可测试性、可扩展性和可维护性

1+

PowerShellRefactoring on the GPT Store

Best Alternative GPTs to C#Refactoring on GPTs Store

C Sharp Refiner

Refactors C# for .NET 4.8 & Visual Studio 2019, in Japanese.

300+

C Coding Assistant

Will help you make code, bug check your code, give you examples, or help you in the right direction.

100+

Ghidra Code Cleaner

Detail-oriented C++ code refactoring, emphasizing modern standards and concise guidance.

100+

Cognitive Complexity Reducer

Assistant for refactoring C# .NET code to reduce cognitive or cyclomatic complexity

50+

Code Mentor

C# code refactoring expert providing examples.

30+

C# Refactoring and Clean Code Pro

한글로 C# 리팩토링, 클린 코드 및 SMT PCB 검사 전문

20+

C# Refactor Pro

A C# refactoring and design pattern expert.

20+

C# Refactor Assistant

Assists in refactoring C# code with focus on clean code practices, readability, efficiency, and maintainability.

10+

C# Code Companion

Guides C# code refactoring and improvement, with examples and learning resources.

10+

🚀 Refactoring C Codebase Guide

Ready to turn that C codebase from tangled to terrific? This is the GPT for you! 🔎 Get insights from a veteran C programmer, learn how to refactor effectively and understand code organization. 🎓 💎 💼

10+

Unity Refactor Pro

Specialist in refactoring C# for Unity, enhancing readability and maintainability.

10+

📚 Refactoring Legacy C++ with Smart Pointers

Transform old C++ codebases into modern, efficient, and maintainable marvels! 💪 💡 Eliminate memory leaks and boost performance with smart pointers. 🚀 🧩 🎯

10+

.NET Expert

Experienced .NET & C# advisor for clean and efficient code.

10+

🛠️ C# Code Refactoring

With this prompt, you'll put on the hat of a seasoned software developer, diving deep into a major refactoring task.💡🎉🧠

8+

Code Refactor Guru

A friendly C# expert for practical refactoring advice.

3+

Moder.io

Comprehensive coding assistant for HTML, Python, JavaScript, and C#

1+

👨‍💻 Refactoring C Codebase Guide

Ready to turn that C codebase from tangled to terrific? This is the GPT for you! 🔎 Get insights from a veteran C programmer, learn how to refactor effectively and understand code organization. 🎓 💎💻💼

🛠️ C# Code Refactoring

Seasoned C# developer guiding extensive codebase refactoring for improved efficiency and clarity. 🚀🧠💡 Dive into code, streamline, and enhance! 🎉

Harness C++ for Elite Memory Management

Elite C++ Developer specializing in Memory Management. Dive into optimizing and refactoring C++ applications for peak performance! 🛠️🚀🧠💻

📚 Refactoring Legacy C++ with Smart Pointers

Transform old C++ codebases into modern, efficient, and maintainable marvels! 💪 💡 Eliminate memory leaks and boost performance with smart pointers. 🚀 😎 Step into the shoes of an experienced engineer and guide the refactoring process. 🧩 🥳