예제 #1
0
        public void MatchPropertySignature()
        {
            var type       = new TypeReference(_someAssemblyReference, "SomeNamespace", "SomeType");
            var signature1 = PropertySignature.CreateStatic(type.ToTypeSignature());
            var signature2 = PropertySignature.CreateStatic(type.ToTypeSignature());

            Assert.Equal(signature1, signature2, _comparer);
        }
예제 #2
0
        public void InstantiatePropertySignatureWithGenericPropertyType()
        {
            var signature = PropertySignature.CreateStatic(new GenericParameterSignature(GenericParameterType.Type, 0));
            var context   = new GenericContext(GetProvider(_module.CorLibTypeFactory.String), null);

            var newSignature = signature.InstantiateGenericTypes(context);

            var expected = PropertySignature.CreateStatic(_module.CorLibTypeFactory.String);

            Assert.Equal(expected, newSignature, Comparer);
        }
        private static PropertyDefinition CreateDummyProperty(TypeDefinition dummyType, string name)
        {
            var property = new PropertyDefinition(name, 0,
                                                  PropertySignature.CreateStatic(dummyType.Module.CorLibTypeFactory.Object));

            var getMethod = new MethodDefinition($"get_{property.Name}", MethodAttributes.Public | MethodAttributes.Static,
                                                 MethodSignature.CreateStatic(dummyType.Module.CorLibTypeFactory.Object));

            getMethod.CilMethodBody = new CilMethodBody(getMethod)
            {
                Instructions = { new CilInstruction(CilOpCodes.Ldnull), new CilInstruction(CilOpCodes.Ret) }
            };

            dummyType.Methods.Add(getMethod);
            property.Semantics.Add(new MethodSemantics(getMethod, MethodSemanticsAttributes.Getter));
            return(property);
        }
        public MethodSemanticsCollectionTest()
        {
            var module = new ModuleDefinition("Module");

            _property = new PropertyDefinition("Property", 0,
                                               PropertySignature.CreateStatic(module.CorLibTypeFactory.Int32));

            _property2 = new PropertyDefinition("Property2", 0,
                                                PropertySignature.CreateStatic(module.CorLibTypeFactory.Int32));

            _getMethod = new MethodDefinition("get_Property",
                                              MethodAttributes.Public | MethodAttributes.Static,
                                              MethodSignature.CreateStatic(module.CorLibTypeFactory.Int32));

            _setMethod = new MethodDefinition("set_Property",
                                              MethodAttributes.Public | MethodAttributes.Static,
                                              MethodSignature.CreateStatic(module.CorLibTypeFactory.Void, module.CorLibTypeFactory.Int32));
        }