Some of my friends who have made architecture may have been confused about what developers are doing and what they need to do. It is estimated that our solutions will be reflected in the same way.
Introduce your own Implementation ideas and code:
1. Define Interfaces
For example:
/// <Summary>
/// Defines the C # Calculation Rule interface for default column Configuration
/// By Jia Shiyi 2009-1-15
/// </Summary>
Public interface idefaultcalc
{
/// <Summary>
/// The configured parameter value string
/// </Summary>
String parameter {Get; set ;}
/// <Summary>
/// Account of the current user
/// </Summary>
String useraccount {Get; set ;}
/// <Summary>
/// The value returned by the calculation method is the default value.
/// </Summary>
/// <Returns> </returns>
Object getvalue ();
}
2. reflection interface
/// <Summary>
/// Reflection determines whether the class implements idefacalcalc
/// </Summary>
/// <Param name = "idefaultcalc"> </param>
/// <Returns> the error is true when null is returned. </returns>
Public static string isdefaultcalc (string idefaultcalc)
{
If (string. isnullorempty (idefacalcalc ))
{
Return "the class name cannot be blank. You must specify the class name that implements the idefacalcalc interface ";
}
Try
{
Int P = idefaultcalc. lastindexof (".");
If (P> 0)
{
Assembly calcassembly = assembly. Load (idefaultcalc. substring (0, P ));
Object calcobj = calcassembly. createinstance (idefacalcalc, true );
If (calcobj = NULL)
{
Return "class reflection error:" + idefaultcalc + "nonexistent ";
}
Else if (calcobj is idefaultcalc)
{
Return NULL;
}
Else
{
Return idefacalcalc + "class does not implement the idefacalcalc interface ";
}
}
Else
{
Return idefaultcalc + "the class must have a namespace ";
}
}
Catch (exception ex)
{
Return idefaultcalc + "class reflection error:" + ex. message;
}
}
3. provides an entry to the configuration implementation class.
Define the default string in XML, for example, myquery. Bal. querydefault.
4. the user must inherit the interface implementation class
For example:
Using system;
Using system. Collections. Generic;
Using system. text;
Using myquery. mycontrol;
Using myquery. Dal;
Using myquery. utils;
Using system. Web;
Namespace Pasa. Bal
{
/// <Summary>
/// Implement the column computing interface for the query template foot
/// By Jia Shiyi 2009-1-28
/// </Summary>
Public class querydefault: idefaultcalc
{
# Region idefaultcalc members
Private string _ parameter = NULL;
/// <Summary>
/// The configured parameter value string
/// </Summary>
Public String Parameter
{
Get
{
Return _ parameter;
}
Set
{
_ Parameter = value;
}
}
Private string _ useraccount = NULL;
/// <Summary>
/// Account of the current user
/// </Summary>
Public String useraccount
{
Get
{
Return _ useraccount;
}
Set
{
_ Useraccount = value;
}
}
# Endregion
/// <Summary>
/// Return the value calculated by parameter.
/// Note that when there are more than 10 else if statements, we recommend that you create an implementation Class Based on this class, and configure the class name with the new implementation.
/// </Summary>
/// <Returns> </returns>
Public object getvalue ()
{
If (string. isnullorempty (parameter ))
{
Return NULL;
}
# Region custom processing
Else if ("getdate". Equals (parameter, stringcomparison. currentcultureignorecase ))
{
Return datetime. Today. tostring ();
}
# Endregion
Else
{
Return NULL;
}
}
}
}
Welcome to: http: // 121.18.78.216, which is a demonstration platform for ease of query and analysis, workflow, content management, and project management.