public ModelTypeDescriptor(ICustomTypeDescriptor parent, object instance, IList<ModelProperty> properties)
     : base(parent)
 {
     modelPropertyDescriptors = properties
         .Select(p => new ModelPropertyDescriptor(p))
         .ToArray();
 }
        /// <summary>
        /// Constructor taking a metadata context, an structural type, and a parent custom type descriptor
        /// </summary>
        /// <param name="typeDescriptionContext">The <see cref="LinqToEntitiesTypeDescriptionContext"/> context.</param>
        /// <param name="edmType">The <see cref="StructuralType"/> type (can be an entity or complex type).</param>
        /// <param name="parent">The parent custom type descriptor.</param>
        public LinqToEntitiesTypeDescriptor(LinqToEntitiesTypeDescriptionContext typeDescriptionContext, StructuralType edmType, ICustomTypeDescriptor parent)
            : base(parent)
        {
            _typeDescriptionContext = typeDescriptionContext;
            _edmType = edmType;

            EdmMember[] timestampMembers = _edmType.Members.Where(p => ObjectContextUtilities.IsConcurrencyTimestamp(p)).ToArray();
            if (timestampMembers.Length == 1)
            {
                _timestampMember = timestampMembers[0];
            }

            if (edmType.BuiltInTypeKind == BuiltInTypeKind.EntityType)
            {
                // if any FK member of any association is also part of the primary key, then the key cannot be marked
                // Editable(false)
                EntityType entityType = (EntityType)edmType;
                _foreignKeyMembers = new HashSet<EdmMember>(entityType.NavigationProperties.SelectMany(p => p.GetDependentProperties()));
                foreach (EdmProperty foreignKeyMember in _foreignKeyMembers)
                {
                    if (entityType.KeyMembers.Contains(foreignKeyMember))
                    {
                        _keyIsEditable = true;
                        break;
                    }
                }
            }
        }
 public DomainTypeDescriptor(Type entityType, ICustomTypeDescriptor parent, bool keyIsEditable, HashSet<string> foreignKeyMembers)
     : base(parent)
 {
     this._entityType = entityType;
     this._keyIsEditable = keyIsEditable;
     this._foreignKeyMembers = foreignKeyMembers;
 }
        /// <summary>
        /// Returns a custom type descriptor for the specified type (either an entity or complex type).
        /// </summary>
        /// <param name="objectType">Type of object for which we need the descriptor</param>
        /// <param name="parent">The parent type descriptor</param>
        /// <returns>Custom type description for the specified type</returns>
        public override ICustomTypeDescriptor GetTypeDescriptor(Type objectType, ICustomTypeDescriptor parent)
        {
            // No need to deal with concurrency... Worst case scenario we have multiple 
            // instances of this thing.
            ICustomTypeDescriptor td = null;
            if (!_descriptors.TryGetValue(objectType, out td))
            {
                // call into base so the TDs are chained
                parent = base.GetTypeDescriptor(objectType, parent);

                StructuralType edmType = _typeDescriptionContext.GetEdmType(objectType);
                if (edmType != null &&
                    (edmType.BuiltInTypeKind == BuiltInTypeKind.EntityType || edmType.BuiltInTypeKind == BuiltInTypeKind.ComplexType))
                {
                    // only add an LTE TypeDescriptor if the type is an EF Entity or ComplexType
                    td = new LinqToEntitiesTypeDescriptor(_typeDescriptionContext, edmType, parent);
                }
                else
                {
                    td = parent;
                }

                _descriptors[objectType] = td;
            }

            return td;
        }
        //=====================================================================

        /// <summary>
        /// This gets a custom type descriptor for the given type and object
        /// </summary>
        /// <param name="objectType">The type of object for which to retrieve the type descriptor.</param>
        /// <param name="instance">An instance of the type.  This may be null if not instance was passed to the
        /// type descriptor.</param>
        /// <returns>An <see cref="ICustomTypeDescriptor"/> that can provide metadata for the type</returns>
        public override ICustomTypeDescriptor GetTypeDescriptor(Type objectType, object instance)
        {
            if(customTD == null)
                customTD = new ChildPropertyTypeDescriptor(base.GetTypeDescriptor(objectType, instance));

            return customTD;
        }
    internal static ICustomTypeDescriptor GetTypeDescriptor( Type objectType, ICustomTypeDescriptor descriptor )
    {
      if( descriptor == null )
        return null;

      return new DataItemTypeDescriptor( descriptor, objectType );
    }
 public ComponentImporter(Type type, ICustomTypeDescriptor typeDescriptor) : base(type)
 {
     if (typeDescriptor == null)
     {
         typeDescriptor = new Maticsoft.Json.Conversion.CustomTypeDescriptor(type);
     }
     int num = 0;
     PropertyDescriptorCollection properties = typeDescriptor.GetProperties();
     IObjectMemberImporter[] importerArray = new IObjectMemberImporter[properties.Count];
     for (int i = 0; i < properties.Count; i++)
     {
         IServiceProvider provider = properties[i] as IServiceProvider;
         if (provider != null)
         {
             IObjectMemberImporter service = (IObjectMemberImporter) provider.GetService(typeof(IObjectMemberImporter));
             if (service != null)
             {
                 importerArray[i++] = service;
                 num++;
             }
         }
     }
     this._properties = properties;
     if (num > 0)
     {
         this._importers = importerArray;
     }
 }
Example #8
0
        public ComponentImporter(Type type, ICustomTypeDescriptor typeDescriptor) :
            base(type)
        {
            if (typeDescriptor == null)
                typeDescriptor = new CustomTypeDescriptor(type);
            
            int count = 0;
            PropertyDescriptorCollection properties = typeDescriptor.GetProperties();
            IObjectMemberImporter[] importers = new IObjectMemberImporter[properties.Count];
            
            for (int i = 0; i < properties.Count; i++)
            {
                IServiceProvider sp = properties[i] as IServiceProvider;
                
                if (sp == null)
                    continue;
                
                IObjectMemberImporter importer = (IObjectMemberImporter) sp.GetService(typeof(IObjectMemberImporter));
                
                if (importer == null)
                    continue;
                
                importers[i++] = importer;
                count++;
            }

            _properties = properties;

            if (count > 0)
                _importers = importers;
        }
Example #9
0
 public GenericTypeDescriptor(Type objectType, ICustomTypeDescriptor parent)
 {
     if (objectType == null) throw new ArgumentNullException("objectType");
     if (parent == null) throw new ArgumentNullException("parent");
     type = objectType;
     parentDescriptor = parent;
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="T:DescriptorBase"/> class.
 /// </summary>
 /// <param name="provider">The provider.</param>
 /// <param name="parentdescriptor">The parentdescriptor.</param>
 /// <param name="objectType">Type of the object.</param>
 public DescriptorBase(ShapeProvider provider, ICustomTypeDescriptor parentdescriptor, Type objectType)
     : base(parentdescriptor)
 {
     this.provider = provider;
     this.type = objectType;
     mProperties = new PropertyDescriptorCollection(null);
 }
        public NHibernateTypeDescriptor(Type entityType, ICustomTypeDescriptor parent,
                                        Configuration nhibernateConfiguration, Type metaDataType)
            : base(parent)
        {
            Type metaDataType1 = metaDataType;

            while (entityType != null && entityType.Name.EndsWith("Proxy") &&
                   entityType.Assembly.GetName().Name.EndsWith("ProxyAssembly"))
                entityType = entityType.BaseType;
            this.entityType = entityType;
            this._nhibernateConfiguration = nhibernateConfiguration;
            _classMetadata = nhibernateConfiguration.GetClassMapping(this.entityType);
            _identifierCols = _classMetadata.Identifier.ColumnIterator;

            if (metaDataType1 != null)
            {
                var memberInfos =
                    metaDataType1.GetMembers(BindingFlags.DeclaredOnly | BindingFlags.Public | BindingFlags.Instance);
                foreach (var memberInfo in memberInfos)
                {
                    var attributes = memberInfo.GetCustomAttributes(false).Cast<Attribute>();
                    if (attributes.Any())
                        _metaDataAttributes.Add(memberInfo.Name, attributes);
                }
            }
        }
        /// <summary>
        /// Returns a custom type descriptor for the specified entity type
        /// </summary>
        /// <param name="objectType">Type of object for which we need the descriptor</param>
        /// <param name="parent">The parent type descriptor</param>
        /// <returns>a custom type descriptor for the specified entity type</returns>
        public override ICustomTypeDescriptor GetTypeDescriptor(Type objectType, ICustomTypeDescriptor parent)
        {
            // No need to deal with concurrency... Worst case scenario we have multiple 
            // instances of this thing.
            ICustomTypeDescriptor td = null;
            if (!this._descriptors.TryGetValue(objectType, out td))
            {
                // call into base so the TDs are chained
                parent = base.GetTypeDescriptor(objectType, parent);

                MetaType metaType = this._typeDescriptionContext.MetaModel.GetMetaType(objectType);
                if (metaType.IsEntity)
                {
                    // only add an LTS TypeDescriptor if the type is a LTS Entity type
                    td = new LinqToSqlTypeDescriptor(this._typeDescriptionContext, metaType, parent);
                }
                else
                {
                    td = parent;
                }

                this._descriptors[objectType] = td;
            }

            return td;
        }
 public AssociatedMetadataTypeTypeDescriptor(ICustomTypeDescriptor parent, Type type, Type associatedMetadataType)
     : base(parent) {
     if (associatedMetadataType != null) {
         CheckAssociatedMetadataType(type, associatedMetadataType);
         AssociatedMetadataType = associatedMetadataType;
     }
 }
        //=================================================================

        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="typeDescriptor">The type descriptor</param>
        /// <param name="propertyDescriptor">The property descriptor</param>
        public DynamicReadOnlyPropertyDescriptor(
          ICustomTypeDescriptor typeDescriptor,
          PropertyDescriptor propertyDescriptor) : base(propertyDescriptor)
        {
            typeDesc = typeDescriptor;
            propDesc = propertyDescriptor;
        }
 public override ICustomTypeDescriptor GetTypeDescriptor(Type type, ICustomTypeDescriptor parent)
 {
     if (this.LookupIsEntityType(type))
     {
         return new TableMetadataTypeDescriptor(type, base.GetTypeDescriptor(type, parent));
     }
     return base.GetTypeDescriptor(type, parent);
 }
 public ComponentImporter(Type type, ICustomTypeDescriptor typeDescriptor) :
     base(type)
 {
     if (typeDescriptor == null)
         typeDescriptor = new CustomTypeDescriptor(type);
     
     _properties = typeDescriptor.GetProperties();
 }
 public FilteredPropertiesTypeDescriptor(FilteredPropertiesTypeDescriptorProvider provider, ICustomTypeDescriptor descriptor, Type objType)
     : base(descriptor)
 {
     if (provider == null) throw new ArgumentNullException("provider");
     if (descriptor == null) throw new ArgumentNullException("descriptor");
     if (objType == null) throw new ArgumentNullException("objectType");
     objectType = objType;
 }
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="document">The script document</param>
 /// <param name="className">The class name</param>
 public ScriptNetworkLayerFactory(ScriptDocument document, string className)
 {
     Script = document;
     ClassName = className;
     Description = Properties.Resources.ScriptNetworkLayerFactory_Name;
     _config = new Dictionary<string, object>();
     _desc = new ScriptDynamicTypeDescriptor(this);
 }
 public AssociatedMetadataTypeTypeDescriptor(ICustomTypeDescriptor parent, Type type, Type associatedMetadataType)
     : base(parent) {
     AssociatedMetadataType = associatedMetadataType ?? TypeDescriptorCache.GetAssociatedMetadataType(type);
     IsSelfAssociated = (type == AssociatedMetadataType);
     if (AssociatedMetadataType != null) {
         TypeDescriptorCache.ValidateMetadataType(type, AssociatedMetadataType);
     }
 }
        /// <summary>
        /// Gets the value of an <see cref="ICustomTypeDescriptor" /> 
        /// implementation's named property.
        /// </summary>
        /// <param name="item">
        /// The <see cref="ICustomTypeDescriptor" /> implementation, from 
        /// which to extract a named property's value.
        /// </param>
        /// <param name="propertyName">
        /// The name of the property.
        /// </param>
        /// <param name="usesCaseSensitivePropertyNameMatch">
        /// A value indicating whether the property name match should be 
        /// case-sensitive.
        /// </param>
        /// <param name="exceptionThrownIfNoMatch">
        /// A value indicating whether an exception should be thrown if 
        /// no matching property can be found.
        /// </param>
        /// <returns>
        /// The value of the property named by 
        /// propertyName on item,
        /// or a null reference if 
        /// exceptionThrownIfNoMatch is false and 
        /// propertyName does not name a property on 
        /// item.
        /// </returns>
        private static object GetNamedPropertyValue(
            ICustomTypeDescriptor item,
            string propertyName,
            bool usesCaseSensitivePropertyNameMatch,
            bool exceptionThrownIfNoMatch)
        {
            PropertyDescriptor descriptor;
            StringComparison comparisonType;

            if (item == null)
            {
                throw new ArgumentNullException("item");
            }

            if (string.IsNullOrEmpty("propertyName"))
            {
                throw new ArgumentException(
                    "propertyName is a null reference or empty string.",
                    "propertyName");
            }

            if (usesCaseSensitivePropertyNameMatch)
            {
                comparisonType = StringComparison.CurrentCulture;
            }
            else
            {
                comparisonType = StringComparison.CurrentCultureIgnoreCase;
            }

            descriptor = default(PropertyDescriptor);
            foreach (PropertyDescriptor pd in item.GetProperties())
            {
                if (string.Equals(propertyName, pd.Name, comparisonType))
                {
                    descriptor = pd;
                    break;
                }
            }

            if (descriptor == default(PropertyDescriptor))
            {
                if (exceptionThrownIfNoMatch)
                {
                    throw new ArgumentException(
                        "propertyName does not name a property on item.",
                        "propertyName");
                }
                else
                {
                    return null;
                }
            }
            else
            {
                return descriptor.GetValue(item);
            }
        }
Example #21
0
        /// <summary>
        /// Gets the <see cref="System.ComponentModel.TypeDescriptor"/> for the specified Type, using the specified parent descriptor
        /// as the base. Overrides should call base to ensure the <see cref="System.ComponentModel.TypeDescriptor"/>s are chained properly.
        /// </summary>
        /// <param name="type">The Type to return a descriptor for.</param>
        /// <param name="parent">The parent descriptor.</param>
        /// <returns>The <see cref="System.ComponentModel.TypeDescriptor"/> for the specified Type.</returns>
        public virtual ICustomTypeDescriptor GetTypeDescriptor(Type type, ICustomTypeDescriptor parent)
        {
            if (type == null)
                throw Error.ArgumentNull("type");
            if (parent == null)
                throw Error.ArgumentNull("parent");

            return _parentProvider != null ? _parentProvider.GetTypeDescriptor(type, parent) : parent;
        }
    internal DataItemTypeDescriptor( ICustomTypeDescriptor parent, Type objectType )
      : base( parent )
    {
      if( parent == null )
        throw new ArgumentNullException( "parent" );

      m_targetType = objectType;
      m_descriptorType = parent.GetType();
    }
        /// <summary>
        /// Overridables for the derived class to provide a custom type descriptor.
        /// </summary>
        /// <param name="parent">Parent custom type descriptor.</param>
        /// <param name="element">Element to be described.</param>
        protected override ElementTypeDescriptor CreateTypeDescriptor(ICustomTypeDescriptor parent, ModelElement element)
        {
            if (element is AutomationSettingsSchema)
            {
                return new AutomationSettingsTypeDescriptor(parent, element);
            }

            return base.CreateTypeDescriptor(parent, element);
        }
        /// <summary>
        /// Returns an instance of a type descriptor for the given instance of the class.
        /// </summary>
        protected override ElementTypeDescriptor CreateTypeDescriptor(ICustomTypeDescriptor parent, ModelElement element)
        {
            if (element is NamedElementSchema)
            {
                return new NamedElementTypeDescriptor(parent, element);
            }

            return base.CreateTypeDescriptor(parent, element);
        }
 protected override ElementTypeDescriptor CreateTypeDescriptor(ICustomTypeDescriptor parent, ModelElement element)
 {
     var nameableItem = element as NameableItem;
     if (nameableItem != null)
     {
         return new NameableItemDescriptor(parent, nameableItem);
     }
     return base.CreateTypeDescriptor(parent, element);
 }
 /// <summary>
 /// Determines whether a type uses any features requiring the
 /// <see cref="DataControllerTypeDescriptor"/> to be registered. We do this
 /// check as an optimization so we're not adding additional TDPs to the
 /// chain when they're not necessary.
 /// </summary>
 /// <param name="descriptor">The descriptor for the type to check.</param>
 /// <param name="keyIsEditable">Indicates whether the key for this Type is editable.</param>
 /// <param name="foreignKeyMembers">The set of foreign key members for the Type.</param>
 /// <returns>Returns <c>true</c> if the type uses any features requiring the
 /// <see cref="DataControllerTypeDescriptionProvider"/> to be registered.</returns>
 internal static bool ShouldRegister(ICustomTypeDescriptor descriptor, bool keyIsEditable, HashSet<string> foreignKeyMembers)
 {
     return descriptor.GetProperties()
                      .OfType<PropertyDescriptor>()
                      .Any(
                          propertyDescriptor =>
                              ShouldInferAttributes(propertyDescriptor, keyIsEditable, foreignKeyMembers)
         );
 }
		/// <summary>
		/// Creates the type descriptor.
		/// </summary>
		/// <param name="parent">The parent type descriptor.</param>
		/// <param name="element">The model element.</param>
		/// <returns></returns>
		protected override ElementTypeDescriptor CreateTypeDescriptor(ICustomTypeDescriptor parent, ModelElement element)
		{
			if(element is IExtensibleObject)
			{
				return new ExtendedTypeDescriptor(element as IExtensibleObject);
			}

			return null;
		} 
        /// <summary>
        /// Gets the display name for a class. Looks for the <see cref="DisplayNameAttribute"/>
        /// attribute, and falls back to the class's name by default.
        /// </summary>
        /// <param name="descriptor">The class's type descriptor</param>
        /// <returns>The display name of the class</returns>
        internal static string GetDisplayName(ICustomTypeDescriptor descriptor)
        {
            var displayNameAttribute = descriptor.GetAttribute<DisplayNameAttribute>();
            if (displayNameAttribute != null && !String.IsNullOrEmpty(displayNameAttribute.DisplayName)) {
                return displayNameAttribute.DisplayName;
            }

            return descriptor.GetClassName().Split('.', '+').Last();
        }
        /// <summary>
        /// Returns an instance of a type descriptor for the given instance of the class.
        /// </summary>
        protected override ElementTypeDescriptor CreateTypeDescriptor(ICustomTypeDescriptor parent, ModelElement element)
        {
            if (element is CustomizationPolicySchema)
            {
                return new CustomizationPolicyTypeDescriptor(parent, element);
            }

            return base.CreateTypeDescriptor(parent, element);
        }
        /// <summary>
        /// Returns an instance of a type descriptor for the given instance of the class.
        /// </summary>
        protected override ElementTypeDescriptor CreateTypeDescriptor(ICustomTypeDescriptor parent, ModelElement element)
        {
            if (element is ElementLink)
            {
                return new ContainingLinkSchemaTypeDescriptor(element as ElementLink);
            }

            return base.CreateTypeDescriptor(parent, element);
        }
        PropertyDescriptorCollection ITypedList.GetItemProperties(PropertyDescriptor[] listAccessors)
        {
            ICustomTypeDescriptor d = First as ICustomTypeDescriptor;

            return(d?.GetProperties());
        }
Example #32
0
 public AssociationDescriptor(ICustomTypeDescriptor parent, Association association)
     : base(parent, association)
 {
 }
Example #33
0
 public ComponentExporter(Type inputType, ICustomTypeDescriptor typeDescriptor) :
     this(inputType, typeDescriptor != null ?
          typeDescriptor.GetProperties() : (new CustomTypeDescriptor(inputType)).GetProperties())
 {
 }
Example #34
0
        public override ICustomTypeDescriptor GetTypeDescriptor(Type objectType, object instance)
        {
            ICustomTypeDescriptor defaultDescriptor = base.GetTypeDescriptor(objectType, instance);

            return(new FCTBTypeDescriptor(defaultDescriptor, instance));
        }
Example #35
0
 internal HyperTypeDescriptor(ICustomTypeDescriptor parent, Type objectType)
     : base(parent)
 {
     propertyCollection = WrapProperties(parent.GetProperties(), objectType);
 }
 /// <summary>
 /// Initializes a new instance of <see cref="GroupingElementRelationshipTypeDescriptor"/> specified
 /// by <paramref name="selectedElement"/>.
 /// </summary>
 public GroupingElementRelationshipTypeDescriptor(ICustomTypeDescriptor parent, GroupingElementRelationship selectedElement)
     : base(parent, selectedElement)
 {
 }
        private static IEnumerable <DevicePropertyValueModel> ExtractPropertyValueModels(
            ICustomTypeDescriptor deviceProperties)
        {
            DevicePropertyValueModel currentData;
            object currentValue;
            Dictionary <string, DevicePropertyMetadata> devicePropertyIndex;
            int  editableOrdering;
            bool isDisplayedRegistered;
            bool isDisplayedUnregistered;
            bool isEditable;
            int  nonediableOrdering;
            DevicePropertyMetadata propertyMetadata;

            Debug.Assert(deviceProperties != null, "deviceProperties is a null reference.");

            devicePropertyIndex = GetDevicePropertyConfiguration().ToDictionary(t => t.Name);

            // For now, display r/o properties first.
            editableOrdering   = 1;
            nonediableOrdering = int.MinValue;

            foreach (PropertyDescriptor prop in deviceProperties.GetProperties())
            {
                if (devicePropertyIndex.TryGetValue(prop.Name, out propertyMetadata))
                {
                    isDisplayedRegistered   = propertyMetadata.IsDisplayedForRegisteredDevices;
                    isDisplayedUnregistered = propertyMetadata.IsDisplayedForUnregisteredDevices;
                    isEditable = propertyMetadata.IsEditable;
                }
                else
                {
                    isDisplayedRegistered   = isEditable = true;
                    isDisplayedUnregistered = false;
                }

                if (!isDisplayedRegistered && !isDisplayedUnregistered)
                {
                    continue;
                }

                // Mark R/O properties as not-ediable.
                if (prop.IsReadOnly)
                {
                    isEditable = false;
                }

                currentData = new DevicePropertyValueModel()
                {
                    Name         = prop.Name,
                    PropertyType = propertyMetadata.PropertyType
                };

                if (isEditable)
                {
                    currentData.IsEditable   = true;
                    currentData.DisplayOrder = editableOrdering++;
                }
                else
                {
                    currentData.IsEditable   = false;
                    currentData.DisplayOrder = nonediableOrdering++;
                }

                currentData.IsIncludedWithUnregisteredDevices = isDisplayedUnregistered;

                currentValue = prop.GetValue(deviceProperties);
                if (currentValue == null)
                {
                    currentData.Value = string.Empty;
                }
                else
                {
                    currentData.Value = string.Format(CultureInfo.InvariantCulture, "{0}", currentValue);
                }

                yield return(currentData);
            }
        }
Example #38
0
 public XTypeDescriptor(ICustomTypeDescriptor parent) : base(parent)
 {
 }
 public DataItemTypeDescriptor(ICustomTypeDescriptor parent, object instance)
     : base(parent)
 {
 }
Example #40
0
        // NOTE: Keep in sync with ElementTypeDescriptor<TModelElement> and PresentationElementTypeDescriptor<TPresentationElement,TModelElement>

        #region Constructor
        /// <summary>
        /// Initializes a new instance of <see cref="DiagramTypeDescriptor{TPresentationElement,TModelElement}"/> for
        /// the instance of <typeparamref name="TPresentationElement"/> specified by <paramref name="presentationElement"/>
        /// that is associated with the instance of <typeparamref name="TModelElement"/> specified by <paramref name="selectedElement"/>.
        /// </summary>
        public DiagramTypeDescriptor(ICustomTypeDescriptor parent, TPresentationElement presentationElement, TModelElement selectedElement)
#if VISUALSTUDIO_10_0
            : base(parent, presentationElement)
#else
            : base(parent, presentationElement, selectedElement)
Example #41
0
        public void GetTypeDescriptor_InvokeTypeObjectWithParent_ReturnsExpected(Type objectType, object instance, ICustomTypeDescriptor result)
        {
            var mockParentProvider = new Mock <TypeDescriptionProvider>(MockBehavior.Strict);

            mockParentProvider
            .Setup(p => p.GetTypeDescriptor(objectType, instance))
            .Returns(result)
            .Verifiable();
            var provider = new SubTypeDescriptionProvider(mockParentProvider.Object);

            Assert.Same(result, provider.GetTypeDescriptor(objectType, instance));
            mockParentProvider.Verify(p => p.GetTypeDescriptor(objectType, instance), Times.Once());

            // Call again.
            Assert.Same(result, provider.GetTypeDescriptor(objectType, instance));
            mockParentProvider.Verify(p => p.GetTypeDescriptor(objectType, instance), Times.Exactly(2));
        }
        private void netEditor_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
                GraphNode node = netEditor.SelectedObject as GraphNode;

                if (node != null)
                {
                    BaseNodeConfig config = (BaseNodeConfig)node.Tag;

                    PropertyDescriptorCollection coll = TypeDescriptor.GetProperties(config);

                    foreach (PropertyDescriptor desc in coll)
                    {
                        if (typeof(IDocumentObject).IsAssignableFrom(desc.PropertyType))
                        {
                            object o = config;
                            ICustomTypeDescriptor custom = config as ICustomTypeDescriptor;
                            if (custom != null)
                            {
                                o = custom.GetPropertyOwner(desc);
                            }

                            IDocumentObject document = (IDocumentObject)desc.GetValue(o);
                            if (document == null)
                            {
                                if (MessageBox.Show(this, Resources.ResourceManager.GetString("NetGraphDocumentControl_NoDocumentSet", GeneralUtils.GetCurrentCulture()),
                                                    Resources.ResourceManager.GetString("NetGraphDocumentControl_NoDocumentSetCaption", GeneralUtils.GetCurrentCulture()),
                                                    MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                                {
                                    // Create document
                                    if (desc.PropertyType == typeof(ScriptDocument))
                                    {
                                        using (SelectScriptTemplateForm frm = new SelectScriptTemplateForm())
                                        {
                                            if (frm.ShowDialog(this) == DialogResult.OK)
                                            {
                                                ScriptDocument script = CANAPEProject.CurrentProject.CreateDocument <ScriptDocument>(frm.Template.TypeName);
                                                script.Script = frm.Template.GetText();
                                                document      = script;
                                            }
                                        }
                                    }
                                    else
                                    {
                                        document = CANAPEProject.CurrentProject.CreateDocument(desc.PropertyType);
                                    }
                                }
                            }

                            if (document != null)
                            {
                                DocumentControl.Show(document);
                                desc.SetValue(o, document);

                                // Reset selected objects
                                propertyGrid.SelectedObjects = propertyGrid.SelectedObjects;
                            }

                            break;
                        }
                    }
                }
            }
        }
Example #43
0
        /// <summary>
        /// 获取某个属性的值
        /// </summary>
        /// <param name="container">数据源</param>
        /// <param name="propName">属性名</param>
        /// <param name="exist">是否存在此属性</param>
        /// <returns>属性值</returns>
        internal static object GetPropertyValue(object container, string propName, out bool exist)
        {
            exist = false;
            object value = null;

            if (container == null)
            {
                throw new ArgumentNullException("container");
            }
            if (string.IsNullOrEmpty(propName))
            {
                throw new ArgumentNullException("propName");
            }
            if (Utility.IsInteger(propName))
            {
                #region 索引值部分
                //属性名只为数字.则取数组索引
                int index = Utility.ConverToInt32(propName);
                if (container is IList)
                {
                    IList iList = (IList)container;
                    if (iList.Count > index)
                    {
                        exist = true;
                        value = iList[index];
                    }
                }
                else if (container is ICollection)
                {
                    ICollection ic = (ICollection)container;
                    if (ic.Count > index)
                    {
                        exist = true;
                        IEnumerator ie = ic.GetEnumerator();
                        int         i  = 0;
                        while (i++ <= index)
                        {
                            ie.MoveNext();
                        }
                        value = ie.Current;
                    }
                }
                else
                {
                    //判断是否含有索引属性
                    PropertyInfo item = container.GetType().GetProperty("Item", new Type[] { typeof(int) });
                    if (item != null)
                    {
                        try
                        {
                            value = item.GetValue(container, new object[] { index });
                            exist = true;
                        }
                        catch
                        {
                            exist = false;
                        }
                    }
                }
                #endregion
            }
            else
            {
                #region 字段/属性/键值
                //容器是类型.则查找静态属性或字段
                Type         type  = container is Type ? (Type)container : container.GetType();
                BindingFlags flags = BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.IgnoreCase;
                if (!(container is Type))
                {
                    flags |= BindingFlags.Instance;
                }

                //查找字段
                FieldInfo field = type.GetField(propName, flags);
                if (field != null)
                {
                    exist = true;
                    value = field.GetValue(container);
                }
                else
                {
                    //查找属性
                    PropertyInfo property = type.GetProperty(propName, flags, null, null, Type.EmptyTypes, new ParameterModifier[0]);
                    if (property != null)
                    {
                        exist = true;
                        value = property.GetValue(container, null);
                    }
                    else if (container is ICustomTypeDescriptor)
                    {
                        //已实现ICustomTypeDescriptor接口
                        ICustomTypeDescriptor ictd       = (ICustomTypeDescriptor)container;
                        PropertyDescriptor    descriptor = ictd.GetProperties().Find(propName, true);
                        if (descriptor != null)
                        {
                            exist = true;
                            value = descriptor.GetValue(container);
                        }
                    }
                    else if (container is IDictionary)
                    {
                        //是IDictionary集合
                        IDictionary idic = (IDictionary)container;
                        if (idic.Contains(propName))
                        {
                            exist = true;
                            value = idic[propName];
                        }
                    }
                    else if (container is NameObjectCollectionBase)
                    {
                        //是NameObjectCollectionBase派生对象
                        NameObjectCollectionBase nob = (NameObjectCollectionBase)container;

                        //调用私有方法
                        MethodInfo method = nob.GetType().GetMethod("BaseGet", BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance, null, new Type[] { typeof(string) }, new ParameterModifier[] { new ParameterModifier(1) });
                        if (method != null)
                        {
                            value = method.Invoke(container, new object[] { propName });
                            exist = value != null;
                        }
                    }
                    else
                    {
                        //判断是否含有索引属性
                        PropertyInfo item = type.GetProperty("Item", new Type[] { typeof(string) });
                        if (item != null)
                        {
                            try
                            {
                                value = item.GetValue(container, new object[] { propName });
                                exist = true;
                            }
                            catch
                            {
                                exist = false;
                            }
                        }
                    }
                }
                #endregion
            }
            return(value);
        }
        /// <summary>
        /// Redirect class name to grouped element
        /// </summary>
        /// <returns></returns>
        public override string GetClassName()
        {
            ICustomTypeDescriptor targetDescriptor = TargetTypeDescriptor;

            return(targetDescriptor != null?TargetTypeDescriptor.GetClassName() : base.GetClassName());
        }
Example #45
0
 /// <summary>
 /// Initializes a new instance of <see cref="ReadingTypeDescriptor{TModelElement}"/>
 /// for <paramref name="selectedElement"/>.
 /// </summary>
 public ReadingTypeDescriptor(ICustomTypeDescriptor parent, TModelElement selectedElement)
     : base(parent, selectedElement)
 {
 }
        public override ICustomTypeDescriptor GetTypeDescriptor(Type objectType, object instance)
        {
            ICustomTypeDescriptor td = base.GetTypeDescriptor(objectType, instance);

            return(new DataItemTypeDescriptor(td, instance));
        }
 public static IEnumerable <PropertyDescriptor> GetPropertiesWith <TAttribute>(this ICustomTypeDescriptor td)
     where TAttribute : Attribute
 {
     return(td.GetPropertiesWith <TAttribute>(x => true));
 }
        public static IEnumerable <TAttribute> GetAttributes <TAttribute>(this ICustomTypeDescriptor td) where TAttribute : Attribute
        {
            var attributes = td.GetAttributes().OfType <TAttribute>();

            return(TypeExtensions.SortAttributesIfPossible(attributes));
        }
Example #49
0
 public WebAppExtenderFilter(ICustomTypeDescriptor innerObject)
 {
     this._innerObject = innerObject;
 }
Example #50
0
//-------------------------------------------------------------------------------------------
        public void GenerateMenu(RowAction currentPage, Type type)
        {
            string[]     allowedRoles = GetUserRoles();
            MethodInfo[] methods      = type.GetMethods();
            foreach (MethodInfo method in methods)
            {
                foreach (object attrib in method.GetCustomAttributes(typeof(DynamicDataWebMethod), true))
                {
                    DynamicDataWebMethod ddMethod = (DynamicDataWebMethod)attrib;
                    if (ddMethod.HasAnyRole(allowedRoles))
                    {
                        LinkButton webMethod = new LinkButton();
                        webMethod.ID          = "DynamicWebMethod_" + method.Name;
                        webMethod.Text        = ((DynamicDataWebMethod)attrib).MethodName;
                        webMethod.CommandName = method.Name;
                        webMethod.Click      += new EventHandler(DynamicWebMethod_Click);
                        webMethod.CssClass    = "attachmentLink";
                        webMethod.ToolTip     = "Accessible to: " + String.Join(", ", ddMethod.Roles);

                        AvailableActions.Controls.Add(webMethod);

                        if (ddMethod.RequiresPostback)
                        {
                            PostBackTrigger trig1 = new PostBackTrigger();
                            trig1.ControlID = "DynamicWebMethod_" + method.Name;
                            UpdatePanel1.Triggers.Add(trig1);
                        }
                        break;
                    }

                    //if (attrib.GetType() == typeof(CSSAttribute))
                    //{
                    //     ShowError(((CSSAttribute)attrib)._CSS);
                    //}
                }
            }

            ICustomTypeDescriptor descriptor = FormView1.DataItem as ICustomTypeDescriptor;

            if (descriptor != null)
            {
                EntityObject owner = (EntityObject)descriptor.GetPropertyOwner(null);
                if (typeof(INavigationActions).IsAssignableFrom(owner.GetType()))
                {
                    var NavActions = owner as INavigationActions;
                    List <WeavverMenuItem> items = (List <WeavverMenuItem>)NavActions.GetItemMenu();
                    if (items != null)
                    {
                        foreach (WeavverMenuItem item in items)
                        {
                            if (item.Link.StartsWith("control://"))
                            {
                                string controlPath = item.Link.Substring(10);
                                if (File.Exists(Server.MapPath(controlPath)))
                                {
                                    WeavverUserControl customControl = (WeavverUserControl)LoadControl(controlPath);
                                    //quickAdd.DataSaved += new DataSavedHandler(QuickAdd_DataSaved);
                                    AvailableActions.Controls.Add(customControl);
                                }
                            }
                            else
                            {
                                LinkButton webMethod = new LinkButton();
                                webMethod.ID          = "DynamicMethod_" + item.Name;
                                webMethod.Text        = item.Name;
                                webMethod.CommandName = item.Name;
                                webMethod.CssClass    = "attachmentLink";
                                AvailableActions.Controls.Add(webMethod);
                            }
                        }
                    }
                }
            }
        }
        public ImageItemTypeDescriptor(ICustomTypeDescriptor parent, object instance)
            : base(parent)
        {
//			instance = instance as BaseTextItem;
        }
Example #52
0
 /// <summary>
 /// Initializes a new instance of <see cref="MandatoryConstraintTypeDescriptor{TModelElement}"/>
 /// for <paramref name="selectedElement"/>.
 /// </summary>
 public MandatoryConstraintTypeDescriptor(ICustomTypeDescriptor parent, TModelElement selectedElement)
     : base(parent, selectedElement)
 {
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="NamedElementTypeDescriptor"/> class.
 /// </summary>
 /// <param name="parent">The parent.</param>
 /// <param name="modelElement">The model element.</param>
 public NamedElementTypeDescriptor(ICustomTypeDescriptor parent, ModelElement modelElement)
     : base(parent, modelElement)
 {
 }
        public override ICustomTypeDescriptor GetTypeDescriptor(Type objectType, object instance)
        {
            ICustomTypeDescriptor baseDescriptor = base.GetTypeDescriptor(objectType, instance);

            return(new AssociatedMetadataTypeTypeDescriptor(baseDescriptor, objectType, _associatedMetadataType));
        }
Example #55
0
        protected void CheckBoxList1_DataBound(object sender, EventArgs e)
        {
            MetaTable childTable = ChildrenColumn.ChildTable;

            // Comments assume employee/territory for illustration, but the code is generic

            IList         entityList    = null;
            ObjectContext objectContext = null;

            if (Mode == DataBoundControlMode.Edit)
            {
                object entity;
                ICustomTypeDescriptor rowDescriptor = Row as ICustomTypeDescriptor;
                if (rowDescriptor != null)
                {
                    // Get the real entity from the wrapper
                    entity = rowDescriptor.GetPropertyOwner(null);
                }
                else
                {
                    entity = Row;
                }

                // Get the collection of territories for this employee and make sure it's loaded
                RelatedEnd entityCollection = Column.EntityTypeProperty.GetValue(entity, null) as RelatedEnd;
                if (entityCollection == null)
                {
                    throw new InvalidOperationException(String.Format("The ManyToMany template does not support the collection type of the '{0}' column on the '{1}' table.", Column.Name, Table.Name));
                }
                if (!entityCollection.IsLoaded)
                {
                    entityCollection.Load();
                }

                // Get an IList from it (i.e. the list of territories for the current employee)
                // REVIEW: we should be using EntityCollection directly, but EF doesn't have a
                // non generic type for it. They will add this in vnext
                entityList = ((IListSource)entityCollection).GetList();

                // Get the current ObjectContext
                // REVIEW: this is quite a dirty way of doing this. Look for better alternative
                ObjectQuery objectQuery = (ObjectQuery)entityCollection.GetType().GetMethod(
                    "CreateSourceQuery").Invoke(entityCollection, null);
                objectContext = objectQuery.Context;
            }

            // Go through all the territories (not just those for this employee)
            foreach (object childEntity in childTable.GetQuery(objectContext))
            {
                // this is a modified implementation, to support Dynamic Data's dynamic proxy
                MetaTable actualTable;
                ListItem  listItem = null;

                if (!MetaTable.TryGetTable(childEntity.GetType(), out actualTable))
                {
                    actualTable = MetaTable.CreateTable(childEntity.GetType());
                }

                listItem = new ListItem(
                    actualTable.GetDisplayString(childEntity),
                    actualTable.GetPrimaryKeyString(childEntity));


                // Make it selected if the current employee has that territory
                if (Mode == DataBoundControlMode.Edit)
                {
                    listItem.Selected = entityList.Contains(childEntity);
                }

                CheckBoxList1.Items.Add(listItem);
            }
        }
 /// <summary>
 /// Main constructor that accepts the parent custom type descriptor
 /// </summary>
 /// <param name="parent">The parent custom type descriptor.</param>
 public TypeDescriptorBase(ICustomTypeDescriptor parent)
     : base(parent)
 {
 }
 /// <summary>
 /// Initializes a new instance of <see cref="NameGeneratorTypeDescriptor{TModelElement}"/>
 /// for <paramref name="selectedElement"/>.
 /// </summary>
 public NameGeneratorTypeDescriptor(ICustomTypeDescriptor parent, TModelElement selectedElement)
     : base(parent, selectedElement)
 {
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="ItemsBagTypeDescriptor" /> class.
 /// </summary>
 /// <param name="parent">The parent.</param>
 /// <param name="instance">The instance.</param>
 public ItemsBagTypeDescriptor(ICustomTypeDescriptor parent, object instance)
     : base(parent)
 {
     this.bag = (ItemsBag)instance;
 }
Example #59
0
        PropertyDescriptorCollection ICustomTypeDescriptor.GetProperties(Attribute[] attributes)
        {
            ICustomTypeDescriptor d = this;

            return(d.GetProperties());
        }
Example #60
0
 /// <summary>
 /// Initializes a new instance of <see cref="FactTypeDerivationRuleTypeDescriptor{TModelElement}"/>
 /// for <paramref name="selectedElement"/>.
 /// </summary>
 public FactTypeDerivationRuleTypeDescriptor(ICustomTypeDescriptor parent, TModelElement selectedElement)
     : base(parent, selectedElement)
 {
 }