Descriptor for a reference to a Nested Class
Inheritance: ClassRef
Example #1
0
 /// <summary>
 /// Add a nested class to this class
 /// </summary>
 /// <param name="name">Nested class name</param>
 /// <returns>Descriptor for the nested class "name"</returns>
 public NestedClassRef AddNestedClass(string name)
 {
     NestedClassRef nestedClass = (NestedClassRef)GetNested(name);
     if (nestedClass != null) DescriptorError(nestedClass);
     nestedClass = new NestedClassRef(this,name);
     AddToClassList(nestedClass);
     return nestedClass;
 }
Example #2
0
 internal static void Read(PEReader buff, TableRow[] typeRefs, bool resolve)
 {
     for (uint i=0; i < typeRefs.Length; i++) {
         uint resScopeIx = buff.GetCodedIndex(CIx.ResolutionScope);
         string name = buff.GetString();
         string nameSpace = buff.GetString();
         if (buff.CodedTable(CIx.ResolutionScope,resScopeIx) == MDTable.TypeRef)
             typeRefs[i] = new NestedClassRef(resScopeIx,nameSpace,name);
         else
             typeRefs[i] = new ClassRef(resScopeIx,nameSpace,name);
         typeRefs[i].Row = i+1;
     }
     if (resolve) {
         for (int i=0; i < typeRefs.Length; i++) {
             ((ClassRef)typeRefs[i]).ResolveParent(buff,false);
         }
     }
 }
Example #3
0
 internal static void GetClassRefs(PEReader buff, TableRow[] typeRefs, ReferenceScope paren, uint[] parIxs)
 {
     int num = typeRefs.Length;
     uint[] fieldStart = new uint[num+1], methStart = new uint[num+1], extends = new uint[num+1];
     for (int i=0; i < num; i++) {
         uint flags = buff.ReadUInt32();
         string name = buff.GetString();
         string nameSpace = buff.GetString();
         extends[i] = buff.GetCodedIndex(CIx.TypeDefOrRef);
         fieldStart[i] = buff.GetIndex(MDTable.Field);
         methStart[i] = buff.GetIndex(MDTable.Method);
         //Console.WriteLine("flags = " + Hex.Int(flags));
         if (i == 0) // ASSERT first entry is always <Module>
             typeRefs[i] = paren.GetDefaultClass();
         else if (isPublic(flags)) {
             if (parIxs[i] != 0) {
                 typeRefs[i] = new NestedClassRef(paren,nameSpace,name);
             } else {
                 typeRefs[i] = paren.GetExistingClass(nameSpace,name);
                 if (typeRefs[i] == null) {
                     typeRefs[i] = new ClassRef(paren,nameSpace,name);
                     paren.AddToClassList((ClassRef)typeRefs[i]);
                 }
             }
         }
     }
     fieldStart[num] = buff.GetTableSize(MDTable.Field)+1;
     methStart[num] = buff.GetTableSize(MDTable.Method)+1;
     // Find Nested Classes
     for (int i=0; i < typeRefs.Length; i++) {
         if ((typeRefs[i] != null) && (typeRefs[i] is NestedClassRef)) {
             NestedClassRef nRef = (NestedClassRef)typeRefs[i];
             ClassRef nPar = (ClassRef)typeRefs[parIxs[i]-1];
             if (nPar == null) {  // parent is private, so ignore
                 typeRefs[i] = null;
             } else {
                 nRef.SetParent(nPar);
                 nPar.AddToClassList(nRef);
             }
         }
         if (typeRefs[i] != null) {
             if (buff.GetCodedElement(CIx.TypeDefOrRef,extends[i]) == MSCorLib.mscorlib.ValueType())
                 ((ClassRef)typeRefs[i]).MakeValueClass();
             buff.SetElementPosition(MDTable.Field,fieldStart[i]);
             FieldDef.GetFieldRefs(buff,fieldStart[i+1]-fieldStart[i],(ClassRef)typeRefs[i]);
             buff.SetElementPosition(MDTable.Method,methStart[i]);
             MethodDef.GetMethodRefs(buff,methStart[i+1]-methStart[i],(ClassRef)typeRefs[i]);
         }
     }
 }