コード例 #1
0
        public void Dynamic_Class_Must_Be_Created_With_Specified_Method_With_Its_Parameter_Names()
        {
            var method1Name       = "Method1";
            var method1ReturnType = typeof(string);
            var method1Params     = new Dictionary <Type, string>
            {
                { typeof(int), "number" },
                { typeof(string), "message" },
            };
            var attributeType      = typeof(SampleAttribute);
            var ctorParamsMapping  = SampleAttribute.GetCtorParamValueMapping();
            var propsValuesMapping = SampleAttribute.GetPropertyValueMaaping();
            var setAttributeParam  = new Dictionary <Type, Tuple <IDictionary <Type, object>, IDictionary <string, object> > >
            {
                { attributeType, new Tuple <IDictionary <Type, object>, IDictionary <string, object> >(ctorParamsMapping, propsValuesMapping) },
            };


            var builder = DynamicTypeBuilderFactory.CreateClassBuilder("Dynamic.TestClass", new Dictionary <string, Type>());

            SetMethod(builder, method1Name, method1ReturnType, method1Params, setAttributeParam);

            var classType = builder.Build();

            AssertOnHavingMethodWithParamNames(
                classType: classType,
                methodName: method1Name,
                returnType: method1ReturnType,
                @params: method1Params,
                propValuesMapping: new Dictionary <Type, IDictionary <string, object> >
            {
                { attributeType, propsValuesMapping },
            });
        }
        public void Dynamic_Interface_Must_Be_Generated_With_Defined_Attribute()
        {
            var interfaceFullName = "Dynamic.GeneratedInterface";
            var attributeType     = typeof(SampleAttribute);
            var attributeCtorParamValueMapping = SampleAttribute.GetCtorParamValueMapping();
            var attributePropertyValueMapping  = SampleAttribute.GetPropertyValueMaaping();

            var interfaceBuilder = DynamicTypeBuilderFactory.CreateInterfaceBuilder(interfaceFullName);

            interfaceBuilder.SetAttribute(attributeType, attributeCtorParamValueMapping, attributePropertyValueMapping);

            var generatedType = interfaceBuilder.Build();

            AssertOnHavingAttributeOnType(
                interfaceType: generatedType,
                attributeType: attributeType,
                attributeCtorParamValueMapping: attributeCtorParamValueMapping,
                attributePropertyValueMapping: attributePropertyValueMapping);
        }
コード例 #3
0
        public void Dynamic_Dto_Type_Must_Have_The_Specified_Attribute_On_The_Defined_Property()
        {
            var propertyName  = "SomeProperty";
            var attributeType = typeof(SampleAttribute);
            var ctorParametersValuesMapping = SampleAttribute.GetCtorParamValueMapping();
            var propertiesValuesMapping     = SampleAttribute.GetPropertyValueMaaping();

            var typeBuilder = DynamicTypeBuilderFactory.CreateDtoBuilder(propertyName);

            typeBuilder
            .SetProperty(propertyName, typeof(string))
            .SetAttribute(
                attributeType,
                ctorParametersValuesMapping,
                propertiesValuesMapping);

            var generatedType = typeBuilder.Build();

            AssertOnHavingPropertyWithFollowingAttribute(generatedType, propertyName, typeof(SampleAttribute), propertiesValuesMapping);
        }