示例#1
0
 static AssemblyState GetAssemblyState(DmdAssembly assembly)
 {
     if (assembly.TryGetData(out AssemblyState? state))
     {
         return(state);
     }
     return(CreateAssemblyState(assembly));
 }
示例#2
0
 static DmdType?GetType(DmdAssembly assembly, object?value)
 {
     if (value is DmdType type)
     {
         return(type);
     }
     if (value is string typeName)
     {
         return(assembly.GetType(typeName, DmdGetTypeOptions.None));
     }
     return(null);
 }
示例#3
0
            public AssemblyState(DmdAssembly assembly)
            {
                dict = new Dictionary <TypeKey, DmdType>();
                var proxyAttr = assembly.AppDomain.GetWellKnownType(DmdWellKnownType.System_Diagnostics_DebuggerTypeProxyAttribute, isOptional: true);

                Debug2.Assert(!(proxyAttr is null));
                if (!(proxyAttr is null))
                {
                    foreach (var ca in assembly.CustomAttributes)
                    {
                        if (ca.AttributeType != proxyAttr)
                        {
                            continue;
                        }
                        if (ca.ConstructorArguments.Count != 1)
                        {
                            continue;
                        }
                        var proxyType = DebuggerTypeProxyFinder.GetType(assembly, ca.ConstructorArguments[0].Value);
                        if (proxyType is null)
                        {
                            continue;
                        }

                        DmdType?targetType = null;
                        foreach (var namedArg in ca.NamedArguments)
                        {
                            var prop = namedArg.MemberInfo as DmdPropertyInfo;
                            if (prop is null)
                            {
                                continue;
                            }
                            if (prop.Name == nameof(DebuggerTypeProxyAttribute.Target) || prop.Name == nameof(DebuggerTypeProxyAttribute.TargetTypeName))
                            {
                                targetType = DebuggerTypeProxyFinder.GetType(assembly, namedArg.TypedValue.Value);
                                break;
                            }
                        }
                        if (targetType is null)
                        {
                            continue;
                        }

                        dict[new TypeKey(targetType)] = proxyType;
                    }
                }
            }
示例#4
0
        static AssemblyState CreateAssemblyState(DmdAssembly assembly)
        {
            var state = new AssemblyState(assembly);

            return(assembly.GetOrCreateData(() => state));
        }