Background technology
.NET be Microsoft's extend markup language Page Service (Microsoft XML Web services) platform.XML Web services allows application program to carry out communication and shared data by the Internet (Internet), and is which kind of operating system, equipment or programming language regardless of what adopt.Microsoft.NET platform provide create XML Web services and these services are integrated required.
Enumeration type (also referred to as enumerating) provides a kind of effective method for defining one group of name integer constant that can be assigned to variable..NET the enumeration type that the enumerated value under permits using has byte (byte), sbyte, short (short), ushort, integer (int), uint, long (long) or ulong.
When enumerating, inherit from a certain type, when the arbitrary value of this type is paid enumeration object, no matter can normally move when .NET compiles or when .NET moves.Within in service logic, expectation arbitrary value should constrain in the scope of our enumeration definition conventionally.
In correlation technique, adopt following two schemes to realize the validity checking of enumeration definition:
Scheme one: use Enum.IsDefined method to check enumerated value definition, the method can reference: Enum.IsDefined method definition in official of Microsoft document (
http:// msdn.microsoft.com/en-us/library/system.enum.isdefined.a spx).
Inventor finds in research process, and scheme one cannot detect enumerating the situation of combination.
Scheme two: by reflection, obtain enumeration definition, by converting the value of examine to binary numeral, reexamine on each bit (bit) position whether in enumerating, have corresponding definition, for example:
1, check bit flag, check in enumeration definition whether apply System.FlagsAttribute characteristic;
If 2 not application, check by the Enum.IsDefined method providing in scheme one;
If 3 have applied System.FlagsAttribute characteristic, by reflection, obtain all current numerical value of enumerating and define.
Inventor finds in research process, and the technical sophistication degree that scheme two realizes is high, and the execution efficiency of program is low.
Mode technical sophistication degree for the validity checking of enumeration definition in correlation technique is high, and the problem that execution efficiency is low, not yet proposes effective solution at present.
Summary of the invention
The invention provides a kind of definition validity checking method and device of object, high at least to solve the mode technical sophistication degree of validity checking of enumeration definition in correlation technique, the problem that execution efficiency is low.
According to an aspect of the present invention, provide a kind of definition validity checking method of object, having comprised: the returning an object value character string method of invocation target object, and obtain the first rreturn value that returning an object value character string method is returned; Force to change described destination object into basic value type; Call the returning an object value character string method of forcing the described destination object after conversion, and obtain the second rreturn value that returning an object value character string method is returned; According to described the first rreturn value and described the second rreturn value, determine the legitimacy of the definition of described destination object.
Preferably, according to described the first rreturn value and described the second rreturn value, determine that the legitimacy of the definition of described destination object comprises: judge that whether described the first rreturn value is consistent with described the second rreturn value; Judgment result is that consistent in the situation that, the legitimacy of determining the definition of described destination object is no.
Preferably, the legitimacy of determining the definition of described destination object be no after, described method also comprises: the legitimacy that shows the definition of described destination object is no result.
Preferably, judgment result is that, in inconsistent situation, described method also comprises: the legitimacy of determining the definition of described destination object is yes.
Preferably, described basic value type comprises one of following: integer, long.
Preferably, described destination object comprises: inherit and to enumerate or to inherit the combination of enumerating from primary object from primary object.
According to another aspect of the present invention, also provide a kind of definition validity checking device of object, having comprised: the first processing module, for the returning an object value character string method of invocation target object, and obtain the first rreturn value that returning an object value character string method is returned; Modular converter, changes described destination object into basic value type for forcing; The second processing module, for calling the returning an object value character string method of forcing the described destination object after conversion, and obtains the second rreturn value that returning an object value character string method is returned; Determination module, for according to described the first rreturn value and described the second rreturn value, determines the legitimacy of the definition of described destination object.
Preferably, described determination module comprises: judging unit, for judging that whether described the first rreturn value is consistent with described the second rreturn value; The first determining unit, for judgment result is that consistent in the situation that, the legitimacy of determining the definition of described destination object is no.
Preferably, described device also comprises: display module, and for showing that the legitimacy of the definition of described destination object is no result.
Preferably, described determination module also comprises: the second determining unit, for judgment result is that in inconsistent situation, the legitimacy of determining the definition of described destination object is yes.
By the present invention, adopt the returning an object value character string method of invocation target object, and obtain the first rreturn value that returning an object value character string method is returned; Forcing switch target object is basic value type; Call the returning an object value character string method of forcing the destination object after conversion, and obtain the second rreturn value that returning an object value character string method is returned; According to the first rreturn value and the second rreturn value, determine the mode of legitimacy of the definition of destination object, the mode technical sophistication degree of validity checking that has solved enumeration definition in correlation technique is high, the problem that execution efficiency is low, reduce the complexity realizing, improved execution efficiency.
Embodiment
It should be noted that, in the situation that not conflicting, embodiment and the feature in embodiment in the application can combine mutually.Describe below with reference to the accompanying drawings and in conjunction with the embodiments the present invention in detail.
In the step shown in the process flow diagram of accompanying drawing, can in the computer system such as one group of computer executable instructions, carry out, and, although there is shown logical order in flow process, in some cases, can carry out shown or described step with the order being different from herein.For example, the step of the step of the step S104 in the following example, step S106 and step S102 can be exchanged.
The present embodiment provides a kind of definition validity checking method of object, and Fig. 1 is according to the schematic flow sheet of the definition validity checking method of the object of the embodiment of the present invention, and as shown in Figure 1, this flow process comprises the steps:
Step S102, the returning an object value character string method of invocation target object, and obtain the first rreturn value that returning an object value character string method is returned;
Step S104, forcing switch target object is basic value type;
Step S106, calls the returning an object value character string method of forcing the destination object after conversion, and obtains the second rreturn value that returning an object value character string method is returned;
Step S108, according to the first rreturn value and the second rreturn value, determines the legitimacy of the definition of destination object.
Pass through above-mentioned steps, the mode that the result of respectively the returning an object value character string method of the destination object after destination object and pressure translation type being returned compares, to determine the legitimacy of the definition of destination object, for the scheme two providing in correlation technique, owing to no longer needing the value by examine to convert binary numeral to, reexamine and on each bit, whether in enumerating, have corresponding definition, thereby the mode technical sophistication degree of validity checking that has solved enumeration definition in correlation technique is high, the problem that execution efficiency is low, reduced the complexity realizing, improved execution efficiency.
Preferably, step S108 comprises: judge that whether the first rreturn value is consistent with the second rreturn value; Judgment result is that consistent in the situation that, the legitimacy of determining the definition of destination object is no.
Preferably, the legitimacy of determining the definition of destination object be no after, the legitimacy of definition that can also display-object object is no result, to notify the definition of ownership goal object, is illegal.
Preferably, in step S108, also comprise: judgment result is that in inconsistent situation, determining that the definition of destination object is legal.
Preferably, above-mentioned basic value type comprises one of following: integer, long.
Preferably, destination object comprises: inherit and to enumerate or to inherit the combination of enumerating from primary object from primary object.By the such scheme providing in the present embodiment, not only can check the legitimacy of single enumeration object, can also support to check enumerating the legitimacy of combination, filled up the existing defect of scheme one in correlation technique.
The present embodiment also provides a kind of definition validity checking device of object, this device is for realizing the definition validity checking method of above-mentioned object, function in this device embodiment realizes had carried out detailed explanation in said method embodiment, at this, will repeat no more.
Fig. 2 is according to the structural representation of the definition validity checking device of the object of the embodiment of the present invention, as shown in Figure 2, this device comprises: the first processing module 22, modular converter 24, the second processing module 26 and determination module 28, wherein, the first processing module 22, for the returning an object value character string method of invocation target object, and obtain the first rreturn value that returning an object value character string method is returned; Modular converter 24 is basic value type for forcing switch target object; The second processing module 26 is coupled to modular converter 24, for calling the returning an object value character string method of forcing the destination object after conversion, and obtains the second rreturn value that returning an object value character string method is returned; Determination module 28 is coupled respectively to the first processing module 22 and the second processing module 26, for according to the first rreturn value and the second rreturn value, determines the legitimacy of the definition of destination object.
Module, unit involved in embodiments of the invention can be realized by the mode of software, also can realize by the mode of hardware.Described module in the present embodiment, unit also can be arranged in processor, for example, can be described as: a kind of processor comprises the first processing module 22, modular converter 24, the second processing modules 26 and determination module 28.Wherein, the title of these modules does not form the restriction to this module itself under certain conditions, for example, the first processing module can also be described to " for the returning an object value character string method of invocation target object and obtain the module of the first rreturn value that returning an object value character string method returns ".
Fig. 3 is that preferably, determination module 28 comprises according to the preferred structure schematic diagram one of the definition validity checking device of the object of the embodiment of the present invention: judging unit 282, for judging that whether the first rreturn value is consistent with the second rreturn value; The first determining unit 284 is coupled to judging unit 282, for judgment result is that consistent in the situation that, the legitimacy of determining the definition of destination object is no.
Fig. 4 is according to the preferred structure schematic diagram two of the definition validity checking device of the object of the embodiment of the present invention, preferably, this device also comprises: display module 42 is coupled to the first determining unit 284, for the legitimacy of the definition of display-object object, is no result.
Fig. 5 is according to the preferred structure schematic diagram three of the definition validity checking device of the object of the embodiment of the present invention, preferably, determination module 28 also comprises: the second determining unit 286 is coupled to judging unit 282, for judgment result is that in inconsistent situation, the legitimacy of determining the definition of destination object is yes.
Preferably, above-mentioned basic value type comprises one of following: integer, long.
Preferably, destination object comprises: inherit and to enumerate or to inherit the combination of enumerating from primary object from primary object.
Below in conjunction with preferred embodiment, be described and illustrate.
This preferred embodiment provide a kind of under .NET enumerated value invalid value pick-up unit, Fig. 6 is the workflow schematic diagram of enumerated value invalid value pick-up unit under .NET according to the preferred embodiment of the invention, as shown in Figure 6, whether legally suppose to detect some enumeration object M, the course of work of this device comprises the steps:
Step S1, calls its returning an object value character string (ToString ()) method by current object M, and the rreturn value of obtaining after its ToString is referred to as A;
Step S2, is transformed into long type by current object M and obtains an object B;
Step S3, is referred to as C by the rreturn value of calling after B object ToString () method;
Step S4, relatively whether A is identical with C, if the same proves that M is the content (illegal) that belongs to non-original definition, if inconsistent, proves that M is the content (being legal) of original definition
Seen from the above description, by the above embodiment of the present invention, can support enumerating the detection of mark (Flag) attribute tags in .NET, and realize the simple validity checking of definition efficiently.In a preferred embodiment of the invention, put forth effort on and check out and enumerate legal definition (checking out that value is the combination of enumerated value definition or enumeration definition), the run-time exception of can also dishing out and if illegal.Visible, the mode technical sophistication degree of validity checking that the embodiment of the present invention has at least solved enumeration definition in correlation technique is high, and the problem that execution efficiency is low has reduced the complexity realizing, and has improved execution efficiency.
Obviously, those skilled in the art should be understood that, above-mentioned each module of the present invention or each step can realize with general calculation element, they can concentrate on single calculation element, or be distributed on the network that a plurality of calculation elements form, alternatively, they can be realized with the executable program code of calculation element, thereby, they can be stored in memory storage and be carried out by calculation element, or they are made into respectively to each integrated circuit modules, or a plurality of modules in them or step are made into single integrated circuit module to be realized.Like this, the present invention is not restricted to any specific hardware and software combination.
More than above are only the preferred embodiments of the present invention, be not limited to the present invention, for a person skilled in the art, the present invention can have various modifications and variations.Within the spirit and principles in the present invention all, any modification of doing, be equal to replacement, improvement etc., within all should being included in protection scope of the present invention.