devxlogo

.NET

Net Development

Top .NET Development Companies

In the dynamic world of software development, one framework stands tall, powering the technology-driven future: .NET. In this article, we unveil the pioneers, the visionaries, and the game-changers—the Top .NET

Unit Test Non-Public Methods in C# Unit Tests

To expose non-public methods to the test project, you need to mark the assembly with an attribute called InternalsVisibleTo in the asemblyinfo.cs file?? For example: [assembly: InternalsVisibleTo(“testProjectName”)] You need to

Replace a Web API Response with a Custom JSON

Use StringContent?in the Web API response to return a custom JSON. See below for an example: StringContent responseContent = new StringContent ( ” { ‘handled’ : ‘true’ } “, Encoding.UTF8,

Extract Faces Using Amazon Rekognition

AmazonRekognitionClient amazonRekognitionClient = new AmazonRekognitionClient(Amazon.RegionEndpoint.);byte[] imageData = System.IO.File.ReadAllBytes(inputImageFile);DetectFacesRequest facesRequest = new DetectFacesRequest();facesRequest.Image = new Amazon.Rekognition.Model.Image{Bytes = new MemoryStream(imageData)};DetectFacesResponse facesResponse = amazonRekognitionClient.DetectFaces(facesRequest);//If faces are detected, extract themif (facesResponse.FaceDetails.Count > 0){foreach (var

Convert a String to a Byte Array

Explore how to convert a string to a byte array. String stringToBeConverted = ” ? ” ;int stringLength = stringToBeConverted.Length;byte[] bytes = new byte[stringLength / 2];for (int counter = 0;

Split a Concatenated String with a Delimiter

Here is how to split a concatenated string with a delimiter and remove empty entries. public static void Test() { string concatenatedString = “,ONE,,TWO,,,THREE,,”; char[] charSeparator = new char[] {‘,’};

Use BitConverter Class to Convert a Byte Array

BitConverter’s ToString?method can be used to convert a byte array to a string. See below for an example: byte[] byteArray = ?string convertedString = BitConverter.ToString(byteArray).Replace(“-“,””);

Using SoapHexBinary Class for Byte and String Conversions

See below for a code sample of how to perform byte and string conversions: using System.Runtime.Remoting.Metadata.W3cXsd2001;public static byte[] GetStringToBytes(string stringValue){ SoapHexBinary result = SoapHexBinary.Parse(stringValue); return result.Value;}public static string GetBytesToString(byte[] byteArray){