My library: Hicsutil

Source: Internet
Author: User

Hicsutil is a generic library I wrote, Address: Https://github.com/xumingxsh/HiCSUtil

The goal of the library is to provide a common library for some of the features that are reused. Mainly include:

1:CBO: Provides a simple mapping of data to objects, such as initializing or creating an object based on the obtained DataRow.

2:json: Provides JSON string to object, object to JSON string, JSON string to datatable,datatable to JSON string conversion.

3:datatableutil:datatable, the goal is to avoid accessing nonexistent columns or column rows that result in a crash that exceeds the index. Also includes reading data of the specified type from the DataTable.

4:hilog: A log framework, after I abstract the log, I find that the write log only requires a function (and its extension function), which can bring the most convenience to the log.

5: Hitypehelper: Type of auxiliary class, learning from Esbasic, the main function has to determine whether data type, whether simple type, according to their own needs to obtain the default value of a certain type of data, etc.

How do I read this program? First, look at the test cases under the Test folder.

1:CBO:

In UNITTESTCBO, there is the CBO test code, for example:

private void filldr<t> (T obj, DataRow dr)        {            CBO. Fillobject (obj, (string name) + =            {                if (!dr. Table.Columns.Contains (name))                {                    return null;                }                return dr[name];}            );        

This code demonstrates how to assign a value to an object based on a DataRow.

2:json Conversion:

Unittestjson The following is the test case code for the JSON transformation.

[TestMethod]        public void unittestjson_datatable ()        {            DataTable dt = GetTable ();            Dt. TableName = "table";            String str = Json.datatable2json (dt);            System.Diagnostics.Debug.WriteLine (str);            DataTable DT2 = json.json2datatable (str);            Assert.istrue (DT2. Rows.Count > 0);        }

The preceding code snippet shows how to convert a DataTable to a JSON string, or a JSON string, or a DataTable.

[TestMethod]        public void Unittestjson_dictionary ()        {            idictionary<string, string> dic = new dictionary<string, String> ();            dic["x"] = "x";            dic["y"] = "Y";            string text = Json.obj2json (DIC);            Assert.isfalse (String. Isnullorwhitespace (text));            System.Diagnostics.Trace.WriteLine (text);            dictionary<string, string> dic2 = json.json2obj<dictionary<string, string>> (text);            Assert.istrue (Dic2. Count = = 2);        }

The code above demonstrates how to convert a data dictionary to a JSON string and then convert the JSON string back to the data dictionary.

Note:

The CBO learns from DotNetNuke (DNN).

My library: Hicsutil

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.