Ejemplo n.º 1
0
        public dynamic As()
        {
            if (CellControlElementType == null)
            {
                CellControlElementType = typeof(Label);
            }

            if (CellControlBy == null)
            {
                object instance   = Activator.CreateInstance(CellControlElementType);
                var    byProperty = CellControlElementType.GetProperty("By");
                byProperty?.SetValue(instance, By, null);

                var wrappedElementProperty = CellControlElementType.GetProperty("WrappedElement");
                var wrappedElementParent   = CellControlElementType.GetProperty("ParentWrappedElement");
                var wrappedElementIndex    = CellControlElementType.GetProperty("ElementIndex");

                wrappedElementProperty?.SetValue(instance, WrappedElement, null);
                wrappedElementParent?.SetValue(instance, ParentWrappedElement, null);
                wrappedElementIndex?.SetValue(instance, ElementIndex, null);

                var isRefreshableElementProperty = CellControlElementType.GetProperty("ShouldCacheElement");
                isRefreshableElementProperty?.SetValue(instance, true, null);

                return(instance);
            }
            else
            {
                return(Create(CellControlBy, CellControlElementType));
            }
        }
Ejemplo n.º 2
0
        public TElement As <TElement>()
            where TElement : Element, new()
        {
            CellControlElementType = typeof(TElement);
            if (CellControlBy == null)
            {
                object instance   = Activator.CreateInstance(CellControlElementType);
                var    byProperty = CellControlElementType.GetProperty("By");
                byProperty?.SetValue(instance, By, null);

                var wrappedElementProperty = CellControlElementType.GetProperty("WrappedElement");
                var wrappedElementParent   = CellControlElementType.GetProperty("ParentWrappedElement");
                var wrappedElementIndex    = CellControlElementType.GetProperty("ElementIndex");

                wrappedElementProperty?.SetValue(instance, WrappedElement, null);
                wrappedElementParent?.SetValue(instance, ParentWrappedElement, null);
                wrappedElementIndex?.SetValue(instance, ElementIndex, null);

                var isRefreshableElementProperty = CellControlElementType.GetProperty("ShouldCacheElement");
                isRefreshableElementProperty?.SetValue(instance, true, null);
                return(instance as TElement);
            }
            else
            {
                return(Create(CellControlBy, typeof(TElement)));
            }
        }