当前位置: 首页>>代码示例>>C#>>正文


C# Library.getType方法代码示例

本文整理汇总了C#中Library.getType方法的典型用法代码示例。如果您正苦于以下问题:C# Library.getType方法的具体用法?C# Library.getType怎么用?C# Library.getType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Library的用法示例。


在下文中一共展示了Library.getType方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: testConstructedGenericClass

		public void testConstructedGenericClass() {
			var typeSystem = new Library(new String[] { bin });
			var typeInfo = typeSystem.getType("stab/bytecode/test/classes/GenericClass");
			var args = new ArrayList<TypeInfo>();
			args.add(typeSystem.getType("java/lang/String"));
			doTest("ConstructedGenericClass", typeSystem.getGenericType(typeInfo, args));
		}
开发者ID:nagyistoce,项目名称:cnatural-language,代码行数:7,代码来源:TypeSystemTest.stab.cs

示例2: testBaseTypes

		public void testBaseTypes() {
			var typeSystem = new Library(new String[] {});
			var stringType = typeSystem.getType("java/lang/String");
			var types = Query.asIterable(new TypeInfo[] {
				typeSystem.getType("java/lang/Object"),
				typeSystem.getType("java/io/Serializable"),
				typeSystem.getType("java/lang/CharSequence"),
				typeSystem.getGenericType(typeSystem.getType("java/lang/Comparable"), Collections.singletonList(stringType))
			});
			var publicBaseTypes = stringType.getBaseTypes().where(p => p.IsPublic);
			Assert.assertTrue(publicBaseTypes.union(types).sequenceEqual(publicBaseTypes));
			Assert.assertFalse(publicBaseTypes.except(types).any());
		}
开发者ID:nagyistoce,项目名称:cnatural-language,代码行数:13,代码来源:TypeSystemTest.stab.cs

示例3: testObjectMethods

		public void testObjectMethods() {
			var typeSystem = new Library(new String[] {});
			var typeInfo = typeSystem.getType("java/lang/Object");
			var names = Query.asIterable(new String[] { 
				"<init>", "equals", "getClass", "hashCode", "notify", "notifyAll", "toString", "wait", "wait", "wait" });
			Assert.assertTrue(typeInfo.Methods.where(p => p.IsPublic).select(p => p.Name).orderBy(p => p).sequenceEqual(names));
		}
开发者ID:nagyistoce,项目名称:cnatural-language,代码行数:7,代码来源:TypeSystemTest.stab.cs

示例4: classWithFieldTest

		public void classWithFieldTest() {
			// public class ClassWithField {
			//     public int field;
			//     public ClassWithField() {
			//         field = 123;
			//     }
			// }
			var typeSystem = new Library(new String[0]);
			var typeBuilder = typeSystem.defineType("stab/ClassWithField");
			typeBuilder.setPublic(true);
			typeBuilder.setBaseType(typeSystem.getType("java/lang/Object"));

			var field = typeBuilder.defineField("field", typeSystem.IntType);
			field.setPublic(true);

			var methodBuilder = typeBuilder.defineMethod("<init>");
			methodBuilder.setPublic(true);
			methodBuilder.setReturnType(typeSystem.VoidType);
			var generator = methodBuilder.getCodeGenerator();
			generator.beginScope();
			generator.emit(Opcode.Aload, generator.getLocal("this"));
			generator.emit(Opcode.Invokespecial, typeBuilder.BaseType.getMethod("<init>", Query.empty<TypeInfo>()));
			generator.emit(Opcode.Aload, generator.getLocal("this"));
			generator.emit(Opcode.Ldc, (Object)123);
			generator.emit(Opcode.Putfield, field);
			generator.emit(Opcode.Return);
			generator.endScope();
			
			var bytecode = typeBuilder.createType(typeSystem);
			
			saveBytecode("ClassWithField", bytecode);
			
			var loader = new DynamicClassLoader();
			var c = loader.defineClass("stab.ClassWithField", bytecode);
			loader.linkClass(c);

			var cstr = c.getConstructor();
			var f = c.getField("field");
			var instance = cstr.newInstance();
			int value = f.getInt(instance);
			
			Assert.assertEquals(123, value);
		}
开发者ID:nagyistoce,项目名称:cnatural-language,代码行数:43,代码来源:TypeBuilderTest.stab.cs

示例5: SimpleClassTest

		public void SimpleClassTest() {
			// public class SimpleClass {
			//     public SimpleClass() {
			//     }
			// }
			var typeSystem = new Library(new String[0]);
			var typeBuilder = typeSystem.defineType("stab/SimpleClass");
			typeBuilder.setPublic(true);
			typeBuilder.setBaseType(typeSystem.getType("java/lang/Object"));
			
			createDefaultConstructor(typeBuilder);
			
			var bytecode = typeBuilder.createType(typeSystem);
			
			saveBytecode("SimpleClass", bytecode);
			
			var loader = new DynamicClassLoader();
			Class<?> c = loader.defineClass("stab.SimpleClass", bytecode);
			loader.linkClass(c);

			var cstr = c.getConstructor();
			cstr.newInstance();
		}
开发者ID:nagyistoce,项目名称:cnatural-language,代码行数:23,代码来源:TypeBuilderTest.stab.cs

示例6: classWithStaticFieldTest

		public void classWithStaticFieldTest() {
			// public class ClassWithStaticField {
			//     public static int FIELD = 123;
			//     public ClassWithStaticField() {
			//     }
			// }
			var typeSystem = new Library(new String[0]);
			var typeBuilder = typeSystem.defineType("stab/ClassWithStaticField");
			typeBuilder.setPublic(true);
			typeBuilder.setBaseType(typeSystem.getType("java/lang/Object"));

			var field = typeBuilder.defineField("FIELD", typeSystem.IntType);
			field.setPublic(true);
			field.setStatic(true);
			field.setValue(new Integer(123));

			createDefaultConstructor(typeBuilder);
			
			var bytecode = typeBuilder.createType(typeSystem);
			
			saveBytecode("ClassWithStaticField", bytecode);
			
			var loader = new DynamicClassLoader();
			var c = loader.defineClass("stab.ClassWithStaticField", bytecode);
			loader.linkClass(c);

			var f = c.getField("FIELD");
			int value = f.getInt(null);
			
			Assert.assertEquals(123, value);
		}
开发者ID:nagyistoce,项目名称:cnatural-language,代码行数:31,代码来源:TypeBuilderTest.stab.cs

示例7: genericClassTest

		public void genericClassTest() {
			// public class GenericClass<T> {
			//     public T field;
			//     public GenericClass(T t) {
			//         this.field = t;
			//     }
			// }
			var typeSystem = new Library(new String[0]);
			var typeBuilder = typeSystem.defineType("stab/GenericClass");
			typeBuilder.setPublic(true);
			typeBuilder.setBaseType(typeSystem.getType("java/lang/Object"));
			var t = typeBuilder.addGenericArgument("T");

			var field = typeBuilder.defineField("field", t);
			field.setPublic(true);

			var methodBuilder = typeBuilder.defineMethod("<init>");
			methodBuilder.setPublic(true);
			methodBuilder.setReturnType(typeSystem.VoidType);
			methodBuilder.addParameter(t).setName("t");
			var generator = methodBuilder.getCodeGenerator();
			generator.beginScope();
			generator.emit(Opcode.Aload, generator.getLocal("this"));
			generator.emit(Opcode.Invokespecial, typeBuilder.BaseType.getMethod("<init>", Query.empty<TypeInfo>()));
			generator.emit(Opcode.Aload, generator.getLocal("this"));
			generator.emit(Opcode.Aload, generator.getLocal("t"));
			generator.emit(Opcode.Putfield, field);
			generator.emit(Opcode.Return);
			generator.endScope();

			var bytecode = typeBuilder.createType(typeSystem);
			saveBytecode("GenericClass", bytecode);

			var loader = new DynamicClassLoader();
			var c = loader.defineClass("stab.GenericClass", bytecode);
			loader.linkClass(c);

			var cstr = c.getConstructor(typeof(Object));
			var f = c.getField("field");
			var instance = cstr.newInstance("TEST");
			Assert.assertEquals("TEST", f.get(instance));
		}
开发者ID:nagyistoce,项目名称:cnatural-language,代码行数:42,代码来源:TypeBuilderTest.stab.cs

示例8: staticInnerClassTest

		public void staticInnerClassTest() {
			// public class StaticInnerClass {
			//     public static class Nested {
			//         public Nested() {
			//		   }
			//     }
			//     public StaticInnerClass() {
			//     }
			// }
			var typeSystem = new Library(new String[0]);
			var typeBuilder = typeSystem.defineType("stab/StaticInnerClass");
			typeBuilder.setPublic(true);
			typeBuilder.setBaseType(typeSystem.getType("java/lang/Object"));

			createDefaultConstructor(typeBuilder);
			
			var nestedType = typeBuilder.defineNestedType("Nested");
			nestedType.setPublic(true);
			nestedType.setNestedPublic(true);
			nestedType.setBaseType(typeSystem.getType("java/lang/Object"));

			createDefaultConstructor(nestedType);

			var bytecode = typeBuilder.createType(typeSystem);
			saveBytecode("StaticInnerClass", bytecode);

			var innerBytecode = nestedType.createType(typeSystem);
			saveBytecode("StaticInnerClass$Nested", innerBytecode);

			var loader = new DynamicClassLoader();
			var c = loader.defineClass("stab.StaticInnerClass", bytecode);
			var nc = loader.defineClass("stab.StaticInnerClass$Nested", innerBytecode);
			loader.linkClass(c);
			loader.linkClass(nc);

			var cstr = c.getConstructor();
			cstr.newInstance();

			var ncstr = nc.getConstructor();
			ncstr.newInstance();
		}
开发者ID:nagyistoce,项目名称:cnatural-language,代码行数:41,代码来源:TypeBuilderTest.stab.cs

示例9: doTest

		private void doTest(String test) {
			var typeSystem = new Library(new String[] { bin });
			var typeInfo = typeSystem.getType("stab/bytecode/test/classes/" + test);
			doTest(test, typeInfo);
		}
开发者ID:nagyistoce,项目名称:cnatural-language,代码行数:5,代码来源:TypeSystemTest.stab.cs


注:本文中的Library.getType方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。