Example #1
0
        public dynamic As()
        {
            if (CellControlComponentType == null)
            {
                CellControlComponentType = typeof(Label);
            }

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

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

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

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

                return(instance);
            }
            else
            {
                return(Create(CellControlBy, CellControlComponentType));
            }
        }
Example #2
0
        public TComponent As <TComponent>()
            where TComponent : Component, new()
        {
            CellControlComponentType = typeof(TComponent);
            if (CellControlBy == null)
            {
                object instance   = Activator.CreateInstance(CellControlComponentType);
                var    byProperty = CellControlComponentType.GetProperty("By");
                byProperty?.SetValue(instance, By, null);

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

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

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