|
using System;
using System.Collections.Generic;
using System.Text;
using System.Reflection;
namespace FormulaEditor
{
/// <summary>
/// Acceptor of inequality opreation
/// </summary>
public class EqualityAcceptor : IBinaryAcceptor
{
/// <summary>
/// The singleton
/// </summary>
public static readonly EqualityAcceptor Object = new EqualityAcceptor();
/// <summary>
/// Constructor
/// </summary>
private EqualityAcceptor()
{
}
/// <summary>
/// Accepts operation
/// </summary>
/// <param name="typeA">Type of left part</param>
/// <param name="typeB">Type of right part</param>
/// <returns>Accepted operation</returns>
public IObjectOperation Accept(object typeA, object typeB)
{
if ((typeA is object[]) & (typeB is object[]))
{
object[] oa = typeA as object[];
object[] ob = typeB as object[];
Type tA = oa[0].GetType();
Type tB = ob[0].GetType();
string pA = oa[1] as string;
string pB = ob[1] as string;
PropertyInfo iA = tA.GetProperty(pA);
PropertyInfo iB = tB.GetProperty(pB);
if (iA.GetValue(oa[0], null).GetType() == iA.GetValue(ob[0], null).GetType())
{
return EqualityOperation.Object;
}
}
if ((typeA is object[]))
{
object[] oa = typeA as object[];
Type tA = oa[0].GetType();
string pA = oa[1] as string;
PropertyInfo iA = tA.GetProperty(pA);
if (iA.GetValue(oa[0], null).GetType() == typeB.GetType())
{
return EqualityOperation.Object;
}
}
if ((typeB is object[]))
{
object[] ob = typeB as object[];
Type tB = ob[0].GetType();
string pB = ob[1] as string;
PropertyInfo iB = tB.GetProperty(pB);
if (iB.GetValue(ob[0], null).GetType() == typeA.GetType())
{
return EqualityOperation.Object;
}
}
if (!typeA.Equals(typeB))
{
throw new Exception("Different types in equality");
}
return EqualityOperation.Object;
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.
A list of licenses authors might use can be found here
Ph. D. Petr Ivankov worked as scientific researcher at Russian Mission Control Centre since 1978 up to 2000. Now he is engaged by Aviation training simulators http://dinamika-avia.com/ . His additional interests are:
1) Noncommutative geometry
http://front.math.ucdavis.edu/author/P.Ivankov
2) Literary work (Russian only)
http://zhurnal.lib.ru/editors/3/3d_m/
3) Scientific articles
http://arxiv.org/find/all/1/au:+Ivankov_Petr/0/1/0/all/0/1