extends Binder to create your own binder : Binder « GUI Windows Forms « C# / CSharp Tutorial

Home
C# / CSharp Tutorial
1.Language Basics
2.Data Type
3.Operator
4.Statement
5.String
6.struct
7.Class
8.Operator Overload
9.delegate
10.Attribute
11.Data Structure
12.Assembly
13.Date Time
14.Development
15.File Directory Stream
16.Preprocessing Directives
17.Regular Expression
18.Generic
19.Reflection
20.Thread
21.I18N Internationalization
22.LINQ
23.GUI Windows Forms
24.Windows Presentation Foundation
25.Windows Communication Foundation
26.Workflow
27.2D
28.Design Patterns
29.Windows
30.XML
31.XML LINQ
32.ADO.Net
33.Network
34.Directory Services
35.Security
36.unsafe
C# / C Sharp
C# / C Sharp by API
C# / CSharp Open Source
C# / CSharp Tutorial » GUI Windows Forms » Binder 
23.86.1.extends Binder to create your own binder
using System;
using System.Reflection;
using System.Globalization;
  class MyClass
  {
    DateTime[] dateTimes = new DateTime[10];
    public DateTime this[int index]
    {
      getreturn dateTimes[index]}
      setdateTimes[index= value;}
    }
    
    
    private DateTime dateOfBirth;
    public DateTime DateOfBirth
    {
        getreturn dateOfBirth; }
        setdateOfBirth = value; }
    }
      
    public void Test()
    {
      Console.WriteLine("Test method called");
    }
    
    
    private string field;
    
    public string Property
    
      getreturn field; }
      setfield = value; }
    }
    
  }


    class MainClass{
    
    static void Main(string[] args)
    {
      Type type = typeof(MyClass);
      object o = Activator.CreateInstance(type);
      type.InvokeMember"DateOfBirth"
        BindingFlags.Instance | BindingFlags.SetProperty |
        BindingFlags.Public, new DateTimeBinder()
        o, new object[]{@"02/12/1966"});
        
      Console.WriteLine(((MyClass)o).DateOfBirth);

    }
    }    
    public class DateTimeBinder : Binder
    {
      public override MethodBase BindToMethod(
        BindingFlags bindingAttr,
        MethodBase[] match,
        ref object[] args,
        ParameterModifier[] modifiers,
        CultureInfo culture,
        string[] names,
        out object state)
      {
        state = null;
        return match.Length == ? match[0null;
      }
      
      public override FieldInfo BindToField(
        BindingFlags bindingAttr,
        FieldInfo[] match,
        object value,
        CultureInfo culture)
      {
        return null;
      }
      
      public override MethodBase SelectMethod(
        BindingFlags bindingAttr,
        MethodBase[] match,
        Type[] types,
        ParameterModifier[] modifiers)
      {
        return null;
      }
      
      public override PropertyInfo SelectProperty(BindingFlags bindingAttr,PropertyInfo[] match,Type returnType,Type[] indexes,ParameterModifier[] modifiers){
        return null;
      }
      
      public override object ChangeType(object value,Type type,CultureInfo culture)
      {
        if value.GetType() != typeof(string)) return value;
        try
        {
          return Convert.ToDateTime(value);
        }
        catch
        {
          return value;
        }
      }
      public override void ReorderArgumentArray(ref object[] args,object state){}
    }
23.86.Binder
23.86.1.extends Binder to create your own binder
23.86.2.extends ISupportInitialize
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.