Ejemplo n.º 1
0
        /// <summary>
        /// Gets the CLR static variable.
        /// </summary>
        /// <param name="name">The name.</param>
        /// <param name="appDomain">The application domain.</param>
        /// <returns>Static variable if found</returns>
        public Variable GetClrVariable(string name, CsDebugScript.CLR.AppDomain appDomain)
        {
            int variableNameIndex = name.LastIndexOf('.');
            string typeName = name.Substring(0, variableNameIndex);
            var clrType = ClrModule.GetTypeByName(typeName);

            if (clrType == null)
            {
                throw new Exception($"CLR type not found {typeName}");
            }

            string variableName = name.Substring(variableNameIndex + 1);
            var staticField = clrType.GetStaticFieldByName(variableName);

            if (staticField == null)
            {
                throw new Exception($"Field {staticField} wasn't found in CLR type {typeName}");
            }

            var address = staticField.GetAddress(appDomain.ClrAppDomain);
            Variable field = Variable.CreateNoCast(FromClrType(clrType), address, variableName);

            return Variable.UpcastClrVariable(field);
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Finds metadata that comes from the specified module or first if not found.
 /// </summary>
 /// <param name="metadatas">The metadatas.</param>
 /// <param name="module">The module.</param>
 public static UserTypeMetadata FromModuleOrFirst(this UserTypeMetadata[] metadatas, CsDebugScript.Module module)
 {
     foreach (var metadata in metadatas)
         if (metadata.ModuleName == module.Name)
             return metadata;
     return metadatas.First();
 }