public static void RootMethod(IRootingServiceProvider rootProvider, MethodDesc method, string reason) { // Make sure we're not putting something into the graph that will crash later. LibraryRootProvider.CheckCanGenerateMethod(method); rootProvider.AddReflectionRoot(method, reason); }
void ICompilationRootProvider.AddCompilationRoots(IRootingServiceProvider rootProvider) { // We go over all the types and members that need a runtime artifact present in the // compiled executable and root it. const string reason = "Reflection"; foreach (var pair in _reflectableTypes) { if ((pair.Value & MetadataCategory.RuntimeMapping) != 0) { rootProvider.AddCompilationRoot(pair.Key, reason); } } foreach (var pair in _reflectableMethods) { if ((pair.Value & MetadataCategory.RuntimeMapping) != 0) { MethodDesc method = pair.Key; rootProvider.AddReflectionRoot(method, reason); } } foreach (var pair in _reflectableFields) { if ((pair.Value & MetadataCategory.RuntimeMapping) != 0) { FieldDesc field = pair.Key; // We only care about static fields at this point. Instance fields don't need // runtime artifacts generated in the image. if (field.IsStatic && !field.IsLiteral) { if (field.IsThreadStatic) { rootProvider.RootThreadStaticBaseForType(field.OwningType, reason); } else if (field.HasGCStaticBase) { rootProvider.RootGCStaticBaseForType(field.OwningType, reason); } else { rootProvider.RootNonGCStaticBaseForType(field.OwningType, reason); } } } } foreach (var type in _typesWithRootedCctorContext) { rootProvider.RootNonGCStaticBaseForType(type, reason); } }
void ICompilationRootProvider.AddCompilationRoots(IRootingServiceProvider rootProvider) { // We go over all the types and members that need a runtime artifact present in the // compiled executable and root it. const string reason = "Reflection"; foreach (var pair in _reflectableTypes) { if ((pair.Value & MetadataCategory.RuntimeMapping) != 0) { rootProvider.AddCompilationRoot(pair.Key, reason); } } foreach (var pair in _reflectableMethods) { if ((pair.Value & MetadataCategory.RuntimeMapping) != 0) { MethodDesc method = pair.Key; rootProvider.AddReflectionRoot(method, reason); } } foreach (var pair in _reflectableFields) { if ((pair.Value & MetadataCategory.RuntimeMapping) != 0) { FieldDesc field = pair.Key; rootProvider.AddReflectionRoot(field, reason); } } foreach (var type in _typesWithRootedCctorContext) { rootProvider.RootNonGCStaticBaseForType(type, reason); } }
public static void RootField(IRootingServiceProvider rootProvider, FieldDesc field, string reason) { // Make sure we're not putting something into the graph that will crash later. if (field.IsLiteral) { // Nothing to check } else if (field.IsStatic) { field.OwningType.ComputeStaticFieldLayout(StaticLayoutKind.StaticRegionSizes); } else { field.OwningType.ComputeInstanceLayout(InstanceLayoutKind.TypeOnly); } rootProvider.AddReflectionRoot(field, reason); }