Skip to content

Instantly share code, notes, and snippets.

@SridharPasham
SridharPasham / SerializeDeserializeTest
Created February 4, 2022 09:46
Serialize and deserialize test in asp.net web api
string Serialize<T>(MediaTypeFormatter formatter, T value)
{
// Create a dummy HTTP Content.
Stream stream = new MemoryStream();
var content = new StreamContent(stream);
/// Serialize the object.
formatter.WriteToStreamAsync(typeof(T), value, stream, content, null).Wait();
// Read the serialized string.
stream.Position = 0;
return content.ReadAsStringAsync().Result;
@SridharPasham
SridharPasham / ExecuteAroundMethodPattern.cs
Last active June 24, 2019 07:50
Execute Around Method pattern
using System;
using System.Collections.Generic;
namespace PatternsByVS
{
public class Resource
{
private Resource()
{
Console.WriteLine("Resource created...");
@SridharPasham
SridharPasham / AbstractFactory.cs
Last active December 30, 2015 09:53
AbstractFactory sample code
using System;
using System.Collections.Generic;
namespace PatternsByVS
{
public class Book
{
public string Title { get; set; }
public string Pages { get; set; }
using System;
namespace ConsoleApplication1
{
// Declare delegate
public delegate int mathDelegate(int a, int ab);
class EventDelegateClass
{
// event of type mathDelegate