ClassLib_Test.MyClass2.TestIsDefined_Type C# (CSharp) Method

TestIsDefined_Type() public method

public TestIsDefined_Type ( MemberInfo mem ) : bool
mem System.Reflection.MemberInfo
return bool
 override public bool TestIsDefined_Type (MemberInfo mem)
   {
   Util.print ("\n\n" + this.GetType ().ToString () + " - TestIsDefined_Type() started.");
   Util.print ("For: " + mem.GetType ().ToString () + "\n");
   string strLoc="L_2_000";
   bool isattr = false;
   try  
     {
     do
       {
       iCountTestcases++;
       strLoc="L_2_001";
       iCountTestcases++;
       strLoc="L_2_002.2";
       isattr = Attribute.IsDefined (mem, typeof (ClassLib_Attributes.CA_AMfalse_INfalse), false);
       if (isattr) {
       iCountErrors++;
       Util.printerr ("E_2_gfh4 - IsDefined returned true");
       }
       iCountTestcases++;
       strLoc="L_3_002.2";
       isattr = Attribute.IsDefined (mem, typeof (ClassLib_Attributes.CA_AMfalse_INtrue), true);
       if ((mem is ConstructorInfo) || (mem is FieldInfo) ) {
       if (isattr) {
       iCountErrors++;
       Util.printerr ("E_3_fkj2 - IsDefined returned true");
       }				
       }
       else if (!isattr) {					
       iCountErrors++;
       Util.printerr ("E_3_gfh4 - IsDefined returned false");
       }
       iCountTestcases++;
       strLoc="L_4_002.2";
       isattr = Attribute.IsDefined (mem, typeof (ClassLib_Attributes.CA_AMtrue_INtrue), true);
       if ((mem is ConstructorInfo) || (mem is FieldInfo)) {
       if (isattr) {
       iCountErrors++;
       Util.printerr ("E_4_fkj2 - IsDefined returned true");
       }				
       }
       else if (!isattr) {	
       iCountErrors++;
       Util.printerr ("E_4_gfh4 - IsDefined returned false");
       }
       iCountTestcases++;
       strLoc="L_5_002.2";
       isattr = Attribute.IsDefined (mem, typeof (ClassLib_Attributes.CA_AMtrue_INfalse), false);
       if (!isattr) {
       iCountErrors++;
       Util.printerr ("E_5_gfh4 - IsDefined returned false");
       }
       iCountTestcases++;
       strLoc="L_6_002.2";
       isattr = Attribute.IsDefined (mem, typeof (System.Attribute), true);
       if (!isattr) {
       iCountErrors++;
       Util.printerr ("E_6_gfh4 - IsDefined returned false");
       }
       } while ( false );
     }
   catch( Exception exc_runTest ) {
   ++iCountErrors;
   Util.printerr ("Err_333un! - Uncaught Exception caught in TestIsDefined_Type(); strLoc == " + strLoc);
   Util.printexc (exc_runTest);
   Util.print (exc_runTest.StackTrace);
   }
   if ( iCountErrors == 0 ) {   return true; }
   else {  return false;}
   }
}

Same methods

MyClass2::TestIsDefined_Type ( ParameterInfo param ) : bool

Usage Example

        public bool RunTest()
        {
            print(strPath + strTest + "  RunTest() started.");
            string        strLoc   = "L_000";
            MyClass       myclass  = new MyClass("myclass");
            MyClass2      myclass2 = new MyClass2("myclass2");
            bool          isattr   = false;
            ParameterInfo param    = null;
            ParameterInfo param2   = null;
            Type          type     = null;
            Type          type2    = null;

            try
            {
                iCountTestcases++;
                strLoc = "L_200_001";
                param  = this.GetType().GetMethod("Dummy").GetParameters() [0];
                if (param == null)
                {
                    iCountErrors++;
                    Util.printerr("E_200_dj13 - param == null");
                }
                iCountTestcases++;
                strLoc = "L_200_001.2";
                isattr = Attribute.IsDefined(param, typeof(System.Attribute), true);
                if (isattr)
                {
                    iCountErrors++;
                    Util.printerr("E_200_oi32 - IsDefined returned true!c");
                }
                iCountTestcases++;
                strLoc = "L_200_001.3";
                try {
                    isattr = Attribute.IsDefined(param, typeof(System.Int32), true);
                    iCountErrors++;
                    Util.printerr("E_200_oi32 - Should 've thrown ArgExc");
                }
                catch (ArgumentException) {
                }
                iCountTestcases++;
                strLoc = "L_200_002";
                type   = myclass.GetType();
                param  = type.GetMethod("MyMethod").GetParameters() [0];
                if (param == null)
                {
                    iCountErrors++;
                    Util.printerr("E_200_75yhg - param == null");
                }
                iCountTestcases++;
                strLoc = "L_200_002.1";
                try {
                    isattr = Attribute.IsDefined(param, null, false);
                    iCountErrors++;
                    Util.printerr("E_200_oi32 - Should 've thrown ArgNullExc");
                }
                catch (ArgumentException) {
                }
                iCountTestcases++;
                strLoc = "L_200_002.1.2";
                try {
                    isattr = Attribute.IsDefined((ParameterInfo)null, typeof(ClassLib_Attributes.CA_AMfalse_INfalse), false);
                    iCountErrors++;
                    Util.printerr("E_200_oi322 - Should 've thrown ArgNullExc");
                }
                catch (ArgumentException) {
                }
                type = myclass.GetType();
                iCountTestcases++;
                strLoc = "L_200_003.4";
                param  = type.GetConstructor(new Type [] { typeof(String) }).GetParameters() [0];
                myclass.TestIsDefined_Type(param);
                iCountTestcases++;
                strLoc = "L_200_003.5";
                param  = type.GetMethod("MyMethod").GetParameters() [0];
                myclass.TestIsDefined_Type(param);
                type2 = myclass2.GetType();
                iCountTestcases++;
                strLoc = "L_2_200_003.4";
                param2 = type2.GetConstructor(new Type [] { typeof(String) }).GetParameters() [0];
                myclass2.TestIsDefined_Type(param2);
                iCountTestcases++;
                strLoc = "L_2_200_003.5";
                param2 = type2.GetMethod("MyMethod").GetParameters() [0];
                myclass2.TestIsDefined_Type(param2);
            }
            catch (Exception exc_runTest) {
                ++myclass2.iCountErrors;
                printerr("Err_888un! - Uncaught Exception caught in runTest(); strLoc == " + strLoc);
                printexc(exc_runTest);
                print(exc_runTest.StackTrace);
            }
            iCountErrors    = myclass.iCountErrors + myclass2.iCountErrors;
            iCountTestcases = myclass.iCountTestcases + myclass2.iCountTestcases;
            if (iCountErrors == 0)
            {
                return(true);
            }
            else
            {
                print("Related Bugs: " + strBug);
                print("FAiL!   " + strPath + strTest + "  iCountErrors==" + iCountErrors.ToString());
                return(false);
            }
        }
All Usage Examples Of ClassLib_Test.MyClass2::TestIsDefined_Type