Exemplo n.º 1
0
 /// <summary>
 /// Creates a <see cref="TypeDescriptorContext"/> for the <see cref="DomainPropertyInfo"/>
 /// specified by <paramref name="domainPropertyInfo"/>.
 /// </summary>
 /// <param name="element">
 /// The instance of <see cref="ModelElement"/> containing the property for which a
 /// <see cref="TypeDescriptorContext"/> should be created.
 /// <see langword="null"/> may be specified for this parameter.
 /// </param>
 /// <param name="domainPropertyInfo">
 /// The <see cref="DomainPropertyInfo"/> for which a <see cref="TypeDescriptorContext"/>
 /// should be created.
 /// </param>
 /// <returns>
 /// A <see cref="TypeDescriptorContext"/> for the <see cref="DomainPropertyInfo"/>
 /// specified by <paramref name="domainPropertyInfo"/>.
 /// </returns>
 /// <exception cref="ArgumentNullException">
 /// <paramref name="domainPropertyInfo"/> is <see langword="null"/>.
 /// </exception>
 public static TypeDescriptorContext CreateTypeDescriptorContext(ModelElement element, DomainPropertyInfo domainPropertyInfo)
 {
     if (domainPropertyInfo == null)
     {
         throw new ArgumentNullException("domainPropertyInfo");
     }
     return(new TypeDescriptorContext(element, DomainTypeDescriptor.CreatePropertyDescriptor(element, domainPropertyInfo)));
 }
Exemplo n.º 2
0
 /// <summary>
 /// Replaces <see cref="ElementTypeDescriptor.ShouldCreatePropertyDescriptor"/>.
 /// </summary>
 /// <seealso cref="ElementTypeDescriptor.ShouldCreatePropertyDescriptor"/>
 protected override bool ShouldCreatePropertyDescriptor(ModelElement requestor, DomainPropertyInfo domainProperty)
 {
     if (domainProperty == null)
     {
         throw new ArgumentNullException("domainProperty");
     }
     return(((BrowsableAttribute)DomainTypeDescriptor.GetRawAttributes(domainProperty.PropertyInfo)[typeof(BrowsableAttribute)]).Browsable);
 }
Exemplo n.º 3
0
 /// <summary>
 /// Replaces <see cref="ElementTypeDescriptor.GetRolePlayerPropertyAttributes"/>.
 /// </summary>
 /// <seealso cref="ElementTypeDescriptor.GetRolePlayerPropertyAttributes"/>
 protected new Attribute[] GetRolePlayerPropertyAttributes(DomainRoleInfo domainRole)
 {
     if (domainRole == null)
     {
         throw new ArgumentNullException("domainRole");
     }
     return(EditorUtility.GetAttributeArray(DomainTypeDescriptor.GetRawAttributes(domainRole.LinkPropertyInfo)));
 }
Exemplo n.º 4
0
 /// <summary>
 /// Replaces <see cref="ElementTypeDescriptor.GetDomainPropertyAttributes"/>.
 /// </summary>
 /// <seealso cref="ElementTypeDescriptor.GetDomainPropertyAttributes"/>
 protected new Attribute[] GetDomainPropertyAttributes(DomainPropertyInfo domainPropertyInfo)
 {
     if (domainPropertyInfo == null)
     {
         throw new ArgumentNullException("domainPropertyInfo");
     }
     return(EditorUtility.GetAttributeArray(DomainTypeDescriptor.GetRawAttributes(domainPropertyInfo.PropertyInfo)));
 }
Exemplo n.º 5
0
        /// <summary>
        /// Creates a <see cref="PropertyDescriptor"/> for the <see cref="DomainPropertyInfo"/> specified
        /// by <paramref name="domainPropertyInfo"/>.
        /// </summary>
        /// <param name="element">
        /// The instance of <see cref="ModelElement"/> containing the property for which a <see cref="PropertyDescriptor"/>
        /// should be created.
        /// <see langword="null"/> may be specified for this parameter.
        /// </param>
        /// <param name="domainPropertyInfo">
        /// The <see cref="DomainPropertyInfo"/> for which a <see cref="PropertyDescriptor"/> should be created.
        /// </param>
        /// <returns>
        /// A <see cref="PropertyDescriptor"/> for the <see cref="DomainPropertyInfo"/> specified
        /// by <paramref name="domainPropertyInfo"/>.
        /// </returns>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="domainPropertyInfo"/> is <see langword="null"/>.
        /// </exception>
        public static PropertyDescriptor CreatePropertyDescriptor(ModelElement element, DomainPropertyInfo domainPropertyInfo)
        {
            if (domainPropertyInfo == null)
            {
                throw new ArgumentNullException("domainPropertyInfo");
            }
            Type               propertyType     = domainPropertyInfo.PropertyType;
            string             propertyName     = domainPropertyInfo.Name;
            Guid               domainPropertyId = domainPropertyInfo.Id;
            PropertyDescriptor propertyDescriptor;
            Type               elementType;

            if (element != null)
            {
                // Try the default type descriptor for the element (including custom type descriptors).
                propertyDescriptor = DomainTypeDescriptor.FindPropertyDescriptorInternal(TypeDescriptor.GetProperties(element, false), propertyType, propertyName, domainPropertyId);
                if (propertyDescriptor != null)
                {
                    return(propertyDescriptor);
                }
                // Try the default type descriptor for the element (excluding custom type descriptors, in case it is filtering out the property we want).
                propertyDescriptor = DomainTypeDescriptor.FindPropertyDescriptorInternal(TypeDescriptor.GetProperties(element, true), propertyType, propertyName, domainPropertyId);
                if (propertyDescriptor != null)
                {
                    return(propertyDescriptor);
                }
                elementType = element.GetType();
            }
            else
            {
                elementType = domainPropertyInfo.DomainClass.ImplementationClass;
            }

            // Try the default type descriptor for the Type of the element.

            // The following line is never returning in VS2010 (ValueRange.MinInclusion as
            // as a sample, but others are likely to experience the same behavior). This
            // will skip custom descriptors and return reflected property descriptors anyway,
            // so we just create the specific property descriptor directly.
            // propertyDescriptor = DomainTypeDescriptor.FindPropertyDescriptorInternal(TypeDescriptor.GetProperties(elementType), propertyType, propertyName, domainPropertyId);
            propertyDescriptor = TypeDescriptor.CreateProperty(elementType, propertyName, propertyType);
            if (propertyDescriptor != null)
            {
                return(propertyDescriptor);
            }

            // GetRawAttributes(PropertyInfo) has a LinkDemand for ReflectionPermission with MemberAccess. In order to avoid any security
            // issues, we do a full Demand for the same permission here. We could have instead put the same LinkDemand on this method,
            // but in the majority of cases this permission won't actually be necessary. By doing it this way, callers without this
            // permission can still successfully use this method as long as the PropertyDescriptor is found before this point.
            new ReflectionPermission(ReflectionPermissionFlag.MemberAccess).Demand();

            // Since we couldn't find a PropertyDescriptor, we'll have to construct one ourselves.
            return(new ElementPropertyDescriptor(element, domainPropertyInfo, EditorUtility.GetAttributeArray(DomainTypeDescriptor.GetRawAttributes(domainPropertyInfo.PropertyInfo))));
        }
Exemplo n.º 6
0
 /// <summary>
 /// Attempts to locate a <see cref="PropertyDescriptor"/> for the <see cref="DomainRoleInfo"/>
 /// specified by <paramref name="domainRoleInfo"/> in the <see cref="PropertyDescriptorCollection"/>
 /// specified by <paramref name="propertyDescriptors"/>.
 /// </summary>
 /// <param name="propertyDescriptors">
 /// The <see cref="PropertyDescriptorCollection"/> in which to search.
 /// </param>
 /// <param name="domainRoleInfo">
 /// The <see cref="DomainRoleInfo"/> for which a <see cref="PropertyDescriptor"/> should be searched for
 /// in the <see cref="PropertyDescriptorCollection"/> specified by <paramref name="propertyDescriptors"/>.
 /// </param>
 /// <returns>
 /// A <see cref="PropertyDescriptor"/> for the <see cref="DomainRoleInfo"/> specified by
 /// <paramref name="domainRoleInfo"/> if one could be located in the <see cref="PropertyDescriptorCollection"/>
 /// specified by <paramref name="propertyDescriptors"/>; otherwise, <see langword="null"/>.
 /// </returns>
 public static PropertyDescriptor FindPropertyDescriptor(PropertyDescriptorCollection propertyDescriptors, DomainRoleInfo domainRoleInfo)
 {
     if (propertyDescriptors == null)
     {
         throw new ArgumentNullException("propertyDescriptors");
     }
     if (domainRoleInfo == null)
     {
         throw new ArgumentNullException("domainRoleInfo");
     }
     return(DomainTypeDescriptor.FindRolePlayerPropertyDescriptorInternal(propertyDescriptors, domainRoleInfo.LinkPropertyInfo.PropertyType, domainRoleInfo.PropertyName, domainRoleInfo.OppositeDomainRole.Id));
 }
Exemplo n.º 7
0
        /// <summary>
        /// Creates a <see cref="PropertyDescriptor"/> for the <see cref="DomainRoleInfo"/> specified
        /// by <paramref name="domainRoleInfo"/>.
        /// </summary>
        /// <param name="element">
        /// The instance of <see cref="ModelElement"/> playing the <see cref="DomainRoleInfo"/> specified by
        /// <paramref name="domainRoleInfo"/> for which a <see cref="PropertyDescriptor"/> should be created.
        /// </param>
        /// <param name="domainRoleInfo">
        /// The <see cref="DomainRoleInfo"/> for which a <see cref="PropertyDescriptor"/> should be created.
        /// </param>
        /// <returns>
        /// A <see cref="PropertyDescriptor"/> for the <see cref="DomainRoleInfo"/> specified by
        /// <paramref name="domainRoleInfo"/> played by the <see cref="ModelElement"/> specified by
        /// <paramref name="element"/>.
        /// </returns>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="element"/> is <see langword="null"/>.
        /// </exception>
        /// /// <exception cref="ArgumentNullException">
        /// <paramref name="domainRoleInfo"/> is <see langword="null"/>.
        /// </exception>
        public static PropertyDescriptor CreatePropertyDescriptor(ModelElement element, DomainRoleInfo domainRoleInfo)
        {
            if (element == null)
            {
                throw new ArgumentNullException("element");
            }
            if (domainRoleInfo == null)
            {
                throw new ArgumentNullException("domainRoleInfo");
            }
            PropertyInfo       linkPropertyInfo       = domainRoleInfo.LinkPropertyInfo;
            Type               propertyType           = linkPropertyInfo.PropertyType;
            string             propertyName           = domainRoleInfo.PropertyName;
            DomainRoleInfo     oppositeDomainRoleInfo = domainRoleInfo.OppositeDomainRole;
            Guid               oppositeDomainRoleId   = oppositeDomainRoleInfo.Id;
            PropertyDescriptor propertyDescriptor;

            // Try the default type descriptor for the element (including custom type descriptors).
            propertyDescriptor = DomainTypeDescriptor.FindRolePlayerPropertyDescriptorInternal(TypeDescriptor.GetProperties(element, false), propertyType, propertyName, oppositeDomainRoleId);
            if (propertyDescriptor != null)
            {
                return(propertyDescriptor);
            }
            // Try the default type descriptor for the element (excluding custom type descriptors, in case it is filtering out the property we want).
            propertyDescriptor = DomainTypeDescriptor.FindRolePlayerPropertyDescriptorInternal(TypeDescriptor.GetProperties(element, true), propertyType, propertyName, oppositeDomainRoleId);
            if (propertyDescriptor != null)
            {
                return(propertyDescriptor);
            }
            // Try the default type descriptor for the Type of the element.
            propertyDescriptor = DomainTypeDescriptor.FindRolePlayerPropertyDescriptorInternal(TypeDescriptor.GetProperties(element.GetType()), propertyType, propertyName, oppositeDomainRoleId);
            if (propertyDescriptor != null)
            {
                return(propertyDescriptor);
            }

            // GetRawAttributes(PropertyInfo) has a LinkDemand for ReflectionPermission with MemberAccess. In order to avoid any security
            // issues, we do a full Demand for the same permission here. We could have instead put the same LinkDemand on this method,
            // but in the majority of cases this permission won't actually be necessary. By doing it this way, callers without this
            // permission can still successfully use this method as long as the PropertyDescriptor is found before this point.
            new ReflectionPermission(ReflectionPermissionFlag.MemberAccess).Demand();

            // Since we couldn't find a PropertyDescriptor, we'll have to construct one ourselves.
            return(new RolePlayerPropertyDescriptor(element, oppositeDomainRoleInfo, EditorUtility.GetAttributeArray(DomainTypeDescriptor.GetRawAttributes(linkPropertyInfo))));
        }
Exemplo n.º 8
0
        /// <summary>
        /// Creates a <see cref="PropertyDescriptor"/> for the <see cref="DomainPropertyInfo"/> or
        /// <see cref="DomainRoleInfo"/> with a <see cref="DomainObjectInfo.Id"/> equal to
        /// <paramref name="domainPropertyOrRoleId"/>.
        /// </summary>
        /// <param name="element">
        /// The instance of <see cref="ModelElement"/> containing the property for which a
        /// <see cref="PropertyDescriptor"/> should be created.
        /// </param>
        /// <param name="domainPropertyOrRoleId">
        /// The <see cref="DomainObjectInfo.Id"/> of the <see cref="DomainPropertyInfo"/> or
        /// <see cref="DomainRoleInfo"/> for which a <see cref="PropertyDescriptor"/> should
        /// be created.
        /// </param>
        /// <returns>
        /// A <see cref="PropertyDescriptor"/> for the <see cref="DomainPropertyInfo"/> or
        /// <see cref="DomainRoleInfo"/> with a <see cref="DomainObjectInfo.Id"/> equal to
        /// <paramref name="domainPropertyOrRoleId"/>.
        /// </returns>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="element"/> is <see langword="null"/>.
        /// </exception>
        /// <exception cref="DomainDataNotFoundException">
        /// Neither a <see cref="DomainPropertyInfo"/> nor a <see cref="DomainRoleInfo"/>
        /// with a <see cref="DomainObjectInfo.Id"/> equal to
        /// <paramref name="domainPropertyOrRoleId"/> could be found.
        /// </exception>
        public static PropertyDescriptor CreatePropertyDescriptor(ModelElement element, Guid domainPropertyOrRoleId)
        {
            if (element == null)
            {
                throw new ArgumentNullException("element");
            }
            DomainDataDirectory domainDataDirectory = element.Store.DomainDataDirectory;
            DomainPropertyInfo  domainPropertyInfo  = domainDataDirectory.FindDomainProperty(domainPropertyOrRoleId);

            if (domainPropertyInfo != null)
            {
                return(DomainTypeDescriptor.CreatePropertyDescriptor(element, domainPropertyInfo));
            }
            else
            {
                return(DomainTypeDescriptor.CreatePropertyDescriptor(element, domainDataDirectory.GetDomainRole(domainPropertyOrRoleId)));
            }
        }
        /// <summary>See <see cref="TypeConverter.ConvertFrom(ITypeDescriptorContext,CultureInfo,Object)"/>.</summary>
        public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
        {
            object             component;
            PropertyDescriptor elementPropertyDescriptor;
            string             stringValue;
            ModelElement       element;
            PropertyDescriptor namePropertyDescriptor;

            if (context != null &&
                (component = context.Instance) != null &&
                (elementPropertyDescriptor = context.PropertyDescriptor) != null &&
                (object)(stringValue = value as string) != null &&
                (element = elementPropertyDescriptor.GetValue(component) as ModelElement) != null &&
                (namePropertyDescriptor = DomainTypeDescriptor.CreateNamePropertyDescriptor(element)) != null)
            {
                namePropertyDescriptor.SetValue(element, stringValue);
                return(element);
            }
            return(base.ConvertFrom(context, culture, value));
        }
Exemplo n.º 10
0
        /// <summary>
        /// Creates a <see cref="PropertyDescriptor"/> for the <c>Name</c> property of <paramref name="element"/>.
        /// </summary>
        /// <param name="element">
        /// The instance of <see cref="ModelElement"/> containing the <c>Name</c> property for which a
        /// <see cref="PropertyDescriptor"/> should be created.
        /// </param>
        /// <returns>
        /// A <see cref="PropertyDescriptor"/> for the <c>Name</c> property of <paramref name="element"/>
        /// </returns>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="element"/> is <see langword="null"/>.
        /// </exception>
        /// <exception cref="InvalidOperationException">
        /// <paramref name="element"/> does not have a <c>Name</c> property.
        /// </exception>
        public static PropertyDescriptor CreateNamePropertyDescriptor(ModelElement element)
        {
            if (element == null)
            {
                throw new ArgumentNullException("element");
            }
            DomainPropertyInfo nameDomainPropertyInfo = element.GetDomainClass().NameDomainProperty;

            if (nameDomainPropertyInfo == null)
            {
                // Cheat and use the Exception that DSL Tools throws so that we don't need to worry about localizing it.
                try
                {
                    DomainClassInfo.GetName(element);
                }
                catch (InvalidOperationException ex)
                {
                    throw ex;                     // Yes, we want to reset the stack trace.
                }
            }
            return(DomainTypeDescriptor.CreatePropertyDescriptor(element, nameDomainPropertyInfo));
        }