Archive for the ‘.NET’ Category

随手写了几个Char类型的扩展方法   2 comments

C# 3.0的新特性很好使 /// <summary> /// This helper class extends the /// methods that Char offers /// </summary> internal static class CharHelper { /// <summary> /// Increase the char value by an integer /// </summary> /// <param name="source">the source char value</param> /// <param name="increament">the increament</param> /// <returns>the increased char</returns> public static Char Increase(this Char source, Int32 [...]

Posted November 1, 2007 by garfilone in .NET

See several Architecture Diagrams   Leave a comment

MSDN Community is always the first & best choice for a so-called Micro$oft programmer, just like me. Today’s discovery is a server-based application call .NET Stock Trader. The content page contains several links, from which you can get the source of the application, the builds and some documents. This sample application shows how to build [...]

Posted September 30, 2007 by garfilone in .NET

.NET Tips: Something about BackgroundWorker , from Mark Zhou   1 comment

发信人: hustorochi (Mark Zhou), 信区: DotNet标  题: Re: Working with BackgroundWorker发信站: 武汉白云黄鹤站 (2007年09月06日16:28:30 星期四) BackgroundWork is a new Control in .NET Framework 2.0; and it really makes an easy way to perform asynchronony code. Meanwhile, there are some top tips using this Control. 1. DONOT perform more than one work in a same BackgroundWorker, that [...]

Posted September 6, 2007 by garfilone in .NET

.NET Topics: Working with BackgroundWorker in C#   Leave a comment

MSDN says that using the BackgroundWorker component is the preferred way to implement multithreading in your application. The BackgroundWorker component uses an event-driven model for multithreading. The worker thread runs your DoWork event handler, and the thread that creates your controls runs your ProgressChanged and RunWorkerCompleted event handlers. If you use multithreading to improve the [...]

Posted September 6, 2007 by garfilone in .NET

C# 3.0: LINQ初体验   Leave a comment

今天终于体验到了Linq的爽快便利,简单定义了一个Person类,然后写了个Main作为测试: static void Main(string[] args){    List<Person> persons = new List<Person>();    persons.Add(new Person("Tim", "Thomas", 26));    persons.Add(new Person("Tim", "Duncan", 29));    persons.Add(new Person("Ming", "Yao", 27));    persons.Add(new Person("Kobe", "Bryant", 30));    persons.Add(new Person("Tracy", "McGrady", 28));     var selectPersons = from p in persons                        where p.Age < 29 orderby p.Age descending                        select p;    foreach (var p in selectPersons)        Console.WriteLine(p);} 输出: Tracy [...]

Posted August 6, 2007 by garfilone in .NET

原来这样就是所谓的.NET内建的对AOP的支持   1 comment

[WebMethod]public string HelloWorld(){  return "Hello World";} 对于这样一个最简单的WS代码,[WebMethod]属性标签告诉ASP.NET的Runtime说这是一个Web方法,然后ASP.NET的Runtime会自动为它加上必要的框架代码使之成为完整的WebMethod,这样就是比较简单而明显的一个AOP。看到这里对“.NET以Attributes内建对AOP的支持”有了一点理解了

Posted July 27, 2007 by garfilone in .NET

关于托管GDI+的一点随笔   Leave a comment

最近使用GDI在MFC下写了位图文件的解析和基本变换的程序,萌生出使用托管GDI+编写.NET平台适用的图像处理库的想法,下手编写的时候马上遇到了处理索引颜色图像的问题,遂中断工作并进行了简单的测试。托管GDI+提供的GetPixel(int x,int y)可以针对任何支持的图像格式获取其颜色值,不管是RGBA模式色彩还是索引色彩,但是SetPixel(int x,int y,Color c)却不支持对索引色彩图像的像素点色彩赋值,这不是对称的Get/Set,看来要利用托管GDI+封装一个图像滤镜库,必须重新封装SetPixel方法。封装方法可以继续参考基于C/C++的开源图像库CxImage 在同一幅图像上(BMP,791KB,24Bpp,600×450)执行灰度变换算法,分别使用以下两段代码: 第一段:// 使用GetPixel与SetPixel执行灰度变换 Bitmap b; Color c;for (int y = 0; y < b.Height;y++){    for(int x=0;x<b.Width;x++)    {        // 得到像素点的颜色信息        c=b.GetPixel(x, y);        // 灰度变换计算式        byte val = (byte)(.299 * c.R + .587 * c.G + .114 * c.B);        // 灰度化        c=Color.FromArgb(val, val, val);        b.SetPixel(x, y, c);    }} 第二段:// 使用指针扫描内存区执行灰度变换 Bitmap [...]

Posted July 27, 2007 by garfilone in .NET

关于MulticastDelegate的[Serializable]标记   Leave a comment

 [Serializable]public abstract class MulticastDelegate : Delegate   这个问题我芍了,怎么就忘记了所谓的面向抽象编程呢,测试了一下Stream fs = new FileStream("delegateData.soap", FileMode.OpenOrCreate);SoapFormatter soapFormatter = new SoapFormatter();soapFormatter.Serialize(fs, bOP);fs.Dispose();   看看输出的SOAP   <SOAP-ENV:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:clr="http://schemas.microsoft.com/soap/encoding/clr/1.0" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"><SOAP-ENV:Body><a1:DelegateSerializationHolder id="ref-1" xmlns:a1="http://schemas.microsoft.com/clr/ns/System"><Delegate href="#ref-2"/><method0 href="#ref-3"/></a1:DelegateSerializationHolder><a1:DelegateSerializationHolder_x002B_DelegateEntry id="ref-2" xmlns:a1="http://schemas.microsoft.com/clr/ns/System"><type id="ref-4">ClrTest.Program+BinaryOp</type><assembly id="ref-5">ClrTest, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null</assembly><target xsi:type="xsd:anyType" xsi:null="1"/><targetTypeAssembly href="#ref-5"/><targetTypeName id="ref-6">ClrTest.Program+SimpleMath</targetTypeName><methodName id="ref-7">Subtract</methodName><delegateEntry xsi:null="1"/></a1:DelegateSerializationHolder_x002B_DelegateEntry><a2:MemberInfoSerializationHolder id="ref-3" xmlns:a2="http://schemas.microsoft.com/clr/ns/System.Reflection"><Name href="#ref-7"/><AssemblyName href="#ref-5"/><ClassName href="#ref-6"/><Signature id="ref-8">Int32 Subtract(Int32, Int32)</Signature><MemberType>8</MemberType><GenericArguments xsi:null="1"/></a2:MemberInfoSerializationHolder></SOAP-ENV:Body></SOAP-ENV:Envelope>

Posted July 22, 2007 by garfilone in .NET

C# Delegate略析   1 comment

C# Delegate,看起来和函数指针很类似,我简单理解为安全的方法套 直接看代码来理解CLR之上的机制,废话不说 对于一个简单的委托public delegate int BinaryOp(int x, int y); 它将展开为sealed class BinaryOp : System.MulticastDelegate{    public BinaryOp(object target, uint functionAddress);    public void Invoke(int x, int y);    public IAsyncResult BeginInvoke(int x, int y,        AsyncCallback cb, object state);    public int EndInvoke(IAsyncResult result);} 注意到这是一个封闭的类,然后提供了异步调用的能力 更泛的情况,一个类似代入公式的伪代码写法:public sealed class DelegateName : System.MulticastDelegate{    public DelegateName (object target, uint functionAddress);    public delegateReturnValue [...]

Posted July 21, 2007 by garfilone in .NET

C# 静态构造器的功用   3 comments

课件修订到这一块的时候发现没有写例程,随手写一个,能说明静态构造器的功用 using System; public class MathClass{    public static double pie;    public double instVal;     static MathClass()    {        Console.WriteLine("Static Ctor does stuff");        pie = 3.14159;    }     public MathClass() { }    public MathClass(double val)     {        Console.WriteLine("Instance Ctor does stuff");        this.instVal = val;     }} public class MathClass2{    public static double staticVal;    public double instVal;     [...]

Posted July 17, 2007 by garfilone in .NET

Follow

Get every new post delivered to your Inbox.