1: private void ExamineCodeElement(CodeElement codeElement)
2: {
3: try
4: {
5: if (codeElement.Kind == vsCMElement.vsCMElementClass)
6: {
7: CodeClass cClass = (CodeClass)codeElement;
8: MessageBox.Show("Class name is " + codeElement.Name);
9:
10: foreach (CodeAttribute attr in cClass.Attributes)
11: {
12: // Name of the attribute
13: if (!string.IsNullOrEmpty(attr.Name))
14: {
15: MessageBox.Show("Attributes Defined for class " + codeElement.Name + " is " + attr.Name);
16: }
17: // Values Defied in attribute
18: MessageBox.Show("Value of attribute is " + attr.Value);
19: }
20:
21: // To change the name of the class defined in the c# source code file
22: cClass.Name = "NewClassName";
23: }
24: if (codeElement.Kind == vsCMElement.vsCMElementProperty)
25: {
26: CodeProperty cProperty = (CodeProperty)codeElement;
27: MessageBox.Show("Property name is " + codeElement.Name);
28: foreach (CodeAttribute attr in cProperty.Attributes)
29: {
30: if (!string.IsNullOrEmpty(attr.Name))
31: {
32: MessageBox.Show("Attributes Defined for property " + codeElement.Name + " is " + attr.Name);
33: }
34: }
35:
36: // To change the name of the propert defined in the c# source code file
37: cProperty.Name = "NewClassName";
38: }
39:
40: if (codeElement.Kind == vsCMElement.vsCMElementFunction)
41: {
42: CodeFunction cFucntion = (CodeFunction)codeElement;
43: MessageBox.Show("Function name is " + codeElement.Name);
44:
45: foreach (CodeAttribute attr in cFucntion.Attributes)
46: {
47: if (!string.IsNullOrEmpty(attr.Name))
48: {
49: MessageBox.Show("Attributes Defined for function " + codeElement.Name + " is " + attr.Name);
50: }
51: }
52:
53: // To change the name of the property defined in the c# source code file
54: cFucntion.Name = "NewcFucntionName";
55:
56: }
57:
58: if (codeElement.Kind == vsCMElement.vsCMElementNamespace)
59: {
60: CodeNamespace cNamespace = (CodeNamespace)codeElement;
61: MessageBox.Show("Namespace name is " + codeElement.Name);
62:
63: // To change the name of the namespace defined in the c# source code file
64: cNamespace.Name = "NewcNameSpaceName";
65: }
66:
67: if (codeElement.Kind == vsCMElement.vsCMElementStruct)
68: {
69: CodeStruct CodeStruct = (CodeStruct)codeElement;
70: MessageBox.Show("Struct name is " + codeElement.Name);
71:
72: // To change the name of the Struct defined in the c# source code file
73: CodeStruct.Name = "NewcStructName";
74: }
75:
76: if (codeElement.Kind == vsCMElement.vsCMElementEnum)
77: {
78: CodeEnum CodeEnum = (CodeEnum)codeElement;
79: MessageBox.Show("Enum name is " + codeElement.Name);
80:
81: // To change the name of the Enum defined in the c# source code file
82: CodeEnum.Name = "NewcEnumName";
83: }
84:
85: if (codeElement.Kind == vsCMElement.vsCMElementDelegate)
86: {
87: CodeDelegate CodeDelegate = (CodeDelegate)codeElement;
88: MessageBox.Show("Delegate name is " + codeElement.Name);
89:
90: // To change the name of the delegate defined in the c# source code file
91: CodeDelegate.Name = "NewcDelegateName";
92: }
93:
94: if (codeElement.Kind == vsCMElement.vsCMElementEvent)
95: {
96: CodeEvent CodeEvent = (CodeEvent)codeElement;
97: MessageBox.Show("Event name is " + codeElement.Name);
98:
99: // To change the name of the Event defined in the c# source code file
100: CodeEvent.Name = "NewcEventName";
101: }
102:
103: foreach (CodeElement childElement in codeElement.Children)
104: {
105: ExamineCodeElement(childElement);
106: }
107: }
108: catch
109: {
110: //
111: }
112: }