Example #1
0
 private string getCommentsText(IField field)
 {
     // we'll assume that all dictionary lookups work, and if they don't return empty.
     try
     {
         IStructField structure = field as IStructField;
         if (structure != null)
         {
             return(commentsIndex[structure.TypeName]["(this)"]); // keyword for info about a struct itself
         }
         return(commentsIndex[field.Parent.TypeName][field.Name]);
     }
     catch
     {
         return("");
     }
 }
 /// <summary>
 /// Array-style access to fields.
 /// </summary>
 /// <param name="identifier">Name of the field you want to look up.</param>
 /// <returns>IField object representing the field with that identifier</returns>
 public IField this[string identifier]
 {
     get
     {
         string[] parts = identifier.Split('.');
         try
         {
             int          index  = 0;
             IStructField parent = this;
             // this loop will fail if we access members of a primitive or have a bad name somewhere
             while (index < parts.Length - 1) // exhaust all dot-following, leaving only the final identifier
             {
                 parent = (IStructField)parent[parts[index++]];
             }
             return(parent.Fields.First(f => f.Name == parts[index]));
         }
         catch
         {
             throw new ArgumentException("Identifier " + identifier + " not found.", identifier);
         }
     }
 }
Example #3
0
        private static TFields GetStructFields <TFields>(StructMetadata metadata)
            where TFields : class, new()
        {
            if (metadata.Fields != null)
            {
                return((TFields)metadata.Fields);
            }

            var pyVersion = metadata.Process.GetPythonRuntimeInfo().LanguageVersion;

            TFields fields = new TFields();

            foreach (var fieldInfo in typeof(TFields).GetFields())
            {
                var fieldType = fieldInfo.FieldType;
                if (fieldType.GetInterfaces().Contains(typeof(IStructField)))
                {
                    Debug.Assert(!fieldInfo.IsInitOnly);

                    var name = GetFieldName(fieldInfo, pyVersion);
                    if (string.IsNullOrEmpty(name))
                    {
                        continue;
                    }

                    long         offset = metadata.Symbol.GetFieldOffset(name);
                    IStructField field  = (IStructField)Activator.CreateInstance(fieldType);
                    field.Process = metadata.Process;
                    field.Offset  = offset;
                    fieldInfo.SetValue(fields, field);
                }
            }

            metadata.Fields = fields;
            return(fields);
        }