Exemple #1
0
        private void BuildProperty(ILConversion conversion, ConvertedTypeDefinitionWithProperties_I convertedType, PropertyDefinition propertyDefinition)
        {
            var propertyAttributes = GetPropertyAttributes(propertyDefinition);

            var propertyType = Execution.Types.Ensuring.EnsureToType(conversion, propertyDefinition.PropertyType);

            var parameterTypes = Parameters.GetSystemParameterTypes(conversion, propertyDefinition.Parameters);

            var builder = convertedType.TypeBuilder.DefineProperty(propertyDefinition.Name, propertyAttributes, propertyType, parameterTypes);

            var entry = new ConvertedProperty()
            {
                Name    = propertyDefinition.Name,
                Builder = builder,
                UnderlyingPropertyInfo = builder,
                PropertyDefinition     = propertyDefinition
            };

            if (!convertedType.Properties.ByName.TryGetValue(entry.Name, out List <SemanticPropertyMask_I> propertyList))
            {
                propertyList = new List <SemanticPropertyMask_I>();

                convertedType.Properties.ByName.Add(entry.Name, propertyList);
            }

            propertyList.Add(entry);

            if (propertyDefinition.GetMethod != null)
            {
                ConvertedMethodMask_I getMethod = Methods.Getting.GetMethod(convertedType, propertyDefinition.GetMethod);

                if (getMethod?.UnderlyingMethod == null)
                {
                    throw new System.Exception("Expected get method");
                }

                builder.SetGetMethod((MethodBuilder)getMethod.UnderlyingMethod);
            }

            if (propertyDefinition.SetMethod != null)
            {
                ConvertedMethodMask_I setMethod = Methods.Getting.GetMethod(convertedType, propertyDefinition.SetMethod);

                if (setMethod?.UnderlyingMethod == null)
                {
                    throw new System.Exception("Expected set method");
                }

                builder.SetSetMethod((MethodBuilder)setMethod.UnderlyingMethod);
            }

            CustomAttributes.BuildCustomAttributes(conversion, convertedType, entry);
        }
        public void BuildCustomAttributes(ILConversion conversion, ConvertedTypeDefinitionWithProperties_I convertedType, ConvertedProperty entry)
        {
            var propertyDefinition = entry.PropertyDefinition;

            var builders = CreateCustomAttributeList(conversion, propertyDefinition.CustomAttributes);

            for (int i = 0; i < builders.Count; i++)
            {
                var builder1 = builders[i];

                entry.Builder.SetCustomAttribute(builder1);
            }
        }