/// <summary> /// Recupera a propriedade pelo nome informado. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="typeDescriptor"></param> /// <param name="propertyName"></param> /// <returns></returns> public static T Property<T>(this System.ComponentModel.ICustomTypeDescriptor typeDescriptor, string propertyName) { System.ComponentModel.PropertyDescriptor descriptor = System.ComponentModel.TypeDescriptor.GetProperties(typeDescriptor)[propertyName]; if(descriptor == null) { throw new ArgumentException(string.Format(System.Globalization.CultureInfo.CurrentCulture, "Property with specified name: {0} cannot be found on type: {1}", propertyName, typeDescriptor.GetType()), "propertyName"); } return UnboxT<T>.Unbox(descriptor.GetValue(typeDescriptor)); }
public override System.ComponentModel.ICustomTypeDescriptor GetTypeDescriptor(Type objectType, object instance) { System.ComponentModel.ICustomTypeDescriptor defaultTypeDescriptor = base.GetTypeDescriptor(objectType, instance); if (instance == null) { return(defaultTypeDescriptor); } System.ComponentModel.ICustomTypeDescriptor customTypeDescriptor; if (m_ICustomTypeDescriptorCollectionByHashCode.TryGetValue(instance.GetHashCode(), out customTypeDescriptor)) { return(customTypeDescriptor); } customTypeDescriptor = new CustomTypeDescriptorBag(defaultTypeDescriptor, instance); m_ICustomTypeDescriptorCollectionByHashCode.Add(instance.GetHashCode(), customTypeDescriptor); //if (instance != null) // System.Diagnostics.Debug.WriteLine("HashCode: " + instance.GetHashCode()); return(customTypeDescriptor); }
public override System.ComponentModel.ICustomTypeDescriptor GetTypeDescriptor(Type type, System.ComponentModel.ICustomTypeDescriptor parent) { try { Activator.CreateInstance(this._domainServiceType); } catch (TargetInvocationException ex) { throw ex.InnerException; } return(null); }
public TypeDescriptionProvider(System.ComponentModel.TypeDescriptionProvider parent, System.ComponentModel.ICustomTypeDescriptor ctd) : base(parent) { m_ctd = ctd; }
/// <summary> /// Recupera o valor da propriedade. /// </summary> /// <param name="controllerContext"></param> /// <param name="bindingContext"></param> /// <param name="descriptor"></param> /// <param name="loader"></param> /// <param name="propertyName"></param> /// <returns></returns> private object GetPropertyValue(ControllerContext controllerContext, ModelBindingContext bindingContext, System.ComponentModel.ICustomTypeDescriptor descriptor, Colosoft.Business.IEntityLoader loader, string propertyName) { if (propertyName == "Uid" && !string.IsNullOrEmpty(loader.UidPropertyName)) { propertyName = loader.UidPropertyName; } var propertyMetadata = bindingContext.PropertyMetadata[propertyName]; var property = descriptor.GetProperties()[propertyName]; var propertyBinder = this.Binders.GetBinder(property.PropertyType); var propertyBindingContext = new System.Web.Mvc.ModelBindingContext(bindingContext) { ModelMetadata = propertyMetadata, ModelName = CreatePropertyModelName(bindingContext.ModelName, propertyMetadata.PropertyName) }; var value = propertyBinder.BindModel(controllerContext, propertyBindingContext); if (value == null && propertyName == "Uid") { value = GetPropertyValue(controllerContext, bindingContext, descriptor, loader, loader.UidPropertyName); } return(value); }
/// <summary> /// Recupera o valor da propriedade. /// </summary> /// <param name="controllerContext"></param> /// <param name="bindingContext"></param> /// <param name="descriptor"></param> /// <param name="loader"></param> /// <param name="propertyName"></param> /// <returns></returns> protected object GetPropertyValue(ControllerContext controllerContext, ModelBindingContext bindingContext, System.ComponentModel.ICustomTypeDescriptor descriptor, string propertyName) { var propertyMetadata = bindingContext.PropertyMetadata[propertyName]; var property = descriptor.GetProperties()[propertyName]; var propertyBinder = this.Binders.GetBinder(property.PropertyType); var propertyBindingContext = new System.Web.Mvc.ModelBindingContext(bindingContext) { ModelMetadata = propertyMetadata, ModelName = CreatePropertyModelName(bindingContext.ModelName, propertyMetadata.PropertyName) }; return(propertyBinder.BindModel(controllerContext, propertyBindingContext)); }
internal CustomTypeDescriptorBag(System.ComponentModel.ICustomTypeDescriptor parent, object instance) : base(parent) { m_Facility = (Ifc4.CcFacility)instance; }