.


:




:

































 

 

 

 


M. Invoke(reflectOb, null);




}

Break;

case 1: //

if (pi[0].ParameterType == typeof(int)) { object[] args = new object[1]; args[0] = 14;

If ((bool) m.Invoke(reflectOb, args))

Console.WriteLine (" 14 x "); else

Console.WriteLine (" 14 ");

}

Break;

case 2: //

if((pi[0].ParameterType == typeof(int)) &&

(pi[1].ParameterType == typeof(int))) {

object[] args = new object[2]; args[0] = 9;

args[l] = 18;

M.Invoke(reflectOb, args);

}

else if((pi[0].ParameterType == typeof(double)) &&

(pi[1].ParameterType == typeof(double))) {

object[] args = new object [2]; args[0] = 1J12; args[l] = 23.4; m.Invoke(reflectOb, args);

}

Break;

}

Console.WriteLine();

}

}

}

.

: MyClass MyClass(int).

: 10, : 10

reflectOb.

Sum : 20

IsBetween

14

Set

Set (int, int). : 9, : 18 Set

Set(double, double). : 1, : 23

Show

: 1, : 23

, . -, , MyClass. BindingFlags GetMethods (), , . -, , switch. .

C# , (), , , .. , , , . , . , , , .

, System. Attribute. Attribute. Attribute , . Attribute. , ErrorAttribute , .

AttributeUsage. , . , .

, . . , , , . .

[AttributeUsage(AttributeTargets.All) ] public class RemarkAttribute: Attribute {

string pri_remark; // Remark

public RemarkAttribute(string comment) { pri_remark = comment;

}

public string Remark { v get {

Return pri_remark;

}

}

}

.

RemarkAttribute. AttributeUsage, , RemarkAttribute . AttributeUsage , . .

RemarkAttribute, Attribute. RemarkAttribute pri_remark, Remark. , . (, Remark set, , .) , Remark. RemarkAttribute, .

, . , , . , RemarkAttribute .

[RemarkAttribute(" .")] class UseAttrib {

//...

}

RemarkAttribute, " . 11 UseAttrib.





:


: 2016-12-03; !; : 369 |


:

:

, .
==> ...

2015 - | 1815 -


© 2015-2024 lektsii.org - -

: 0.011 .