/// <summary>
        /// See <see cref="ITypeResolutionService.GetType(string, bool, bool)"/>.
        /// </summary>
        public override Type GetType(string name, bool throwOnError, bool ignoreCase)
        {
            if (name == null)
            {
                throw new ArgumentNullException("name");
            }
            object value = typeAliases[name];

            if (value != null)
            {
                string stringValue = value as string;
                if (stringValue != null)
                {
                    // In this case, we haven't loaded the type yet. Ask the parent loader.
                    Type type = parentLoader.GetType(stringValue, throwOnError, ignoreCase);
                    if (type != null)
                    {
                        typeAliases[name] = type;
                    }
                    return(type);
                }
                else
                {
                    // We already have the type.
                    return((Type)value);
                }
            }
            else
            {
                return(parentLoader.GetType(name, throwOnError, ignoreCase));
            }
        }
示例#2
0
        private Type ResolveType(string typeName, ITypeResolutionService typeResolver)
        {
            Type resolvedType = null;

            if (typeResolver != null)
            {
                // If we cannot find the strong-named type, then try to see
                // if the TypeResolver can bind to partial names. For this,
                // we will strip out the partial names and keep the rest of the
                // strong-name information to try again.

                resolvedType = typeResolver.GetType(typeName, false);
                if (resolvedType == null)
                {
                    string[] typeParts = typeName.Split(',');

                    // Break up the type name from the rest of the assembly strong name.
                    if (typeParts != null && typeParts.Length >= 2)
                    {
                        string partialName  = typeParts[0].Trim();
                        string assemblyName = typeParts[1].Trim();
                        partialName  = partialName + ", " + assemblyName;
                        resolvedType = typeResolver.GetType(partialName, false);
                    }
                }
            }

            if (resolvedType == null)
            {
                resolvedType = Type.GetType(typeName, false);
            }

            return(resolvedType);
        }
示例#3
0
        public void GetAndSetType()
        {
            Expect.Call(
                _typeResolutionServiceMock.GetType(
                    "Remotion.ObjectBinding.UnitTests.TestDomain.SimpleBusinessObjectClass, Remotion.ObjectBinding.UnitTests", true))
            .Return(typeof(SimpleBusinessObjectClass));
            _mockRepository.ReplayAll();

            Assert.That(_dataSource.Type, Is.Null);
            _dataSource.Type = typeof(SimpleBusinessObjectClass);
            Assert.That(_dataSource.Type, Is.SameAs(typeof(SimpleBusinessObjectClass)));

            _mockRepository.VerifyAll();
        }
示例#4
0
        private Type ResolveType(string typeName, ITypeResolutionService typeResolver)
        {
            if (!typeName.Contains(", System.Drawing.Common") && typeName.Contains(", System.Drawing"))
            {
                typeName = typeName.Replace(", System.Drawing", ", System.Drawing.Common");
            }

            Type t = null;

            if (typeResolver != null)
            {
                // If we cannot find the strong-named type, then try to see
                // if the TypeResolver can bind to partial names. For this,
                // we will strip out the partial names and keep the rest of the
                // strong-name information to try again.

                t = typeResolver.GetType(typeName, false);
                if (t == null)
                {
                    string[] typeParts = typeName.Split(',');

                    // Break up the type name from the rest of the assembly strong name.
                    //
                    if (typeParts.Length >= 2)
                    {
                        string partialName  = typeParts[0].Trim();
                        string assemblyName = typeParts[1].Trim();
                        partialName = partialName + ", " + assemblyName;
                        t           = typeResolver.GetType(partialName, false);
                    }
                }
            }

            if (t == null)
            {
                t = Type.GetType(typeName, false);

                if (t == null)
                {
                    var testTypeName = string.Join(",", typeName.Split(',').Take(2));
                    if (testTypeName.Length > 0)
                    {
                        t = Type.GetType(testTypeName, false);
                    }
                }
            }

            return(t);
        }
示例#5
0
        private T GetInstance <T>(ITypeResolutionService resolution, string concreteType)
        {
            Type instanceType = resolution.GetType(concreteType, true);

            ReflectionHelper.EnsureAssignableTo(instanceType, typeof(T));
            return((T)Activator.CreateInstance(instanceType));
        }
        public override bool OnNext()
        {
            TypeItem selectedTypeItem = this.SelectedTypeItem;

            System.Type type = selectedTypeItem.Type;
            if (type == null)
            {
                ITypeResolutionService service = (ITypeResolutionService)base.ServiceProvider.GetService(typeof(ITypeResolutionService));
                if (service == null)
                {
                    return(false);
                }
                try
                {
                    type = service.GetType(selectedTypeItem.TypeName, true, true);
                }
                catch (Exception exception)
                {
                    UIServiceHelper.ShowError(base.ServiceProvider, exception, System.Design.SR.GetString("ObjectDataSourceDesigner_CannotGetType", new object[] { selectedTypeItem.TypeName }));
                    return(false);
                }
            }
            if (type == null)
            {
                return(false);
            }
            if (type != this._previousSelectedType)
            {
                (base.NextPanel as ObjectDataSourceChooseMethodsPanel).SetType(type);
                this._previousSelectedType = type;
            }
            return(true);
        }
示例#7
0
        /// <summary>
        /// Creates the unbound reference and registers
        /// the reference with the Recipe Framework
        /// </summary>
        public override void Execute()
        {
            ITypeResolutionService typeLoader = GetService <ITypeResolutionService>(true);
            Type assetType = typeLoader.GetType(this.referenceType, true);

            if (!typeof(IUnboundAssetReference).IsAssignableFrom(assetType))
            {
                throw new ArgumentException(String.Format(
                                                System.Globalization.CultureInfo.CurrentCulture,
                                                Properties.Resources.CreateUnboundReferenceAction_WrongType,
                                                assetType));
            }

            ConstructorInfo ctor = assetType.GetConstructor(new Type[] { typeof(string) });

            if (ctor == null)
            {
                throw new NotSupportedException(String.Format(
                                                    System.Globalization.CultureInfo.CurrentCulture,
                                                    Properties.Resources.CreateUnboundReferenceAction_UnsupportedConstructor,
                                                    assetType));
            }

            reference = (IAssetReference)ctor.Invoke(new object[] { this.assetName });
            if (reference is IAttributesConfigurable)
            {
                ((IAttributesConfigurable)reference).Configure(this.attributes);
            }
            IAssetReferenceService service = GetService <IAssetReferenceService>(true);

            service.Add(reference);
        }
示例#8
0
        internal static System.Type GetType(IServiceProvider serviceProvider, string typeName, bool silent)
        {
            ITypeResolutionService service = null;

            if (serviceProvider != null)
            {
                service = (ITypeResolutionService)serviceProvider.GetService(typeof(ITypeResolutionService));
            }
            if (service == null)
            {
                return(null);
            }
            try
            {
                return(service.GetType(typeName, true, true));
            }
            catch (Exception exception)
            {
                if (!silent)
                {
                    UIServiceHelper.ShowError(serviceProvider, exception, System.Design.SR.GetString("ObjectDataSourceDesigner_CannotGetType", new object[] { typeName }));
                }
                return(null);
            }
        }
 private void InitializeDataNode(string basePath)
 {
     System.Type type = null;
     if (!string.IsNullOrEmpty(this.nodeInfo.TypeName))
     {
         type = internalTypeResolver.GetType(this.nodeInfo.TypeName, false, true);
     }
     if ((type != null) && type.Equals(typeof(ResXFileRef)))
     {
         string[] strArray = ResXFileRef.Converter.ParseResxFileRefString(this.nodeInfo.ValueData);
         if ((strArray != null) && (strArray.Length > 1))
         {
             if (!Path.IsPathRooted(strArray[0]) && (basePath != null))
             {
                 this.fileRefFullPath = Path.Combine(basePath, strArray[0]);
             }
             else
             {
                 this.fileRefFullPath = strArray[0];
             }
             this.fileRefType = strArray[1];
             if (strArray.Length > 2)
             {
                 this.fileRefTextEncoding = strArray[2];
             }
         }
     }
 }
示例#10
0
        /// <summary>
        /// Retrieves the <see cref="Type"/> corresponding to the <paramref name="codeClass"/>.
        /// </summary>
        /// <exception cref="InvalidOperationException">An <see cref="ITypeDiscoveryService"/> cannot be
        /// retrieved for the project the class lives in.</exception>
        /// <exception cref="InvalidOperationException">The <paramref name="codeClass"/> has not been
        /// compiled into the project still.</exception>
        public static Type ToType(CodeClass codeClass)
        {
            Guard.ArgumentNotNull(codeClass, "codeClass");

            string           typeFullName = codeClass.FullName;
            Type             returnType   = null;
            IServiceProvider provider     = ToServiceProvider(codeClass.DTE);

            DynamicTypeService typeService = VsHelper.GetService <DynamicTypeService>(provider, true);

            IVsHierarchy hier = ToHierarchy(codeClass.ProjectItem.ContainingProject);

            ITypeResolutionService typeResolution = typeService.GetTypeResolutionService(hier);

            if (typeResolution == null)
            {
                throw new InvalidOperationException(String.Format(
                                                        CultureInfo.CurrentCulture,
                                                        Properties.Resources.ServiceMissing,
                                                        typeof(ITypeResolutionService)));
            }

            returnType = typeResolution.GetType(typeFullName);
            if (returnType == null)
            {
                throw new InvalidOperationException(String.Format(
                                                        CultureInfo.CurrentCulture,
                                                        Properties.Resources.ClassNotCompiledYet,
                                                        typeFullName,
                                                        codeClass.ProjectItem.get_FileNames(1)));
            }

            return(returnType);
        }
示例#11
0
    private Type GetTypeFromName(IServiceProvider serviceProvider, string typeName)
    {
        ITypeResolutionService typeResolutionSvc = (ITypeResolutionService)serviceProvider
                                                   .GetService(typeof(ITypeResolutionService));

        return(typeResolutionSvc.GetType(typeName));
    }
示例#12
0
        private void EnsureInitializeMetadataForCurrentRecipe()
        {
            if (!argumentsMetaDataByRecipe.ContainsKey(currentRecipe.Configuration.Name))
            {
                Dictionary <string, ValueInfo> infos;
                if (currentRecipe.Configuration.Arguments == null)
                {
                    infos = new Dictionary <string, ValueInfo>(0);
                }
                else
                {
                    infos = new Dictionary <string, ValueInfo>(currentRecipe.Configuration.Arguments.Length);
                    foreach (Config.Argument argument in currentRecipe.Configuration.Arguments)
                    {
                        ITypeResolutionService resolution = currentRecipe.GetService <ITypeResolutionService>(true);
                        Type          argumentType        = resolution.GetType(argument.Type, true);
                        TypeConverter converter           = null;

                        if (argument.Converter != null)
                        {
                            converter = CreateAndConfigureConverter(argument, resolution, converter);
                        }
                        else
                        {
                            converter = GetBuiltInConverter(argumentType, converter);
                        }

                        infos.Add(argument.Name, new ValueInfo(argument.Name, argument.Required, argumentType, converter));
                    }
                }

                argumentsMetaDataByRecipe.Add(currentRecipe.Configuration.Name, infos);
            }
        }
示例#13
0
        /// <summary>
        /// Returns schema information for each property on
        /// the object.
        /// </summary>
        /// <remarks>All public properties on the object
        /// will be reflected in this schema list except
        /// for those properties where the
        /// <see cref="BrowsableAttribute">Browsable</see> attribute
        /// is False.
        /// </remarks>
        public System.Web.UI.Design.IDataSourceFieldSchema[] GetFields()
        {
            ITypeResolutionService typeService = null;
            List <ObjectFieldInfo> result      = new List <ObjectFieldInfo>();

            if (_designer != null)
            {
                Type objectType = null;
                try
                {
                    typeService = (ITypeResolutionService)(_designer.Site.GetService(typeof(ITypeResolutionService)));
                    objectType  = typeService.GetType(_typeName, true, false);

                    if (typeof(IEnumerable).IsAssignableFrom(objectType))
                    {
                        // this is a list so get the item type
                        objectType = Utilities.GetChildItemType(objectType);
                    }
                    PropertyDescriptorCollection props = TypeDescriptor.GetProperties(objectType);
                    foreach (PropertyDescriptor item in props)
                    {
                        if (item.IsBrowsable)
                        {
                            result.Add(new ObjectFieldInfo(item));
                        }
                    }
                }
                catch
                { /* do nothing - just swallow exception */ }
            }

            return(result.ToArray());
        }
示例#14
0
        private void InitializeDataNode(string basePath)
        {
            // we can only use our internal type resolver here
            // because we only want to check if this is a ResXFileRef node
            // and we can't be sure that we have a typeResolutionService that can
            // recognize this. It's not very clean but this should work.
            Type nodeType = null;

            if (!string.IsNullOrEmpty(nodeInfo.TypeName)) // can be null if we have a string (default for string is TypeName == null)
            {
                nodeType = internalTypeResolver.GetType(nodeInfo.TypeName, false, true);
            }

            if (nodeType != null && nodeType.Equals(typeof(ResXFileRef)))
            {
                // we have a fileref, split the value data and populate the fields
                string[] fileRefDetails = ResXFileRef.Converter.ParseResxFileRefString(nodeInfo.ValueData);
                if (fileRefDetails != null && fileRefDetails.Length > 1)
                {
                    if (!Path.IsPathRooted(fileRefDetails[0]) && basePath != null)
                    {
                        fileRefFullPath = Path.Combine(basePath, fileRefDetails[0]);
                    }
                    else
                    {
                        fileRefFullPath = fileRefDetails[0];
                    }
                    fileRefType = fileRefDetails[1];
                    if (fileRefDetails.Length > 2)
                    {
                        fileRefTextEncoding = fileRefDetails[2];
                    }
                }
            }
        }
示例#15
0
 internal static Microsoft.Practices.ComponentModel.ServiceContainer CreateFilter(IServiceProvider provider, string filterTypeName, StringDictionary attributes, out ICodeModelEditorFilter filter)
 {
     Microsoft.Practices.ComponentModel.ServiceContainer editorServiceProvider = new Microsoft.Practices.ComponentModel.ServiceContainer(true);
     editorServiceProvider.Site = new Site(provider, editorServiceProvider, editorServiceProvider.GetType().FullName);
     editorServiceProvider.AddService(typeof(IDictionaryService), new DictionaryWrapper(attributes));
     if (string.IsNullOrEmpty(filterTypeName))
     {
         filter = null;
     }
     else
     {
         ITypeResolutionService typeResService =
             (ITypeResolutionService)provider.GetService(typeof(ITypeResolutionService));
         Type filterType = typeResService.GetType(filterTypeName);
         if (filterType == null)
         {
             filter = null;
         }
         else
         {
             filter = (ICodeModelEditorFilter)Activator.CreateInstance(filterType);
             if (filter is IComponent)
             {
                 editorServiceProvider.Add((IComponent)filter);
             }
         }
     }
     return(editorServiceProvider);
 }
示例#16
0
        /// <summary>
        /// Sets the properties of the current action using the values provided, if possible.
        /// </summary>
        /// <param name="attributes">A <see cref="StringDictionary"/> containing the set of attributes
        /// to use to set the properties of the action.</param>
        public virtual void Configure(StringDictionary attributes)
        {
            PropertyDescriptorCollection props;
            ISite mysite = this.Site;

            try
            {
                // Must remove the site temporarily because
                // otherwise the TypeDescriptor doesn't work properly.
                this.Site = null;
                props     = TypeDescriptor.GetProperties(this);
            }
            finally
            {
                this.Site = mysite;
            }

            foreach (string key in attributes.Keys)
            {
                PropertyDescriptor prop = props[key];
                if (prop == null || prop.IsReadOnly)
                {
                    continue;
                }
                TypeConverter          converter = null;
                TypeConverterAttribute convattr  = (TypeConverterAttribute)prop.Attributes[typeof(TypeConverterAttribute)];
                if (convattr != null && !string.IsNullOrEmpty(convattr.ConverterTypeName))
                {
                    ITypeResolutionService resolutionService = (ITypeResolutionService)
                                                               ServiceHelper.GetService(this, typeof(ITypeResolutionService));
                    Type type = resolutionService.GetType(convattr.ConverterTypeName, true);
                    converter = (TypeConverter)Activator.CreateInstance(type);
                }
                else
                {
                    converter = TypeDescriptor.GetConverter(prop.PropertyType);
                }
                object value;
                try
                {
                    // Perform minimum conversion if necessary.
                    if (!prop.PropertyType.IsAssignableFrom(typeof(string)))
                    {
                        value = converter.ConvertFromString(new CustomDescriptor(this, prop), attributes[key]);
                    }
                    else
                    {
                        value = attributes[key];
                    }
                    prop.SetValue(this, value);
                }
                catch (TargetInvocationException e)
                {
                    throw e.InnerException;
                }
            }
        }
        /// <summary>
        /// This method sets various values on the newly created component.
        /// </summary>
        private IComponent[] RunWizard(IDesignerHost host, IComponent[] comps)
        {
            DialogResult result  = DialogResult.No;
            IVsUIShell   uiShell = null;

            if (host != null)
            {
                uiShell = (IVsUIShell)host.GetService(typeof(IVsUIShell));
            }

            // Always use the UI shell service to show a messagebox if possible.
            // There are also some useful helper methods for this in VsShellUtilities.
            if (uiShell != null)
            {
                int  nResult   = 0;
                Guid emptyGuid = Guid.Empty;

                uiShell.ShowMessageBox(0, ref emptyGuid, "Question", "Do you want to set the Text property?", null, 0,
                                       OLEMSGBUTTON.OLEMSGBUTTON_YESNO, OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_SECOND, OLEMSGICON.OLEMSGICON_QUERY, 0, out nResult);

                if (nResult == IDYES)
                {
                    result = DialogResult.Yes;
                }
            }
            else
            {
                result = MessageBox.Show("Do you want to set the Text property?", "Question", MessageBoxButtons.YesNo);
            }

            if (result == DialogResult.Yes)
            {
                if (comps.Length > 0)
                {
                    // Use Types from the ITypeResolutionService.  Do not use locally defined types.
                    ITypeResolutionService typeResolver = (ITypeResolutionService)host.GetService(typeof(ITypeResolutionService));
                    if (typeResolver != null)
                    {
                        Type t = typeResolver.GetType(typeof(MyCustomTextBoxWithPopup).FullName);

                        // Check to ensure we got the right Type.
                        if (t != null && comps[0].GetType().IsAssignableFrom(t))
                        {
                            // Use a property descriptor instead of direct property access.
                            // This will allow the change to appear in the undo stack and it will get
                            // serialized correctly.
                            PropertyDescriptor pd = TypeDescriptor.GetProperties(comps[0])["Text"];
                            if (pd != null)
                            {
                                pd.SetValue(comps[0], "Text Property was initialized!");
                            }
                        }
                    }
                }
            }
            return(comps);
        }
示例#18
0
        private Type FindType(string typeName)
        {
#if CONFIG_COMPONENT_MODEL_DESIGN
            if (typeResolver == null)
            {
                return(Type.GetType(typeName));
            }
            else
#endif
            return(typeResolver.GetType(typeName));
        }
示例#19
0
        public override Type BindToType(string assemblyName, [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)] string typeName)
        {
            if (_typeResolver is null)
            {
                return(null);
            }

            typeName = typeName + ", " + assemblyName;

            Type type = _typeResolver.GetType(typeName);

            if (type is null)
            {
                string[] typeParts = typeName.Split(',');

                // Break up the assembly name from the rest of the assembly strong name.
                // we try 1) FQN 2) FQN without a version 3) just the short name
                if (typeParts is not null && typeParts.Length > 2)
                {
                    string partialName = typeParts[0].Trim();

                    for (int i = 1; i < typeParts.Length; ++i)
                    {
                        string typePart = typeParts[i].Trim();
                        if (!typePart.StartsWith("Version=") && !typePart.StartsWith("version="))
                        {
                            partialName = partialName + ", " + typePart;
                        }
                    }

                    type = _typeResolver.GetType(partialName);
                    if (type is null)
                    {
                        type = _typeResolver.GetType(typeParts[0].Trim());
                    }
                }
            }

            // Binder couldn't handle it, let the default loader take over.
            return(type);
        }
        public override Type BindToType(string assemblyName, string typeName)
        {
            if (typeResolver == null)
            {
                return(null);
            }

            typeName = typeName + ", " + assemblyName;

            Type t = typeResolver.GetType(typeName);

            if (t == null)
            {
                string[] typeParts = typeName.Split(',');

                // Break up the assembly name from the rest of the assembly strong name.
                // we try 1) FQN 2) FQN without a version 3) just the short name
                if (typeParts.Length > 2)
                {
                    string partialName = typeParts[0].Trim();

                    for (int i = 1; i < typeParts.Length; ++i)
                    {
                        string s = typeParts[i].Trim();
                        if (!s.StartsWith("Version=") && !s.StartsWith("version="))
                        {
                            partialName = partialName + ", " + s;
                        }
                    }

                    t = typeResolver.GetType(partialName);
                    if (t == null)
                    {
                        t = typeResolver.GetType(typeParts[0].Trim());
                    }
                }
            }

            // Binder couldn't handle it, let the default loader take over.
            return(t);
        }
示例#21
0
        /// <summary>
        /// Allows to change the value of the Editor
        /// </summary>
        /// <param name="context"></param>
        /// <param name="provider"></param>
        /// <param name="value"></param>
        /// <returns></returns>
        public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
        {
            if (referenceType != null && reference == null)
            {
                ITypeResolutionService resolver = (ITypeResolutionService)ServiceHelper.GetService(provider,
                                                                                                   typeof(ITypeResolutionService), this);
                Type type = resolver.GetType(referenceType, true);
                ReflectionHelper.EnsureAssignableTo(type, typeof(IUnboundAssetReference));
                reference = (IUnboundAssetReference)Activator.CreateInstance(type, String.Empty);
            }

            DTE vs = (DTE)ServiceHelper.GetService(provider, typeof(DTE), this);

            using (SolutionPickerControl control = new SolutionPickerControl(
                       vs, reference, value, context.PropertyDescriptor.PropertyType))
            {
                // Set site so the control can find the IWindowsFormsEditorService
                control.Site = new Site(provider, control, control.GetType().FullName);
                //control.SelectionChanged += new SelectionChangedEventHandler(OnSelectionChanged);
                first        = true;
                initialValue = value;

                formsService = (IWindowsFormsEditorService)ServiceHelper.GetService(
                    provider, typeof(IWindowsFormsEditorService), this);
                formsService.DropDownControl(control);
                formsService = null;
                if (reference != null)
                {
                    bool enabled;
                    try
                    {
                        enabled = reference.IsEnabledFor(control.SelectedTarget);
                    }
                    catch (Exception ex)
                    {
                        throw new RecipeExecutionException(reference.AssetName,
                                                           Properties.Resources.Reference_FailEnabledFor, ex);
                    }
                    if (enabled)
                    {
                        return(control.SelectedTarget);
                    }
                    else
                    {
                        return(null);
                    }
                }
                else
                {
                    return(control.SelectedTarget);
                }
            }
        }
示例#22
0
 public bool HasField(string fullTypeName, string fieldName)
 {
     if (_resolution != null)
     {
         Type type = _resolution.GetType(fullTypeName);
         if (type != null)
         {
             return(type.GetField(fieldName) != null);
         }
     }
     return(false);
 }
示例#23
0
        private void InitializeDataNode(string basePath)
        {
            // we can only use our internal type resolver here
            // because we only want to check if this is a ResXFileRef node
            // and we can't be sure that we have a typeResolutionService that can
            // recognize this. It's not very clean but this should work.
            Type nodeType = null;

            if (nodeInfo.TypeName != null)
            {
                if (nodeInfo.TypeName.Contains("ResXFileRef"))
                {
                    nodeType = typeof(ResXFileRef);
                }
                else if (nodeInfo.TypeName.Contains("ResXNullRef"))
                {
                    nodeType = typeof(ResXNullRef);
                }
                else
                {
                    nodeType = internalTypeResolver.GetType(nodeInfo.TypeName, false, true);
                }
            }
            else
            {
                nodeType = typeof(string);
            }

            if (nodeType != null && nodeType == typeof(ResXFileRef))
            {
                // we have a fileref, split the value data and populate the fields
                string[] fileRefDetails = ResxFileRefStringConverter.ParseResxFileRefString(nodeInfo.ValueData);
                if (fileRefDetails != null && fileRefDetails.Length > 1)
                {
                    if (!Path.IsPathRooted(fileRefDetails[0]) && basePath != null)
                    {
                        fileRefFullPath = Path.Combine(basePath, fileRefDetails[0]);
                    }
                    else
                    {
                        fileRefFullPath = fileRefDetails[0];
                    }

                    fileRefType = Type.GetType(string.Join(",", fileRefDetails[1].Split(',').Take(2)), true)
                                  .AssemblyQualifiedName;
                    if (fileRefDetails.Length > 2)
                    {
                        fileRefTextEncoding = fileRefDetails[2];
                    }
                }
            }
        }
示例#24
0
        private Type GetValidFilterType(ITypeResolutionService resolution, string filterTypeName)
        {
            Type ft = resolution.GetType(filterTypeName, true);

            if (!typeof(ITypeFilterProvider).IsAssignableFrom(ft))
            {
                throw new ArgumentException(String.Format(
                                                CultureInfo.CurrentCulture,
                                                Properties.Resources.InvalidTypeFilter,
                                                ft, typeof(ITypeFilterProvider)));
            }
            return(ft);
        }
示例#25
0
        public System.Type GetType(string typeName)
        {
            ITypeResolutionService typeResolver = (ITypeResolutionService)GetService(typeof(ITypeResolutionService));

            if (typeResolver == null)
            {
                return(Type.GetType(typeName));
            }
            else
            {
                return(typeResolver.GetType(typeName));
            }
        }
示例#26
0
        private Type ResolveType(string typeName)
        {
            if (string.IsNullOrEmpty(typeName))
            {
                return(null);
            }

            typeName = typeName.Trim();

            var type = _typeResolutionService.GetType(typeName);

            if (type == null)
            {
                type = CsTypeToClrType(typeName);
                if (type == null)
                {
                    type = _typeResolutionService.GetType("System." + typeName);
                }
            }

            return(type);
        }
示例#27
0
        /// <summary>
        /// Loads the type.
        /// </summary>
        /// <param name="typeName">Name of the type.</param>
        /// <returns></returns>
        private Type LoadType(string typeName)
        {
            if (DataGridView.Site != null)
            {
                ITypeResolutionService typeResolution = (ITypeResolutionService)DataGridView.Site.GetService(typeof(ITypeResolutionService));
                if (typeResolution != null)
                {
                    return(typeResolution.GetType(typeName, true));
                }
            }

            return(Type.GetType(typeName, true));
        }
示例#28
0
        /// <summary>
        /// This function is the callback used to execute the command when the menu item is clicked.
        /// See the constructor to see how the menu item is associated with this function using
        /// OleMenuCommandService service and MenuCommand class.
        /// </summary>
        /// <param name="sender">Event sender.</param>
        /// <param name="e">Event args.</param>
        private void MenuItemCallback(object sender, EventArgs e)
        {
            var userConfig = this._dte2.SelectedItems.Item(1).ProjectItem.ContainingProject.GetProjectConfiguration();

            DynamicTypeService typeService;
            IVsSolution        solutionService;
            IVsHierarchy       projectHierarchy;

            using (ServiceProvider serviceProvider = new ServiceProvider((Microsoft.VisualStudio.OLE.Interop.IServiceProvider) this._dte2.DTE))
            {
                typeService     = (DynamicTypeService)serviceProvider.GetService(typeof(DynamicTypeService));
                solutionService = (IVsSolution)serviceProvider.GetService(typeof(SVsSolution));
            }

            int uniqueProjectName = solutionService.GetProjectOfUniqueName(this._dte2.SelectedItems.Item(1).ProjectItem.ContainingProject.UniqueName, out projectHierarchy);

            if (uniqueProjectName != 0)
            {
                throw Marshal.GetExceptionForHR(uniqueProjectName);
            }

            ITypeResolutionService resolutionService = typeService.GetTypeResolutionService(projectHierarchy);

            try
            {
                var itemNamespace = this._dte2.SelectedItems.Item(1)?.ProjectItem?.GetNameSpace();

                Type type = resolutionService.GetType($"{itemNamespace.FullName}.{_fileName}");

                var dbContextInfo = new DbContextInfo(type, userConfig);

                var filePath = $"{_fileDirectory}\\{_fileName}.edmx";
                using (var writer = new XmlTextWriter(filePath, Encoding.Default))
                {
                    EdmxWriter.WriteEdmx(dbContextInfo.CreateInstance(), writer);
                }

                _dte2.ItemOperations.OpenFile(filePath);
            }
            catch (Exception ex)
            {
                IVsUIShell uiShell = (IVsUIShell)Package.GetGlobalService(typeof(SVsUIShell));
                Guid       clsid   = Guid.Empty;
                int        result;
                uiShell.ShowMessageBox(0, ref clsid, "Ef Model Generator", string.Format(CultureInfo.CurrentCulture, "Inside {0}.Initialize()", this.GetType().FullName),
                                       ex.ToString(), 0, OLEMSGBUTTON.OLEMSGBUTTON_OK, OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST, OLEMSGICON.OLEMSGICON_INFO,
                                       0, out result);
            }
        }
示例#29
0
        internal static System.Web.Compilation.ExpressionBuilder GetExpressionBuilder(string expressionPrefix, VirtualPath virtualPath, IDesignerHost host)
        {
            if (expressionPrefix.Length == 0)
            {
                if (dataBindingExpressionBuilder == null)
                {
                    dataBindingExpressionBuilder = new DataBindingExpressionBuilder();
                }
                return(dataBindingExpressionBuilder);
            }
            CompilationSection compilationConfig = null;

            if (host != null)
            {
                IWebApplication application = (IWebApplication)host.GetService(typeof(IWebApplication));
                if (application != null)
                {
                    compilationConfig = application.OpenWebConfiguration(true).GetSection("system.web/compilation") as CompilationSection;
                }
            }
            if (compilationConfig == null)
            {
                compilationConfig = MTConfigUtil.GetCompilationConfig(virtualPath);
            }
            System.Web.Configuration.ExpressionBuilder builder = compilationConfig.ExpressionBuilders[expressionPrefix];
            if (builder == null)
            {
                throw new HttpParseException(System.Web.SR.GetString("InvalidExpressionPrefix", new object[] { expressionPrefix }));
            }
            Type c = null;

            if (host != null)
            {
                ITypeResolutionService service = (ITypeResolutionService)host.GetService(typeof(ITypeResolutionService));
                if (service != null)
                {
                    c = service.GetType(builder.Type);
                }
            }
            if (c == null)
            {
                c = builder.TypeInternal;
            }
            if (!typeof(System.Web.Compilation.ExpressionBuilder).IsAssignableFrom(c))
            {
                throw new HttpParseException(System.Web.SR.GetString("ExpressionBuilder_InvalidType", new object[] { c.FullName }));
            }
            return((System.Web.Compilation.ExpressionBuilder)HttpRuntime.FastCreatePublicInstance(c));
        }
示例#30
0
        public Type GetType(string typeName)
        {
            Type type = null;
            ITypeResolutionService typeResolverService = (ITypeResolutionService)GetService(typeof(ITypeResolutionService));

            if (typeResolverService != null)
            {
                type = typeResolverService.GetType(typeName);
            }
            else
            {
                type = Type.GetType(typeName);
            }
            return(type);
        }
        private Type ResolveType(string typeName, ITypeResolutionService typeResolver) {
            Type t = null;            
            if (typeResolver != null) {

                // If we cannot find the strong-named type, then try to see
                // if the TypeResolver can bind to partial names. For this, 
                // we will strip out the partial names and keep the rest of the
                // strong-name information to try again.
                //

                t = typeResolver.GetType(typeName, false);
                if (t == null) {
                    
                    string[] typeParts = typeName.Split(new char[] {','});

                    // Break up the type name from the rest of the assembly strong name.
                    //
                    if (typeParts != null && typeParts.Length >= 2) {
                        string partialName = typeParts[0].Trim();
                        string assemblyName = typeParts[1].Trim();                            
                        partialName = partialName + ", " + assemblyName;
                        t = typeResolver.GetType(partialName, false);
                    }
                }
            }

            if (t == null) {
                t = Type.GetType(typeName, false);
            }
            
            return t;
        }
 private System.Type ResolveType(string typeName, ITypeResolutionService typeResolver)
 {
     System.Type type = null;
     if (typeResolver != null)
     {
         type = typeResolver.GetType(typeName, false);
         if (type == null)
         {
             string[] strArray = typeName.Split(new char[] { ',' });
             if ((strArray != null) && (strArray.Length >= 2))
             {
                 string name = strArray[0].Trim();
                 string str2 = strArray[1].Trim();
                 name = name + ", " + str2;
                 type = typeResolver.GetType(name, false);
             }
         }
     }
     if (type == null)
     {
         type = System.Type.GetType(typeName, false);
     }
     return type;
 }
示例#33
0
		protected Type ResolveType (string typeString, ITypeResolutionService typeResolver) 
		{
			Type result = null;

			if (typeResolver != null)
				result = typeResolver.GetType (typeString);

			if (result == null)
				result = ResolveType (typeString);

			return result;
		}
 public static ComponentDesigner GetComponentDesignerForType(ITypeResolutionService tr, System.Type type)
 {
     ComponentDesigner designer = null;
     DesignerAttribute attribute = null;
     AttributeCollection attributes = TypeDescriptor.GetAttributes(type);
     for (int i = 0; i < attributes.Count; i++)
     {
         DesignerAttribute attribute2 = attributes[i] as DesignerAttribute;
         if (attribute2 != null)
         {
             System.Type type2 = System.Type.GetType(attribute2.DesignerBaseTypeName);
             if ((type2 != null) && (type2 == iDesignerType))
             {
                 attribute = attribute2;
                 break;
             }
         }
     }
     if (attribute != null)
     {
         System.Type c = null;
         if (tr != null)
         {
             c = tr.GetType(attribute.DesignerTypeName);
         }
         else
         {
             c = System.Type.GetType(attribute.DesignerTypeName);
         }
         if ((c != null) && typeof(ComponentDesigner).IsAssignableFrom(c))
         {
             designer = (ComponentDesigner) Activator.CreateInstance(c);
         }
     }
     return designer;
 }