什么返回一个布尔和字符串值的最佳实践 [英] Whats the best practice for returning a Boolean and string value

查看:96
本文介绍了什么返回一个布尔和字符串值的最佳实践的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经创建了一个执行针对动态通过在运行时的Javascript文字另一个类生成的XML层次一些验证的方法。

I've created a method that performs some validations against an XML Hierarchy that is dynamically generated by another Class in Javascript text during run time.

我的方法目前返回无论是真是假,这是用我的类,但我想也回归更丰富的信息,因为可能有几个原因可以抛出一个假消息的人有所帮助。

My method currently returns either True or False, which is helpful for anyone using my Class but I'd like to also return more informative information since there may be several reasons that can throw a False message.

起初我以为,从布尔改变返回类型有一个字符串键和布尔值,我不知道这是最好的办法了一些泛型集合类型。

At first I thought to change the return type from bool to some Generic Collection type having a String key and Boolean value I don't know if this is the best approach.

什么是在这种情况下的最佳实践?

What is the Best Practice in this case?

推荐答案

请像

public class ValidationResponse
{
    public bool Successful { get; set; }
    public string Information { get; set; }
}

和返回ValidationResponse

and return object of ValidationResponse

这篇关于什么返回一个布尔和字符串值的最佳实践的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆