The Argotic Syndication Framework is a Microsoft .NET class library framework that enables developers to easily consume and/or generate syndicated content from within their own applications. The framework makes the reading and writing syndicated content in common formats such as RSS, Atom, OPML, APML, BlogML, and RSD very easy while still remaining extensible enough to support common/custom extensions to the syndication publishing formats. The framework includes out-of-the-box implementations of the most commonly used syndication extensions, network clients for sending and receiving peer-to-peer notification protocol messages; as well as HTTP handlers, modules, services and controls that provide rich syndication functionality to ASP.NET developers.
Adsense
Thursday, March 27, 2008
Thursday, January 31, 2008
System.Reflection - MethodInfo class (usage)
A MethodInfo class provides detailed information about a single method of a class or an interface. The reflected method may be a static method or an instance method. The MethodInfoSpy example shows how to obtain the method information of a class including the access modifiers, type or input parameters:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
using System.Reflection;
namespace MethodInfoSpy
{
class Program
{
static void Main(string[] args)
{
Type type = typeof(Program);
MethodInfo [] methodInfos = type.GetMethods();
foreach (MethodInfo methodInfo in methodInfos)
{
// retrive method information
Console.WriteLine("Name: {0}, Public: {1}, Is Static: {2}, Return Type: {3}",
methodInfo.Name,
methodInfo.IsPublic,
methodInfo.IsStatic,
methodInfo.ReturnType.FullName);
// retrive method parameters information
ParameterInfo [] paramInfos = methodInfo.GetParameters();
foreach (ParameterInfo paramInfo in paramInfos)
{
Console.WriteLine("Parameter Name: {0}, Parameter Type: {1}",
paramInfo.Name, paramInfo.ParameterType.FullName);
}
}
Console.ReadLine();
}
public void DoNothing()
{
}
public int Add(int x, int y)
{
return x + y;
}
}
}
A sample of the output follows:
Name: DoNothing, Public: True, Is Static: False, Return Type: System.Void |
at
23:49
0
comments
Tags: C#, reflection
How to support != and == operations for C# struct
Sometimes we prefer to use structs instead classes .The C# is a convenient way to store coordinates ,complex number etc .
In an example below I'm presenting how to support == and != operators in case we want to check if our structs are equal.
// <summary>
/// Circle
/// </summary>
struct Circle
{
public Point Center;
public double Radius;
/// <summary>
/// Compares two Circle objects. The result specifies whether the values
/// of the Center or Radius properties of the two Circle objects are equal.
/// </summary>
/// <param name="left">A Circle to compare.</param>
/// <param name="right">A Circle to compare.</param>
/// <returns>true if the the Center properties or the Radius properties
/// of left and right are equal; otherwise, false.</returns>
public static bool operator ==(Circle left, Circle right)
{
return (left.Center == right.Center) && (left.Radius == right.Radius);
}
/// <summary>
/// Compares two Circle objects. The result specifies whether the values
/// of the Center or Radius properties of the two Circle objects are unequal.
/// </summary>
/// <param name="left">A Circle to compare.</param>
/// <param name="right">A Circle to compare.</param>
/// <returns>true if the values of either the Center properties
/// or the Radius properties of left and right differ; otherwise, false.</returns>
public static bool operator !=(Circle left, Circle right)
{
return !(left == right);
}
/// <summary>
/// Specifies whether this Circle contains the same Center and Radius as
/// the specified Object.
/// </summary>
/// <param name="obj">Another object to compare to.</param>
/// <returns>
/// true if obj is a Point and has the same Center and Radius as this Circle.
/// </returns>
public override bool Equals(object obj)
{
if (!(obj is Circle))
{
return false;
}
Circle circle = (Circle)obj;
return (circle.Center == this.Center) && (circle.Radius == this.Radius);
}
/// .... You need to overload GetHashCode and ToString methods
}
Testing our struct ...
static void Main(string[] args)
Circle circle1 = new Circle();
circle1.Center = new Point(10, 10);
circle1.Radius = 20;
Circle circle2 = new Circle();
circle2.Center = new Point(10, 10);
circle2.Radius = 20;
bool result = (circle1==circle2);
Console.WriteLine("Is circle1 equal to circle2? [{0}]", result );
circle2.Center = new Point(14, 10);
result = (circle1 == circle2);
Console.WriteLine("Is circle1 equal to circle2? [{0}]", result);
Console.ReadLine();
at
22:57
0
comments
Tags: C#
Sunday, December 02, 2007
SHA1 hash calculation in C#
The SHA1 algorithm can be used to calculate check sum, that very useful when you want to ensure the string is not broken .Also for simple password verification.The example below show how to calculate SHA1 for given string .
/// <summary>
/// Calculates SHA1 hash
/// </summary>
/// <param name="text">input string</param>
/// <param name="enc">Character encoding</param>
/// <returns>SHA1 hash</returns>
public static string CalculateSHA1(string text, Encoding enc)
{
byte[] buffer = enc.GetBytes(text);
SHA1CryptoServiceProvider cryptoTransformSHA1 =
new SHA1CryptoServiceProvider();
string hash = BitConverter.ToString(
cryptoTransformSHA1.ComputeHash(buffer)).Replace("-", "");
return hash;
}
The result SHA1 hash for the string "first string":
at
23:29
10
comments
Tags: C#