Пример #1
0
        public IIntermediateType Add(string name, TypeKind kind)
        {
            IIntermediateType rResult = null;

            switch (kind)
            {
            case TypeKind.Class:
            {
                var result = new IntermediateClassType(name, this.Parent);
                rResult = result;
                this.Parent.Classes.Add(result);
            }
            break;

            case TypeKind.Delegate:
            {
                var result = new IntermediateDelegateType(name, this.Parent);
                rResult = result;
                this.Parent.Delegates.Add(result);
            }
            break;

            case TypeKind.Enumeration:
            {
                var result = new IntermediateEnumType(name, this.Parent);
                rResult = result;
                this.Parent.Enums.Add(result);
            }
            break;

            case TypeKind.Interface:
            {
                var result = new IntermediateInterfaceType(name, this.Parent);
                rResult = result;
                this.Parent.Interfaces.Add(result);
            }
            break;

            case TypeKind.Struct:
            {
                var result = new IntermediateStructType(name, this.Parent);
                rResult = result;
                this.Parent.Structs.Add(result);
            }
            break;

            case TypeKind.Other:
            case TypeKind.Ambiguity:
                break;

            default:
                break;
            }
            if (rResult == null)
            {
                throw new NotSupportedException();
            }
            return(rResult);
        }
Пример #2
0
        public IIntermediateGenericType Add(string name, TypeKindGeneric kind, params GenericParameterData[] genParamData)
        {
            if (genParamData == null)
            {
                throw new ArgumentNullException("genParamData");
            }
            if (name == null)
            {
                throw new ArgumentNullException("name");
            }
            IIntermediateGenericType rResult = null;
            var assembly = this.Parent.Assembly;

            switch (kind)
            {
            case TypeKindGeneric.Class:
            {
                IIntermediateClassType insertionElement = null;
                if (assembly != null)
                {
                    IIntermediateTypeCtorLanguageService <IIntermediateClassType> classService;
                    if (assembly.Provider.TryGetService(LanguageGuids.Services.ClassServices.ClassCreatorService, out classService))
                    {
                        insertionElement = classService.New(name, this.Parent);
                    }
                }
                if (insertionElement == null)
                {
                    insertionElement = new IntermediateClassType(name, this.Parent);
                }
                if (genParamData.Length > 0)
                {
                    insertionElement.TypeParameters.AddRange(genParamData);
                }
                rResult = insertionElement;
                this.Parent.Classes.Add(insertionElement);
            }
            break;

            case TypeKindGeneric.Delegate:
            {
                IIntermediateDelegateType insertionElement = null;
                if (assembly != null && assembly.Provider != null)
                {
                    IIntermediateTypeCtorLanguageService <IIntermediateDelegateType> delegateService;
                    if (assembly.Provider.TryGetService(LanguageGuids.Services.IntermediateDelegateCreatorService, out delegateService))
                    {
                        insertionElement = delegateService.New(name, this.Parent);
                    }
                }
                if (insertionElement == null)
                {
                    insertionElement = new IntermediateDelegateType(name, this.Parent);
                }
                if (genParamData.Length > 0)
                {
                    insertionElement.TypeParameters.AddRange(genParamData);
                }
                rResult = insertionElement;
                this.Parent.Delegates.Add(insertionElement);
            }
            break;

            case TypeKindGeneric.Interface:
            {
                IIntermediateInterfaceType insertionElement = null;
                if (assembly != null && assembly.Provider != null)
                {
                    IIntermediateTypeCtorLanguageService <IIntermediateInterfaceType> interfaceService;
                    if (assembly.Provider.TryGetService(LanguageGuids.Services.InterfaceServices.InterfaceCreatorService, out interfaceService))
                    {
                        insertionElement = interfaceService.New(name, this.Parent);
                    }
                }
                if (insertionElement == null)
                {
                    insertionElement = new IntermediateInterfaceType(name, this.Parent);
                }
                if (genParamData.Length > 0)
                {
                    insertionElement.TypeParameters.AddRange(genParamData);
                }
                rResult = insertionElement;
                this.Parent.Interfaces.Add(insertionElement);
            }
            break;

            case TypeKindGeneric.Struct:
            {
                IIntermediateStructType insertionElement = null;
                if (assembly != null && assembly.Provider != null)
                {
                    IIntermediateTypeCtorLanguageService <IIntermediateStructType> structService;
                    if (assembly.Provider.TryGetService(LanguageGuids.Services.StructServices.StructCreatorService, out structService))
                    {
                        insertionElement = structService.New(name, this.Parent);
                    }
                }
                if (insertionElement == null)
                {
                    insertionElement = new IntermediateStructType(name, this.Parent);
                }
                if (genParamData.Length > 0)
                {
                    insertionElement.TypeParameters.AddRange(genParamData);
                }
                rResult = insertionElement;
                this.Parent.Structs.Add(insertionElement);
            }
            break;

            default:
                throw new NotSupportedException();
            }
            return(rResult);
        }