Exemplo n.º 1
0
        private static void HandlePublicGetter(SortedSet <string> namespaces, bool isMake, bool hasEvents,
                                               PropertyInfo baseProperty, List <string> propertyImplementations)
        {
            var getMethod     = baseProperty.GetMethod;
            var getVisibility = getMethod.IsPublic ? string.Empty : CodeTemplates.GetVisibility(getMethod.IsFamily, getMethod.IsFamilyOrAssembly);
            var returnType    = $"{getMethod.ReturnType.GetFullName(namespaces, getMethod.ReturnParameter)}";

            if (isMake)
            {
                propertyImplementations.Add(PropertyTemplates.GetPropertyGetForMake(getVisibility));
            }
            else if (getMethod.ReturnType.IsSpanLike())
            {
                propertyImplementations.Add(PropertyTemplates.GetPropertyGetForSpanLike(getVisibility));
            }
            else
            {
                var getArgumentNameList = getMethod.GetArgumentNameList();
                var getDelegateCast     = getMethod.GetDelegateCast();

                if (getMethod.GetParameters().Length > 0)
                {
                    var getExpectationChecks           = getMethod.GetExpectationChecks();
                    var getExpectationExceptionMessage = getMethod.GetExpectationExceptionMessage();
                    propertyImplementations.Add(getMethod.ReturnType.RequiresExplicitCast() ?
                                                PropertyTemplates.GetPropertyGetWithValueTypeReturnValue(
                                                    getMethod.MetadataToken, getArgumentNameList, returnType,
                                                    getExpectationChecks, getDelegateCast, getExpectationExceptionMessage, getVisibility, hasEvents) :
                                                PropertyTemplates.GetPropertyGetWithReferenceTypeReturnValue(
                                                    getMethod.MetadataToken, getArgumentNameList, returnType,
                                                    getExpectationChecks, getDelegateCast, getExpectationExceptionMessage, getVisibility, hasEvents));
                }
                else
                {
                    propertyImplementations.Add(getMethod.ReturnType.RequiresExplicitCast() ?
                                                PropertyTemplates.GetPropertyGetWithValueTypeReturnValueAndNoIndexers(
                                                    getMethod.MetadataToken, getArgumentNameList, returnType, getDelegateCast, getVisibility, hasEvents) :
                                                PropertyTemplates.GetPropertyGetWithReferenceTypeReturnValueAndNoIndexers(
                                                    getMethod.MetadataToken, getArgumentNameList, returnType, getDelegateCast, getVisibility, hasEvents));
                }
            }
        }