2 u011978868 u011978868 于 2013.10.09 14:34 提问

各位大神们帮帮忙C#反射

namespace SimpleRuleEngine
{
public class AdvanceActivity :Activity
{

    protected Role PreConditionRole = null;

    [XmlAttribute(DataType = "string", AttributeName = "PreConditionRoleId")]
    public String PreConditionRoleId
    {
        get;
        set;
    }

    public override void prepare(List<Role> roles)
    {
        foreach (Role role in roles)
        {
            if (role.RoleId.CompareTo(this.ConditionRoleId) == 0)
            {
                this.conditionRole = role;
                continue;
            }
            else if(role.RoleId.CompareTo(this.PreConditionRoleId)==0)
            {
                this.PreConditionRole = role;
                continue;
            }
        }


        if (conditionRole == null || PreConditionRole ==null)
        {
            throw new ArgumentException();
        }
    }
}

public class SnackApptizerCommissionActivity :AdvanceActivity
{

    public override void excute(SellData[] dataIn, CommissionData dataOut)
    {
        Dictionary<SellData, bool> preConditionRes = new Dictionary<SellData, bool>();
        for (int i = 0; i < dataIn.Length; i++)
        {
            List<ChosenDish> chosenDishes = dataIn[i].ChosenDish;
            for (int j = 0; j < chosenDishes.Count; j++)
            {
                if (PreConditionRole.check(chosenDishes[j].DishUnitId))
                {
                    preConditionRes.Add(dataIn[i], true);
                    break;
                }
                else if (j == chosenDishes.Count - 1)
                {
                    preConditionRes.Add(dataIn[i], false);
                    break;
                }
            }
        }

        foreach (SellData data in preConditionRes.Keys)
        {
            if (preConditionRes[data])
            {
                for (int z = 0; z < data.ChosenDish.Count; z++)
                {

                    if (conditionRole.check(data.ChosenDish[z].DishUnitId))
                    {
                        float commission = getCommission(data.ChosenDish[z]);
                        dataOut.CommissionChosenDish.Add(data.ChosenDish[z], new Commission(ActivytiName, commission));
                    }
                }
            }
        }
    }

}

public class WineCommissionActivity : AdvanceActivity
{

    [XmlAttribute(DataType = "float", AttributeName = "IncrasePrecent")]
    public float IncrasePrecent
    {
        get;
        set;
    }

    public override void excute(SellData[] dataIn, CommissionData dataOut)
    {
        Dictionary<SellData, bool> preConditionRes = new Dictionary<SellData, bool>();
        for (int i = 0; i < dataIn.Length; i++)
        {
            List<ChosenDish> chosenDishes = dataIn[i].ChosenDish;
            for (int j = 0; j < chosenDishes.Count; j++)
            {
                if (PreConditionRole.check(chosenDishes[j].DishUnitId))
                {
                    preConditionRes.Add(dataIn[i], true);
                    break;
                }
                else if( j== chosenDishes.Count -1 )
                {
                    preConditionRes.Add(dataIn[i], false);
                    break;
                }
            }
        }

        foreach (SellData data in preConditionRes.Keys)
        {
            if (preConditionRes[data])
            {
                for (int z = 0; z < data.ChosenDish.Count; z++)
                {
                    if (conditionRole.check(data.ChosenDish[z].DishUnitId))
                    {
                        float commission = getWineCommission(data.ChosenDish[z], true);
                        dataOut.CommissionChosenDish.Add(data.ChosenDish[z], new Commission(ActivytiName, commission));
                    }
                }
            }
            else
            {
                for (int z = 0; z < data.ChosenDish.Count; z++)
                {

                    if (conditionRole.check(data.ChosenDish[z].DishUnitId))
                    {
                        float commission = getWineCommission(data.ChosenDish[z], false);
                        dataOut.CommissionChosenDish.Add(data.ChosenDish[z], new Commission(ActivytiName, commission));
                    }
                }
            }
        }
    }

    private float getWineCommission(ChosenDish chosenDish,bool preCondition)
    {
        if (conditionRole.getCommissionType(chosenDish.DishUnitId) == LogicType.absolute)
        {
            return conditionRole.getCommissionValue(chosenDish.DishUnitId);
        }
        else
        {
            if(preCondition)
               return chosenDish.Price * (conditionRole.getCommissionValue(chosenDish.DishUnitId) + IncrasePrecent);
            else
               return chosenDish.Price * conditionRole.getCommissionValue(chosenDish.DishUnitId);
        }
    }
}

如何取得AdvanceActivityWineCommissionActivity,SnackApptizerCommissionActivity这三个值????

Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!