/// <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;
        }
Example #2
0
        /// <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);
        }