public void MethodCachingTest() { // Test that when we cache method names they are not re-read using DataTarget dt = TestTargets.Types.LoadFullDump(); dt.CacheOptions.CacheMethods = true; // We want to make sure we are getting the same string because it was cached, // not because it was interned dt.CacheOptions.CacheMethodNames = StringCaching.Cache; using ClrRuntime runtime = dt.ClrVersions.Single().CreateRuntime(); ClrModule module = runtime.GetModule("sharedlibrary.dll"); ClrType type = module.GetTypeByName("Foo"); ClrMethod method = type.GetMethod("Bar"); Assert.NotEqual(0ul, method.MethodDesc); // Sanity test ClrMethod method2 = type.GetMethod("Bar"); Assert.Equal(method, method2); Assert.Same(method, method2); string signature1 = method.Signature; string signature2 = method2.Signature; Assert.NotNull(signature1); Assert.Equal(signature1, signature2); Assert.Equal(signature1, method.Signature); Assert.Same(signature1, method.Signature); }
public void MethodHandleMultiDomainTests() { ulong[] methodDescs; using (DataTarget dt = TestTargets.AppDomains.LoadFullDump()) { ClrRuntime runtime = dt.ClrVersions.Single().CreateRuntime(); ClrModule module = runtime.GetModule("sharedlibrary.dll"); ClrType type = module.GetTypeByName("Foo"); ClrMethod method = type.GetMethod("Bar"); methodDescs = method.EnumerateMethodDescs().ToArray(); Assert.AreEqual(2, methodDescs.Length); } using (DataTarget dt = TestTargets.AppDomains.LoadFullDump()) { ClrRuntime runtime = dt.ClrVersions.Single().CreateRuntime(); ClrMethod method = runtime.GetMethodByHandle(methodDescs[0]); Assert.IsNotNull(method); Assert.AreEqual("Bar", method.Name); Assert.AreEqual("Foo", method.Type.Name); } using (DataTarget dt = TestTargets.AppDomains.LoadFullDump()) { ClrRuntime runtime = dt.ClrVersions.Single().CreateRuntime(); ClrMethod method = runtime.GetMethodByHandle(methodDescs[1]); Assert.IsNotNull(method); Assert.AreEqual("Bar", method.Name); Assert.AreEqual("Foo", method.Type.Name); } }
// Implementation of "GetMethod". protected override MethodInfo GetMethodImpl (String name, BindingFlags bindingAttr, Binder binder, CallingConventions callConvention, Type[] types, ParameterModifier[] modifiers) { CheckCreated(); return(type.GetMethod(name, bindingAttr, binder, callConvention, types, modifiers)); }
internal SingleMessageAccessor(string name) : base(name) { MethodInfo createBuilderMethod = ClrType.GetMethod("CreateBuilder", EmptyTypes); if (createBuilderMethod == null) { throw new ArgumentException("No public static CreateBuilder method declared in " + ClrType.Name); } createBuilderDelegate = ReflectionUtil.CreateStaticUpcastDelegate(createBuilderMethod); }
internal SingleMessageAccessor(FieldDescriptor field, string name, string containingOneofName, bool supportFieldPresence) : base(field, name, containingOneofName, supportFieldPresence) { MethodInfo createBuilderMethod = ClrType.GetMethod("CreateBuilder", ReflectionUtil.EmptyTypes); if (createBuilderMethod == null) { throw new ArgumentException("No public static CreateBuilder method declared in " + ClrType.Name); } createBuilderDelegate = ReflectionUtil.CreateStaticUpcastDelegate(createBuilderMethod); }
public void NoMethodCachingTest() { using DataTarget dt = TestTargets.Types.LoadFullDump(); dt.CacheOptions.CacheMethods = false; dt.CacheOptions.CacheMethodNames = StringCaching.None; using ClrRuntime runtime = dt.ClrVersions.Single().CreateRuntime(); ClrModule module = runtime.GetModule("sharedlibrary.dll"); ClrType type = module.GetTypeByName("Foo"); ClrMethod method = type.GetMethod("Bar"); Assert.NotEqual(0ul, method.MethodDesc); // Sanity test ClrMethod method2 = type.GetMethod("Bar"); Assert.Equal(method, method2); Assert.NotSame(method, method2); string signature1 = method.Signature; string signature2 = method2.Signature; Assert.NotNull(signature1); Assert.Equal(signature1, signature2); Assert.Equal(signature1, method.Signature); Assert.NotSame(signature1, method.Signature); Assert.NotSame(method2.Signature, method.Signature); // Ensure that we can swap this at runtime and that we get interned strings dt.CacheOptions.CacheMethodNames = StringCaching.Intern; Assert.NotNull(method.Signature); Assert.Same(method2.Signature, method.Signature); Assert.Same(method.Signature, string.Intern(method.Signature)); }
public void CompleteSignatureIsRetrievedForMethodsWithGenericParameters() { using DataTarget dt = TestTargets.AppDomains.LoadFullDump(); ClrRuntime runtime = dt.ClrVersions.Single().CreateRuntime(); ClrModule module = runtime.GetModule("sharedlibrary.dll"); ClrType type = module.GetTypeByName("Foo"); ClrMethod genericMethod = type.GetMethod("GenericBar"); string methodName = genericMethod.GetFullSignature(); Assert.Equal(')', methodName.Last()); }
public override ClrMethod GetMethodByHandle(ulong methodHandle) { if (methodHandle == 0) { return(null); } IMethodDescData methodDesc = GetMethodDescData(methodHandle); if (methodDesc == null) { return(null); } ClrType type = Heap.GetTypeByMethodTable(methodDesc.MethodTable); if (type == null) { return(null); } return(type.GetMethod(methodDesc.MDToken)); }
public void MethodHandleSingleDomainTests() { ulong methodDesc; using (DataTarget dt = TestTargets.Types.LoadFullDump()) { using ClrRuntime runtime = dt.ClrVersions.Single().CreateRuntime(); ClrModule module = runtime.GetModule("sharedlibrary.dll"); ClrType type = module.GetTypeByName("Foo"); ClrMethod method = type.GetMethod("Bar"); methodDesc = method.MethodDesc; Assert.NotEqual(0ul, methodDesc); } using (DataTarget dt = TestTargets.Types.LoadFullDump()) { using ClrRuntime runtime = dt.ClrVersions.Single().CreateRuntime(); ClrMethod method = runtime.GetMethodByHandle(methodDesc); Assert.NotNull(method); Assert.Equal("Bar", method.Name); Assert.Equal("Foo", method.Type.Name); } using (DataTarget dt = TestTargets.Types.LoadFullDump()) { using ClrRuntime runtime = dt.ClrVersions.Single().CreateRuntime(); ClrModule module = runtime.GetModule("sharedlibrary.dll"); ClrType type = module.GetTypeByName("Foo"); ClrMethod method = type.GetMethod("Bar"); Assert.Equal(methodDesc, method.MethodDesc); Assert.Equal(method, runtime.GetMethodByHandle(methodDesc)); } }