예제 #1
0
        private static IEnumerable<XAttribute> GeneratePropertyAccessModifier(PropertyAccessModifierAnnotation annotation)
        {
            List<XAttribute> visibilities = new List<XAttribute>();
            AccessModifier getterVisibility = annotation.GetterAccessModifier;
            AccessModifier setterVisibility = annotation.SetterAccessModifier;

            if (getterVisibility != AccessModifier.Unspecified)
            {
                visibilities.Add(new XAttribute(EdmConstants.CodegenNamespace + "GetterAccess", annotation.GetterAccessModifier.ToString()));
            }

            if (setterVisibility != AccessModifier.Unspecified)
            {
                visibilities.Add(new XAttribute(EdmConstants.CodegenNamespace + "SetterAccess", annotation.SetterAccessModifier.ToString()));
            }

            return visibilities.Count > 0 ? visibilities : null;
        }
        private static void ApplyPropertyAccessModifier(CodeMemberAutoImplementedProperty codeProp, PropertyAccessModifierAnnotation propertyAccessModifierAnnotation)
        {
            if (propertyAccessModifierAnnotation != null)
            {
                var maxVisibility = (AccessModifier)Math.Max(
                    (int)propertyAccessModifierAnnotation.GetterAccessModifier,
                    (int)propertyAccessModifierAnnotation.SetterAccessModifier);

                codeProp.Attributes &= ~MemberAttributes.AccessMask;
                codeProp.Attributes |= ConvertAccessModifierToMemberAttributes(maxVisibility);

                if (maxVisibility != propertyAccessModifierAnnotation.GetterAccessModifier)
                {
                    codeProp.GetAttributes =
                        ConvertAccessModifierToMemberAttributes(propertyAccessModifierAnnotation.GetterAccessModifier);
                }

                if (maxVisibility != propertyAccessModifierAnnotation.SetterAccessModifier)
                {
                    codeProp.SetAttributes =
                        ConvertAccessModifierToMemberAttributes(propertyAccessModifierAnnotation.SetterAccessModifier);
                }
            }
        }