Beispiel #1
0
    public IFieldSimpleItem Create()
    {
        IFieldSimpleItem created = InternalCreate();

        CheckCreatedType(created);
        return(created);
    }
    private void CheckCreatedType(IFieldSimpleItem item)
    {
        Type inspect   = this.GetType();
        bool keepgoing = true;

        while (keepgoing)
        {
            string name = inspect.FullName;
            if (CheckDelegateMethods.ContainsKey(name))
            {
                var checkDelegate = CheckDelegateMethods[name];
                if (!checkDelegate(item))
                {
                    throw new Exception("failed check");
                }
            }
            if (inspect == typeof(A))
            {
                keepgoing = false;
            }
            else
            {
                inspect = inspect.BaseType;
            }
        }

        // base class doesn't care. compiler guarantees IFieldSimpleItem
    }
Beispiel #3
0
 protected override void CheckCreatedType(IFieldSimpleItem item)
 {
     base.CheckCreatedType(item);
     if (!(item is IFieldNormalItem))
     {
         throw new Exception("I need a normal item.");
     }
 }
Beispiel #4
0
 protected virtual void CheckCreatedType(IFieldSimpleItem item)
 {
     // base class doesn't care. compiler guarantees IFieldSimpleItem
 }