示例#1
0
        public void DeserializeFromXml(XmlReader reader, string propertyName)
        {
            XmlProxy xmlRoot = XmlProxySerializer.Instance.Deserialize(reader);

            if (xmlRoot.ElementName == propertyName)
            {
                this.Getter = (PropertyAccessModifier)xmlRoot.GetAttr("getter", (int)PropertyAccessModifier.Public);
                this.Setter = (PropertyAccessModifier)xmlRoot.GetAttr("setter", (int)PropertyAccessModifier.Public);
            }
        }
示例#2
0
    public string ForSetter(IPropertyBase property, IPropertiesBuilder propertiesBuilder)
    {
        string result = string.Empty;

        if (this.ActiveDTOStage)
        {
            return(result);
        }

        switch (property.PropertyKind)
        {
        case PropertyKind.Scalar:
        {
            IOrmAttribute[] typeAttributes = propertiesBuilder.GetPropertyTypeAttributes(property);
            OrmKeyAttribute keyAttribute   = (OrmKeyAttribute)typeAttributes.Single(item => item is OrmKeyAttribute);

            result = keyAttribute.Enabled ? VISIBILITY_PRIVATE : string.Empty;
            break;
        }

        case PropertyKind.Navigation:
        {
            IOrmAttribute[] typeAttributes = propertiesBuilder.GetPropertyTypeAttributes(property);
            OrmKeyAttribute keyAttribute   = (OrmKeyAttribute)typeAttributes.Single(item => item is OrmKeyAttribute);

            INavigationProperty navigationProperty = (INavigationProperty)property;
            if (navigationProperty.Multiplicity == MultiplicityKind.Many || keyAttribute.Enabled)
            {
                result = VISIBILITY_PRIVATE;
            }

            break;
        }
        }

        // only when result is not directly 'private' because of business rules we can adjust it from settings
        if (string.IsNullOrEmpty(result))
        {
            PropertyAccessModifier higherModifier = property.PropertyAccess.GetHigherModifier();

            if (property.PropertyAccess.Setter != PropertyAccessModifier.Public && property.PropertyAccess.Setter != higherModifier)
            {
                result = GetPropertyAccessModifierString(property.PropertyAccess.Setter);
            }
        }

        return(result);
    }
示例#3
0
        public override object CreateInstance(ITypeDescriptorContext context, IDictionary propertyValues)
        {
            //ModelElement owner = context.Instance as ModelElement;
            PropertyAccessModifiers currentObj = (PropertyAccessModifiers)context.PropertyDescriptor.GetValue(context.Instance);

            PropertyAccessModifier getter = (PropertyAccessModifier)propertyValues["Getter"];
            PropertyAccessModifier setter = (PropertyAccessModifier)propertyValues["Setter"];

            PropertyAccessModifiers result = new PropertyAccessModifiers
            {
                Getter = getter,
                Setter = setter
            };

            return(result);
        }
示例#4
0
    public string ForGetter(IPropertyBase property)
    {
        string result = string.Empty;

        if (this.ActiveDTOStage)
        {
            return(result);
        }

        PropertyAccessModifier higherModifier = property.PropertyAccess.GetHigherModifier();

        if (property.PropertyAccess.Getter != PropertyAccessModifier.Public && property.PropertyAccess.Getter != higherModifier)
        {
            result = GetPropertyAccessModifierString(property.PropertyAccess.Getter);
        }

        return(result);
    }
示例#5
0
    private string GetPropertyAccessModifierString(PropertyAccessModifier modifier)
    {
        switch (modifier)
        {
        case PropertyAccessModifier.Internal:
            return(VISIBILITY_INTERNAL);

        case PropertyAccessModifier.Private:
            return(VISIBILITY_PRIVATE);

        case PropertyAccessModifier.Protected:
            return(VISIBILITY_PROTECTED);

        case PropertyAccessModifier.ProtectedInternal:
            return(string.Format("{0} {1}", VISIBILITY_PROTECTED, VISIBILITY_INTERNAL));
        }

        return(string.Empty);
    }
示例#6
0
    public string AccessibilityForType(IPropertyBase property)
    {
        PropertyAccessModifier accessModifier = PropertyAccessModifier.Public;

        if (!this.ActiveDTOStage)
        {
            accessModifier = property.PropertyAccess.GetHigherModifier();
        }

        string accessibility = accessModifier == PropertyAccessModifier.ProtectedInternal
            ? VISIBILITY_PROTECTED_INTERNAL
            : accessModifier.ToString().ToLowerInvariant();

        if ((property as IPropertyBase).Owner.TypeKind == PersistentTypeKind.Interface)
        {
            accessibility = string.Empty;
        }

        return(accessibility);
    }
示例#7
0
        private bool PropertyBase_ReadPropertiesFromAttributes(SerializationContext serializationContext,
                                                               PropertyBase propertyBase, XmlReader reader)
        {
            // Access
            if (!serializationContext.Result.Failed)
            {
                string attribAccess = DONetEntityModelDesignerSerializationHelper.Instance.ReadAttribute(serializationContext, propertyBase, reader, "access");
                if (attribAccess != null)
                {
                    AccessModifier valueOfAccess;
                    if (SerializationUtilities.TryGetValue <AccessModifier>(serializationContext, attribAccess, out valueOfAccess))
                    {
                        propertyBase.PropertyAccess = new PropertyAccessModifiers();
                        PropertyAccessModifier modifier = valueOfAccess == AccessModifier.Public
                                                              ? PropertyAccessModifier.Public
                                                              : PropertyAccessModifier.Internal;
                        propertyBase.PropertyAccess.Getter = modifier;
                        propertyBase.PropertyAccess.Setter = modifier;

                        return(true);
                    }
                    else
                    {   // Invalid property value, ignored.
                        EntityModelDesignerSerializationBehaviorSerializationMessages.IgnoredPropertyValue(serializationContext, reader, "access", typeof(AccessModifier), attribAccess);
                    }
                }
                else
                {
                    propertyBase.PropertyAccess        = new PropertyAccessModifiers();
                    propertyBase.PropertyAccess.Getter = PropertyAccessModifier.Public;
                    propertyBase.PropertyAccess.Setter = PropertyAccessModifier.Public;

                    return(false);
                }
            }

            return(false);
        }
示例#8
0
 public PropertyAccessModifiers()
 {
     this.Getter = PropertyAccessModifier.Public;
     this.Setter = PropertyAccessModifier.Public;
 }
示例#9
0
 public string AccessibilityToString(PropertyAccessModifier propertyAccessModifier)
 {
     return(propertyAccessModifier == PropertyAccessModifier.ProtectedInternal
                ? VISIBILITY_PROTECTED_INTERNAL
                : propertyAccessModifier.ToString().ToLower());
 }