Example #1
0
        protected override void BuildImpl(IPropertySymbol propertyWrapperSymbol, RoslynCodeBuilder roslynCodeBuilder)
        {
            Accessibility propAccessibility = propertyWrapperSymbol.DeclaredAccessibility;

            roslynCodeBuilder.AddPropOpening
            (
                propertyWrapperSymbol.Name,
                propertyWrapperSymbol.Type as INamedTypeSymbol,
                propertyWrapperSymbol.DeclaredAccessibility,
                propertyWrapperSymbol.ShouldOverride()
            );

            if (propertyWrapperSymbol.GetMethod != null)
            {
                Accessibility getterAccessibility = propertyWrapperSymbol.GetMethod.DeclaredAccessibility;

                if (getterAccessibility == propAccessibility)
                {
                    getterAccessibility = Accessibility.NotApplicable;
                }

                roslynCodeBuilder.OpenPropGetter(getterAccessibility);

                MemberMapInfo firstMemberMap =
                    this.WrappedMembers
                    .FirstOrDefault(member => (!member.IsNonPublic));

                if (firstMemberMap == null)
                {
                    firstMemberMap = this.WrappedMembers.First();
                }

                if (firstMemberMap.IsNonPublic)
                {
                    if (firstMemberMap.AllowNonPublic)
                    {
                        string returnType = (propertyWrapperSymbol.Type as INamedTypeSymbol).GetFullTypeString();
                        roslynCodeBuilder.AddLine($"return ({returnType}) {firstMemberMap.WrappedObjPropName}.GetPropValue(\"{firstMemberMap.WrappedMemberName}\", true)", true);
                    }
                }
                else
                {
                    string wrappedMemberStr = firstMemberMap.WrappedClassMemberFullName;

                    roslynCodeBuilder.AddReturnVar(wrappedMemberStr);
                }
                roslynCodeBuilder.Pop();
            }

            if (propertyWrapperSymbol.SetMethod != null)
            {
                Accessibility setterAccessibility = propertyWrapperSymbol.SetMethod.DeclaredAccessibility;

                if (setterAccessibility == propAccessibility)
                {
                    setterAccessibility = Accessibility.NotApplicable;
                }

                roslynCodeBuilder.OpenPropSetter(setterAccessibility);

                if (this.IncludeBaseVirtualInOverride)
                {
                    roslynCodeBuilder.AddSettingValue($"base.{WrapperSymbolName}");
                }

                foreach (MemberMapInfo memberMap in this.WrappedMembers)
                {
                    if (memberMap.IsNonPublic)
                    {
                        if (memberMap.AllowNonPublic)
                        {
                            roslynCodeBuilder.AddLine($"{memberMap.WrappedObjPropName}.SetPropValue(\"{memberMap.WrappedMemberName}\", value, true)", true);
                        }
                    }
                    else
                    {
                        string wrappedMemberStr = memberMap.WrappedClassMemberFullName;
                        roslynCodeBuilder.AddSettingValue(wrappedMemberStr);
                    }
                }

                roslynCodeBuilder.Pop();
            }

            roslynCodeBuilder.Pop();
        }
Example #2
0
        protected override void BuildImpl(IPropertySymbol propertyWrapperSymbol, RoslynCodeBuilder roslynCodeBuilder)
        {
            string backingFieldName =
                propertyWrapperSymbol.Name.PropToFieldName();

            if (this.AddBackingField)
            {
                roslynCodeBuilder.AddPropBackingField(propertyWrapperSymbol);
            }

            Accessibility propAccessibility =
                propertyWrapperSymbol.DeclaredAccessibility;
            bool shouldOverride = (!ForceNoOverride) && propertyWrapperSymbol.ShouldOverride();

            roslynCodeBuilder.AddPropOpening
            (
                propertyWrapperSymbol.Name,
                propertyWrapperSymbol.Type as INamedTypeSymbol,
                propertyWrapperSymbol.DeclaredAccessibility,
                shouldOverride
            );

            if (propertyWrapperSymbol.GetMethod != null)
            {
                Accessibility getterAccessibility =
                    propertyWrapperSymbol.GetMethod.DeclaredAccessibility;

                if (getterAccessibility == propAccessibility)
                {
                    getterAccessibility = Accessibility.NotApplicable;
                }

                roslynCodeBuilder.OpenPropGetter(getterAccessibility);

                if (AddBackingField)
                {
                    roslynCodeBuilder.AddReturnVar(backingFieldName);
                }
                else
                {
                    MemberMapInfo firstMemberMap =
                        this.WrappedMembers
                        .FirstOrDefault(member => (!member.IsNonPublic));

                    if (firstMemberMap == null)
                    {
                        firstMemberMap = this.WrappedMembers.First();
                    }

                    firstMemberMap
                    .AddPluginPropGetterLine(propertyWrapperSymbol, roslynCodeBuilder);
                }
                roslynCodeBuilder.Pop();
            }

            if ((propertyWrapperSymbol.SetMethod != null) || ForceCreateSetter || AddBackingField)
            {
                Accessibility setterAccessibility = Accessibility.Private;

                if (propertyWrapperSymbol.SetMethod != null)
                {
                    setterAccessibility =
                        propertyWrapperSymbol.SetMethod.DeclaredAccessibility;
                }

                if (setterAccessibility == propAccessibility)
                {
                    setterAccessibility = Accessibility.NotApplicable;
                }

                roslynCodeBuilder.OpenPropSetter(setterAccessibility);

                if (AddBackingField)
                {
                    roslynCodeBuilder.AddSettingValue(backingFieldName);
                }

                if (this.IncludeBaseVirtualInOverride)
                {
                    roslynCodeBuilder.AddSettingValue($"base.{WrapperSymbolName}");
                }

                foreach (MemberMapInfo memberMap in this.WrappedMembers)
                {
                    memberMap.AddCheckForSharedLine(roslynCodeBuilder);
                    roslynCodeBuilder.Push();
                    memberMap.AddAssignPluginProp("value", roslynCodeBuilder);
                    roslynCodeBuilder.Pop();
                }

                roslynCodeBuilder.Pop();
            }

            roslynCodeBuilder.Pop();
        }