public static string GetDefaultPropertyName(object instance)
        {
            DefaultPropertyAttribute attribute = (DefaultPropertyAttribute)TypeDescriptor.GetAttributes(instance)[typeof(DefaultPropertyAttribute)];

            return(attribute != null ? attribute.Name : (string)null);
        }
Exemple #2
0
 public AttributeCollection GetAttributes()
 {
     return(TypeDescriptor.GetAttributes(Object.GetType()));
 }
        protected override void Configure()
        {
            var catalog = new AggregateCatalog();

            foreach (var item in AssemblySource.Instance)
            {
                catalog.Catalogs.Add(new AssemblyCatalog(item));
            }

            this.container = new CompositionContainer(catalog);

            var batch         = new CompositionBatch();
            var windowManager = new AppWindowManager();

            AppMessageBox.WindowManager = ModalDialogBase.WindowManager = windowManager;

            batch.AddExportedValue <IWindowManager>(windowManager);
            batch.AddExportedValue <IEventAggregator>(new EventAggregator());
            batch.AddExportedValue <IAppConfiguration>(this.configs);
            batch.AddExportedValue <IServiceProvider>(this);
            batch.AddExportedValue <ICompositionService>(this.container);

            foreach (var item in this.GetParts())
            {
                var contractName = AttributedModelServices.GetContractName(item.Item1);
                var typeIdentity = AttributedModelServices.GetTypeIdentity(item.Item1);
                batch.AddExport(new Export(contractName, new Dictionary <string, object>
                {
                    {
                        "ExportTypeIdentity",
                        typeIdentity
                    }
                }, () => item.Item2));
            }
            this.container.Compose(batch);
            this.container.SatisfyImportsOnce(windowManager);

            var defaultLocateForView = ViewModelLocator.LocateForView;

            ViewModelLocator.LocateForView = (view) =>
            {
                object viewModel = defaultLocateForView(view);
                if (viewModel != null)
                {
                    return(viewModel);
                }

                if (TypeDescriptor.GetAttributes(view)[typeof(ModelAttribute)] is ModelAttribute attr)
                {
                    if (attr.ModelType.IsInterface == true)
                    {
                        return(this.GetInstance(attr.ModelType, null));
                    }
                    return(TypeDescriptor.CreateInstance(null, attr.ModelType, null, null));
                }

                return(viewModel);
            };

            var defaultLocateTypeForModelType = ViewLocator.LocateTypeForModelType;

            ViewLocator.LocateTypeForModelType = (vmType, location, context) =>
            {
                var attribute = vmType.GetCustomAttributes(typeof(ViewAttribute), true).OfType <ViewAttribute>().FirstOrDefault();
                if (attribute != null)
                {
                    return(Type.GetType(attribute.ViewTypeName));
                }

                var viewType = defaultLocateTypeForModelType(vmType, location, context);

                if (viewType == null)
                {
                    Type baseType = vmType.BaseType;
                    if (baseType.Name.EndsWith("ViewModel") == true)
                    {
                        return(ViewLocator.LocateTypeForModelType(baseType, location, context));
                    }
                }

                return(viewType);
            };

            var defaultLocateForModel = ViewLocator.LocateForModel;

            ViewLocator.LocateForModel = (model, displayLocation, context) =>
            {
                //IViewAware viewAware = model as IViewAware;
                //if (viewAware != null)
                //{
                //    UIElement uIElement = viewAware.GetView(context) as UIElement;
                //    if (uIElement != null)
                //    {
                //        Window window = uIElement as Window;
                //        if (window == null || (!window.IsLoaded && !(new System.Windows.Interop.WindowInteropHelper(window).Handle == IntPtr.Zero)))
                //        {
                //            //ViewLocator.Log.Info("Using cached view for {0}.", new object[]
                //            //{
                //            //    model
                //            //});
                //            return uIElement;
                //        }
                //    }
                //}
                var view = defaultLocateForModel(model, displayLocation, context);

                if (view != null && view.GetType().GetCustomAttributes <ExportAttribute>(true).Any() == false)
                {
                    this.container.SatisfyImportsOnce(view);
                }

                return(view);
            };
        }
 public AttributeCollection GetAttributes()
 {
     return(TypeDescriptor.GetAttributes(mCurrentSelectObject));
 }
Exemple #5
0
        /// <summary>
        ///      Ensures that the verb list has been created.
        /// </summary>
        protected void EnsureVerbs()
        {
            // We apply global verbs only if the base component is the
            // currently selected object.
            //
            bool useGlobalVerbs = false;

            if (_currentVerbs is null && _serviceProvider != null)
            {
                Hashtable buildVerbs = null;
                ArrayList verbsOrder;

                if (_selectionService is null)
                {
                    _selectionService = GetService(typeof(ISelectionService)) as ISelectionService;

                    if (_selectionService != null)
                    {
                        _selectionService.SelectionChanging += new EventHandler(this.OnSelectionChanging);
                    }
                }

                int verbCount = 0;
                DesignerVerbCollection localVerbs          = null;
                DesignerVerbCollection designerActionVerbs = new DesignerVerbCollection(); // we instanciate this one here...
                IDesignerHost          designerHost        = GetService(typeof(IDesignerHost)) as IDesignerHost;

                if (_selectionService != null && designerHost != null && _selectionService.SelectionCount == 1)
                {
                    object selectedComponent = _selectionService.PrimarySelection;
                    if (selectedComponent is IComponent &&
                        !TypeDescriptor.GetAttributes(selectedComponent).Contains(InheritanceAttribute.InheritedReadOnly))
                    {
                        useGlobalVerbs = (selectedComponent == designerHost.RootComponent);

                        // LOCAL VERBS
                        IDesigner designer = designerHost.GetDesigner((IComponent)selectedComponent);
                        if (designer != null)
                        {
                            localVerbs = designer.Verbs;
                            if (localVerbs != null)
                            {
                                verbCount      += localVerbs.Count;
                                _verbSourceType = selectedComponent.GetType();
                            }
                            else
                            {
                                _verbSourceType = null;
                            }
                        }

                        // DesignerAction Verbs
                        DesignerActionService daSvc = GetService(typeof(DesignerActionService)) as DesignerActionService;
                        if (daSvc != null)
                        {
                            DesignerActionListCollection actionLists = daSvc.GetComponentActions(selectedComponent as IComponent);
                            if (actionLists != null)
                            {
                                foreach (DesignerActionList list in actionLists)
                                {
                                    DesignerActionItemCollection dai = list.GetSortedActionItems();
                                    if (dai != null)
                                    {
                                        for (int i = 0; i < dai.Count; i++)
                                        {
                                            DesignerActionMethodItem dami = dai[i] as DesignerActionMethodItem;
                                            if (dami != null && dami.IncludeAsDesignerVerb)
                                            {
                                                EventHandler handler = new EventHandler(dami.Invoke);
                                                DesignerVerb verb    = new DesignerVerb(dami.DisplayName, handler);
                                                designerActionVerbs.Add(verb);
                                                verbCount++;
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }

                // GLOBAL VERBS
                if (useGlobalVerbs && _globalVerbs is null)
                {
                    useGlobalVerbs = false;
                }

                if (useGlobalVerbs)
                {
                    verbCount += _globalVerbs.Count;
                }

                // merge all
                buildVerbs = new Hashtable(verbCount, StringComparer.OrdinalIgnoreCase);
                verbsOrder = new ArrayList(verbCount);

                // PRIORITY ORDER FROM HIGH TO LOW: LOCAL VERBS - DESIGNERACTION VERBS - GLOBAL VERBS
                if (useGlobalVerbs)
                {
                    for (int i = 0; i < _globalVerbs.Count; i++)
                    {
                        string key = ((DesignerVerb)_globalVerbs[i]).Text;
                        buildVerbs[key] = verbsOrder.Add(_globalVerbs[i]);
                    }
                }
                if (designerActionVerbs.Count > 0)
                {
                    for (int i = 0; i < designerActionVerbs.Count; i++)
                    {
                        string key = designerActionVerbs[i].Text;
                        buildVerbs[key] = verbsOrder.Add(designerActionVerbs[i]);
                    }
                }
                if (localVerbs != null && localVerbs.Count > 0)
                {
                    for (int i = 0; i < localVerbs.Count; i++)
                    {
                        string key = localVerbs[i].Text;
                        buildVerbs[key] = verbsOrder.Add(localVerbs[i]);
                    }
                }

                // look for duplicate, prepare the result table
                DesignerVerb[] result = new DesignerVerb[buildVerbs.Count];
                int            j      = 0;
                for (int i = 0; i < verbsOrder.Count; i++)
                {
                    DesignerVerb value = (DesignerVerb)verbsOrder[i];
                    string       key   = value.Text;
                    if ((int)buildVerbs[key] == i)
                    { // there's not been a duplicate for this entry
                        result[j] = value;
                        j++;
                    }
                }

                _currentVerbs = new DesignerVerbCollection(result);
            }
        }
Exemple #6
0
        public virtual void Initialize(Type type)
        {
            CheckUnlocked();

            if (type != null)
            {
                TypeName = type.FullName;
                AssemblyName assemblyName = type.Assembly.GetName(true);
                if (type.Assembly.GlobalAssemblyCache)
                {
                    assemblyName.CodeBase = null;
                }

                Dictionary <string, AssemblyName> parents = new Dictionary <string, AssemblyName>();
                Type parentType = type;
                while (parentType != null)
                {
                    AssemblyName policiedname = parentType.Assembly.GetName(true);

                    AssemblyName aname = GetNonRetargetedAssemblyName(type, policiedname);

                    if (aname != null && !parents.ContainsKey(aname.FullName))
                    {
                        parents[aname.FullName] = aname;
                    }
                    parentType = parentType.BaseType;
                }

                AssemblyName[] parentAssemblies = new AssemblyName[parents.Count];
                int            i = 0;
                foreach (AssemblyName an in parents.Values)
                {
                    parentAssemblies[i++] = an;
                }

                this.DependentAssemblies = parentAssemblies;

                AssemblyName = assemblyName;
                DisplayName  = type.Name;

                //if the Type is a reflectonly type, these values must be set through a config object or manually
                //after construction.
                if (!type.Assembly.ReflectionOnly)
                {
                    object[] companyattrs = type.Assembly.GetCustomAttributes(typeof(AssemblyCompanyAttribute), true);
                    if (companyattrs != null && companyattrs.Length > 0)
                    {
                        AssemblyCompanyAttribute company = companyattrs[0] as AssemblyCompanyAttribute;
                        if (company != null && company.Company != null)
                        {
                            Company = company.Company;
                        }
                    }

                    //set the description based off the description attribute of the given type.
                    DescriptionAttribute descattr = (DescriptionAttribute)TypeDescriptor.GetAttributes(type)[typeof(DescriptionAttribute)];
                    if (descattr != null)
                    {
                        this.Description = descattr.Description;
                    }

                    ToolboxBitmapAttribute attr = (ToolboxBitmapAttribute)TypeDescriptor.GetAttributes(type)[typeof(ToolboxBitmapAttribute)];
                    if (attr != null)
                    {
                        Bitmap itemBitmap = attr.GetImage(type, false) as Bitmap;
                        if (itemBitmap != null)
                        {
                            // Original bitmap is used when adding the item to the Visual Studio toolbox
                            // if running on a machine with HDPI scaling enabled.
                            OriginalBitmap = attr.GetOriginalBitmap();
                            if ((itemBitmap.Width != iconWidth || itemBitmap.Height != iconHeight))
                            {
                                itemBitmap = new Bitmap(itemBitmap, new Size(iconWidth, iconHeight));
                            }
                        }
                        Bitmap = itemBitmap;
                    }

                    bool      filterContainsType = false;
                    ArrayList array = new ArrayList();
                    foreach (Attribute a in TypeDescriptor.GetAttributes(type))
                    {
                        ToolboxItemFilterAttribute ta = a as ToolboxItemFilterAttribute;
                        if (ta != null)
                        {
                            if (ta.FilterString.Equals(TypeName))
                            {
                                filterContainsType = true;
                            }
                            array.Add(ta);
                        }
                    }

                    if (!filterContainsType)
                    {
                        array.Add(new ToolboxItemFilterAttribute(TypeName));
                    }

                    Filter = (ToolboxItemFilterAttribute[])array.ToArray(typeof(ToolboxItemFilterAttribute));
                }
            }
        }
        /// <summary>A Type extension method that converts a type to a type.</summary>
        ///
        /// <param name="type">The type to act on.</param>
        ///
        /// <returns>type as a MetadataType.</returns>
        public static MetadataType ToType(this Type type)
        {
            if (type == null)
            {
                return(null);
            }

            var metaType = new MetadataType
            {
                Name        = type.Name,
                Namespace   = type.Namespace,
                GenericArgs = type.IsGenericType
                    ? type.GetGenericArguments().Select(x => x.Name).ToArray()
                    : null,
                Attributes = type.ToAttributes(),
                Properties = type.ToProperties(),
            };

            if (type.BaseType != null && type.BaseType != typeof(object))
            {
                metaType.Inherits            = type.BaseType.Name;
                metaType.InheritsGenericArgs = type.BaseType.IsGenericType
                    ? type.BaseType.GetGenericArguments().Select(x => x.Name).ToArray()
                    : null;
            }

            if (type.GetTypeWithInterfaceOf(typeof(IReturnVoid)) != null)
            {
                metaType.ReturnVoidMarker = true;
            }
            else
            {
                var genericMarker = type.GetTypeWithGenericTypeDefinitionOf(typeof(IReturn <>));
                if (genericMarker != null)
                {
                    metaType.ReturnMarkerGenericArgs = genericMarker.GetGenericArguments().Select(x => x.Name).ToArray();
                }
            }

            var typeAttrs  = TypeDescriptor.GetAttributes(type);
            var routeAttrs = typeAttrs.OfType <RouteAttribute>().ToList();

            if (routeAttrs.Count > 0)
            {
                metaType.Routes = routeAttrs.ConvertAll(x =>
                                                        new MetadataRoute
                {
                    Path    = x.Path,
                    Notes   = x.Notes,
                    Summary = x.Summary,
                    Verbs   = x.Verbs,
                });
            }

            var descAttr = typeAttrs.OfType <DescriptionAttribute>().FirstOrDefault();

            if (descAttr != null)
            {
                metaType.Description = descAttr.Description;
            }

            var dcAttr = type.GetDataContract();

            if (dcAttr != null)
            {
                metaType.DataContract = new MetadataDataContract
                {
                    Name      = dcAttr.Name,
                    Namespace = dcAttr.Namespace,
                };
            }

            return(metaType);
        }
        public IndexDefinitionStorage(
            ITransactionalStorage transactionalStorage,
            string path,
            IEnumerable <AbstractViewGenerator> compiledGenerators,
            AbstractDynamicCompilationExtension[] extensions)
        {
            this.extensions = extensions;            // this is used later in the ctor, so it must appears first
            this.path       = Path.Combine(path, IndexDefDir);

            if (Directory.Exists(this.path) == false)
            {
                Directory.CreateDirectory(this.path);
            }

            foreach (var index in Directory.GetFiles(this.path, "*.index"))
            {
                try
                {
                    AddAndCompileIndex(
                        MonoHttpUtility.UrlDecode(Path.GetFileNameWithoutExtension(index)),
                        JsonConvert.DeserializeObject <IndexDefinition>(File.ReadAllText(index), new JsonEnumConverter())
                        );
                }
                catch (Exception e)
                {
                    logger.Warn("Could not compile index " + index + ", skipping bad index", e);
                }
            }

            //compiled view generators always overwrite dynamic views
            foreach (var generator in compiledGenerators)
            {
                var copy           = generator;
                var displayNameAtt = TypeDescriptor.GetAttributes(copy)
                                     .OfType <DisplayNameAttribute>()
                                     .FirstOrDefault();

                var name = displayNameAtt != null ? displayNameAtt.DisplayName : copy.GetType().Name;

                transactionalStorage.Batch(actions =>
                {
                    if (actions.Indexing.GetIndexesStats().Any(x => x.Name == name))
                    {
                        return;
                    }

                    actions.Indexing.AddIndex(name);
                });

                var indexDefinition = new IndexDefinition
                {
                    Map = "Compiled map function: " + generator.GetType().AssemblyQualifiedName,
                    // need to supply this so the index storage will create map/reduce index
                    Reduce     = generator.ReduceDefinition == null ? null : "Compiled reduce function: " + generator.GetType().AssemblyQualifiedName,
                    Indexes    = generator.Indexes,
                    Stores     = generator.Stores,
                    IsCompiled = true
                };
                indexCache.AddOrUpdate(name, copy, (s, viewGenerator) => copy);
                indexDefinitions.AddOrUpdate(name, indexDefinition, (s1, definition) => indexDefinition);
            }
        }
Exemple #9
0
 public static void AllowMultiple()
 {
     Assert.Equal(3, TypeDescriptor.GetAttributes(typeof(AllowMultipleClass)).Count);
 }
 AttributeCollection ICustomTypeDescriptor.GetAttributes() => TypeDescriptor.GetAttributes(this, true);
 AttributeCollection ICustomTypeDescriptor.GetAttributes()
 {
     // Gets the attributes of the target object
     return(TypeDescriptor.GetAttributes(_target, true));
 }
 public virtual AttributeCollection GetAttributes()
 {
     return(TypeDescriptor.GetAttributes(_componentPointer, true));
 }
Exemple #13
0
 public AttributeCollection GetAttributes() => TypeDescriptor.GetAttributes(this, true);
Exemple #14
0
 /// <summary>GetAttributes.</summary>
 /// <returns>AttributeCollection</returns>
 public AttributeCollection GetAttributes()
 {
     return(TypeDescriptor.GetAttributes(_selectedObject, true));
 }
Exemple #15
0
 public AttributeCollection GetAttributes()
 {
     return(TypeDescriptor.GetAttributes(elementViewModel, true));
 }
Exemple #16
0
 // Most of the functions required by the ICustomTypeDescriptor are
 // merely pssed on to the default TypeDescriptor for this type,
 // which will do something appropriate.  The exceptions are noted
 // below.
 AttributeCollection ICustomTypeDescriptor.GetAttributes()
 {
     return(TypeDescriptor.GetAttributes(this, true));
 }
Exemple #17
0
        public virtual AttributeCollection GetAttributes()
        {
            AttributeCollection col = TypeDescriptor.GetAttributes(this, true);

            return(col);
        }
Exemple #18
0
 /// <summary>
 /// GetAttributes
 /// </summary>
 /// <returns>AttributeCollection</returns>
 public AttributeCollection GetAttributes()
 {
     return(TypeDescriptor.GetAttributes(this, true));
 }
Exemple #19
0
        private static string GetMethodNamespace(object methodGroup)
        {
            var attributes = TypeDescriptor.GetAttributes(methodGroup.GetType()).OfType <ScriptNamespaceAttribute>().ToArray();

            return(attributes[0].Namespace);
        }