Esempio n. 1
0
     /*?*/
     protected TypeName ConvertToTypeName(
   string serializedTypeName
 )
     {
         TypeNameParser typeNameParser = new TypeNameParser(this.PEFileToObjectModel.NameTable, serializedTypeName);
           TypeName/*?*/ typeName = typeNameParser.ParseTypeName();
           return typeName;
     }
Esempio n. 2
0
        public void SimpleType()
        {
            var type          = typeof(string);
            var typeReference = TypeNameParser.ParseType(null, type.AssemblyQualifiedName);

            Utilities.ValidateType(type, typeReference);
            Utilities.ValidateAssembly(new ReflectionAssemblyNameWrapper(type.Assembly.GetName()),
                                       typeReference.ResolutionScope as AssemblyReference);
        }
Esempio n. 3
0
        public void NestedType()
        {
            var type          = typeof(DebuggableAttribute.DebuggingModes);
            var typeReference = TypeNameParser.ParseType(null, type.AssemblyQualifiedName);

            Utilities.ValidateType(type, typeReference);
            Utilities.ValidateAssembly(new ReflectionAssemblyNameWrapper(type.Assembly.GetName()),
                                       typeReference.GetElementType().DeclaringTypeDescriptor.ResolutionScope as AssemblyReference);
        }
        public void ParseWithDefaultNamespaceAndAssembly()
        {
            const string defaultAssembly  = "DefaultAssembly";
            const string defaultNamespace = "DefaultNamespace";

            AssemblyQualifiedTypeName tn = TypeNameParser.Parse("SomeType", defaultNamespace, defaultAssembly);

            Assert.AreEqual("DefaultNamespace.SomeType", tn.Type);
        }
Esempio n. 5
0
        /// <summary>
        /// Converts a partial class name into a fully one
        /// </summary>
        /// <param name="className"></param>
        /// <param name="mappings"></param>
        /// <returns>The class FullName (without the assembly)</returns>
        /// <remarks>
        /// The FullName is equivalent to the default entity-name
        /// </remarks>
        protected static string FullClassName(string className, Mappings mappings)
        {
            if (className == null)
            {
                return(null);
            }

            return(TypeNameParser.Parse(className, mappings.DefaultNamespace, mappings.DefaultAssembly).Type);
        }
        public void ParseWithDefaultNamespaceNoAssembly()
        {
            const string defaultNamespace = "DefaultNamespace";

            AssemblyQualifiedTypeName tn = TypeNameParser.Parse("SomeType", defaultNamespace, null);

            Assert.AreEqual("DefaultNamespace.SomeType", tn.Type);
            Assert.IsNull(tn.Assembly);
        }
Esempio n. 7
0
        private static Attribute ConvertToRule(XmlNhvmRuleConverterArgs rule)
        {
            NhvmRule ruleRule = (NhvmRule)rule.schemaRule;

            string attribute = ruleRule.attribute;
            AssemblyQualifiedTypeName fullClassName =
                TypeNameParser.Parse(attribute, rule.defaultNameSpace, rule.defaultAssembly);

            System.Type type = ReflectHelper.ClassForFullName(fullClassName.ToString());
#if NETFX
            log.Info("The type found for ruleRule = " + type.FullName);
#else
            Log.Info("The type found for ruleRule = {0}", type.FullName);
#endif
            Attribute thisattribute = (Attribute)Activator.CreateInstance(type);
#if NETFX
            log.Info("Attribute found = " + thisattribute);
#else
            Log.Info("Attribute found = {0}", thisattribute);
#endif

            var tr = thisattribute as ITagableRule;
            if (tr != null)
            {
                AssignTagsFromString(tr, ruleRule.tags);
            }

            if (ruleRule.param == null)
            {
                return(thisattribute);                                    //eager return
            }
            foreach (NhvmParam parameter in ruleRule.param)
            {
                PropertyInfo propInfo = type.GetProperty(parameter.name);
                if (propInfo != null)
                {
#if NETFX
                    log.Info("propInfo value = " + parameter.value);
#else
                    Log.Info("propInfo value = {0}", parameter.value);
#endif
                    object value = propInfo.PropertyType != typeof(string)
                                                                        ? Convert.ChangeType(parameter.value, propInfo.PropertyType)
                                                                        : parameter.value;
                    propInfo.SetValue(thisattribute, value, null);
                }
                else
                {
                    throw new InvalidPropertyNameException(
                              string.Format("The custom attribute '{0}' don't have the property '{1}'; Check for typo.", type.FullName, parameter.name), parameter.name,
                              type);
                }
            }

            return(thisattribute);
        }
Esempio n. 8
0
        public void ReadTypeInCorLibAssemblyWithoutScope()
        {
            const string ns   = "System";
            const string name = "Array";

            var expected = new TypeReference(_module.CorLibTypeFactory.CorLibScope, ns, name).ToTypeSignature();
            var actual   = TypeNameParser.Parse(_module, $"{ns}.{name}");

            Assert.Equal(expected, actual, _comparer);
        }
Esempio n. 9
0
        public void UpdateFrom(TypeDiscoveredMessage message)
        {
            var typeModel = message.TypeModel;
            var typeData  = new TypeData(
                typeModel.Id,
                TypeNameParser.ParseAssemblyQualifiedTypeName(typeModel.AssemblyQualifiedName),
                typeModel.IsDisposable);

            _typeData.Add(typeData);
        }
Esempio n. 10
0
        public void NestedClasses()
        {
            var input  = "Db4oPad.TestDBs.NestedClasses+ChildClass, Db4oPad.TestDBs";
            var result = TypeNameParser.ParseString(input);

            Assert.AreEqual("Db4oPad.TestDBs.NestedClasses+ChildClass", result.NameAndNamespace);
            Assert.AreEqual("Db4oPad.TestDBs", result.AssemblyName);
            Assert.AreEqual(input, result.FullName);
            Assert.AreEqual("ChildClass", result.Name);
        }
Esempio n. 11
0
        public void MultiNestedGeneric()
        {
            var input = "Gamlor.Db4oPad.Tests.TypeGeneration.Generic`2[[System.String, mscorlib], [System.Collections.Generic.List`1[[System.String, mscorlib]], mscorlib]], Gamlor.Db4oPad.Tests";


            var result = TypeNameParser.ParseString(input);

            Assert.AreEqual("Gamlor.Db4oPad.Tests.TypeGeneration.Generic`2", result.NameAndNamespace);
            Assert.AreEqual("Gamlor.Db4oPad.Tests", result.AssemblyName);
        }
Esempio n. 12
0
        /// <summary>
        /// Reads a single custom marshal descriptor from the provided input stream.
        /// </summary>
        /// <param name="parentModule">The module defining the descriptor.</param>
        /// <param name="reader">The input stream.</param>
        /// <returns>The descriptor.</returns>
        public new static CustomMarshalDescriptor FromReader(ModuleDefinition parentModule, ref BinaryStreamReader reader)
        {
            string guid            = reader.ReadSerString();
            string nativeTypeName  = reader.ReadSerString();
            string marshalTypeName = reader.ReadSerString();
            string cookie          = reader.ReadSerString();

            return(new CustomMarshalDescriptor(guid, nativeTypeName,
                                               marshalTypeName is null ? null : TypeNameParser.Parse(parentModule, marshalTypeName), cookie));
        }
Esempio n. 13
0
        public void ParseGenericNested()
        {
            var input = string.Format("Namespace.Map`2[{0}, [Namespace.List`1[{0}], {1}]], {1}", GenericArg, AsseblyName);

            var result = TypeNameParser.ParseString(input);

            Assert.AreEqual("Namespace.Map`2", result.NameAndNamespace);
            Assert.AreEqual(AsseblyName, result.AssemblyName);
            ValidateGenericArgs(result.GenericArguments.Take(1));
            ValidateGenericArgs(result.GenericArguments.Last().Value.GenericArguments);
        }
Esempio n. 14
0
        public void SimpleArrayType()
        {
            const string ns   = "MyNamespace";
            const string name = "MyType";

            var elementType = new TypeReference(_module, ns, name).ToTypeSignature();
            var expected    = new SzArrayTypeSignature(elementType);

            var actual = TypeNameParser.Parse(_module, $"{ns}.{name}[]");

            Assert.Equal(expected, actual, _comparer);
        }
Esempio n. 15
0
        public void ParsesSingleGenericClass()
        {
            var clas = TypeNameParser.Parse("Class<T>");

            Assert.AreEqual("Class", clas.Surname);
            Assert.AreEqual(1, clas.GenericArguments.Count);
            var t = clas.GenericArguments.Get(0);

            Assert.AreEqual("T", t.Surname);
            Assert.False(clas.ContainingType.HasValue);
            Assert.False(t.ContainingType.HasValue);
        }
        private void EvaluateType(SqlNode node, MetaType metaType)
        {
            var sessionFactory = SessionFactoryHelper.Factory;

            var className = sessionFactory.GetImportedClassName(node.OriginalText);

            var discriminatorValue = metaType.GetMetaValue(
                TypeNameParser.Parse(className).Type,
                sessionFactory.Dialect);

            node.Text = discriminatorValue;
        }
Esempio n. 17
0
        public void MultiGenericNested()
        {
            var input = string.Format("Namespace.MainClass`1+NestedClass`2[{0}, {0}, {0}], {1}", GenericArg, AsseblyName);

            var result = TypeNameParser.ParseString(input);

            Assert.AreEqual("Namespace.MainClass`1+NestedClass`2", result.NameAndNamespace);
            Assert.AreEqual(AsseblyName, result.AssemblyName);
            ValidateGenericArgs(result.GenericArguments.Take(1));
            ValidateGenericArgs(result.GenericArguments.Skip(1).Take(1));
            ValidateGenericArgs(result.GenericArguments.Last().Value.GenericArguments);
        }
Esempio n. 18
0
        public void MultidimensionalArray()
        {
            const string ns   = "MyNamespace";
            const string name = "MyType";

            var elementType = new TypeReference(_module, ns, name).ToTypeSignature();
            var expected    = new ArrayTypeSignature(elementType, 4);

            var actual = TypeNameParser.Parse(_module, $"{ns}.{name}[,,,]");

            Assert.Equal(expected, actual, _comparer);
        }
Esempio n. 19
0
        public void TestInvalidTypes()
        {
            Assert.Throws <ArgumentException>(() => TypeNameParser.Parse(null));
            Assert.Throws <ArgumentException>(() => TypeNameParser.Parse(""));

            Assert.Throws <IgniteException>(() => TypeNameParser.Parse("x["));
            Assert.Throws <IgniteException>(() => TypeNameParser.Parse("x[[]"));
            Assert.Throws <IgniteException>(() => TypeNameParser.Parse("x`["));
            Assert.Throws <IgniteException>(() => TypeNameParser.Parse("x`[ ]"));
            Assert.Throws <IgniteException>(() => TypeNameParser.Parse("x,"));
            Assert.Throws <IgniteException>(() => TypeNameParser.Parse("x`2[x"));
        }
Esempio n. 20
0
        public void NestedTypeNoNamespace(string name, string nestedType)
        {
            var expected = new TypeReference(
                new TypeReference(_module, null, name),
                null,
                nestedType)
                           .ToTypeSignature();

            var actual = TypeNameParser.Parse(_module, $"{name}+{nestedType}");

            Assert.Equal(expected, actual, _comparer);
        }
Esempio n. 21
0
        public void NH1822()
        {
            var typeName =
                @"OldMutual.SalesGear.Data.ReferenceType`2[ 
                [OldMutual.SalesGear.Reference.Core.Channel, OldMutual.SalesGear.Reference.Core], 
                [OldMutual.SalesGear.Reference.Core.Channels, OldMutual.SalesGear.Reference.Core] 
              ], OldMutual.SalesGear.Data";
            var expected = "OldMutual.SalesGear.Data.ReferenceType`2[[OldMutual.SalesGear.Reference.Core.Channel, OldMutual.SalesGear.Reference.Core],[OldMutual.SalesGear.Reference.Core.Channels, OldMutual.SalesGear.Reference.Core]], OldMutual.SalesGear.Data";
            var a        = TypeNameParser.Parse(typeName);

            Assert.That(a.ToString(), Is.EqualTo(expected));
        }
Esempio n. 22
0
        public void ReadEscapedTypeName()
        {
            const string ns          = "MyNamespace";
            const string escapedName = "MyType\\+WithPlus";
            const string name        = "MyType+WithPlus";

            var expected = new TypeReference(_module, ns, name).ToTypeSignature();

            var actual = TypeNameParser.Parse(_module, $"{ns}.{escapedName}");

            Assert.Equal(expected, actual, _comparer);
        }
Esempio n. 23
0
        private string GetTypeName(TypeNameParser name)
        {
            if (IsSimpleName)
            {
                return(name.GetName());
            }

            var fullName = NamespaceToLower && name.HasNamespace()
                ? name.GetNamespace().ToLower(CultureInfo.InvariantCulture) + name.GetName()
                : name.GetNameWithNamespace();

            return(NamespacePrefix + fullName);
        }
Esempio n. 24
0
        public void TypeWithAssemblyName()
        {
            const string ns          = "MyNamespace";
            const string name        = "MyType";
            var          assemblyRef = new AssemblyReference("MyAssembly", new Version(1, 2, 3, 4));
            var          expected    = new TypeReference(assemblyRef, ns, name).ToTypeSignature();


            var actual = TypeNameParser.Parse(_module,
                                              $"{ns}.{name}, {assemblyRef.FullName}");

            Assert.Equal(expected, actual, _comparer);
        }
Esempio n. 25
0
 public ClassEntry(string extends, string className, string entityName, string assembly, string @namespace)
 {
     fullExtends       = string.IsNullOrEmpty(extends) ? null : TypeNameParser.Parse(extends, @namespace, assembly);
     fullClassName     = string.IsNullOrEmpty(className) ? null : TypeNameParser.Parse(className, @namespace, assembly);
     this.entityName   = entityName;
     extendsEntityName = string.IsNullOrEmpty(extends) ? null : extends;
     unchecked
     {
         hashCode = (entityName != null ? entityName.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ (fullExtends != null ? fullExtends.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ (fullClassName != null ? fullClassName.GetHashCode() : 0);
     }
 }
Esempio n. 26
0
        public void ParsesClassInNamespace()
        {
            var clas = TypeNameParser.Parse("Ns1.Ns2.Class");

            Assert.AreEqual("Class", clas.Surname);
            var ns2 = clas.ContainingType.Value;

            Assert.AreEqual("Ns2", ns2.Surname);
            var ns1 = ns2.ContainingType.Value;

            Assert.AreEqual("Ns1", ns1.Surname);
            Assert.False(ns1.ContainingType.HasValue);
        }
Esempio n. 27
0
        public void SpacesInAssemblySpec()
        {
            const string ns          = "MyNamespace";
            const string name        = "MyType";
            const string assemblyRef = "Some Assembly";

            var scope    = new AssemblyReference(assemblyRef, new Version(1, 0, 0, 0));
            var expected = new TypeReference(_module, scope, ns, name).ToTypeSignature();

            var actual = TypeNameParser.Parse(_module, $"{ns}.{name}, {assemblyRef}, Version={scope.Version}");

            Assert.Equal(expected, actual, _comparer);
        }
Esempio n. 28
0
        public void StringArray()
        {
            var input = "System.String[], mscorlib";


            var result = TypeNameParser.ParseString(input);

            Assert.AreEqual("System.String[]", result.NameAndNamespace);
            Assert.AreEqual("mscorlib", result.AssemblyName);
            Assert.AreEqual("System.String[], mscorlib", result.FullName);
            Assert.AreEqual(1, result.OrderOfArray);
            Assert.AreEqual("System.String, mscorlib", result.ArrayOf.Value.FullName);
        }
Esempio n. 29
0
        public void GenericTypeSingleBrackets()
        {
            const string ns   = "MyNamespace";
            const string name = "MyType";

            var elementType  = new TypeReference(_module, ns, name);
            var argumentType = _module.CorLibTypeFactory.Object;

            var expected = new GenericInstanceTypeSignature(elementType, false, argumentType);

            var actual = TypeNameParser.Parse(_module, $"{ns}.{name}[{argumentType.Namespace}.{argumentType.Name}]");

            Assert.Equal(expected, actual, _comparer);
        }
Esempio n. 30
0
        public void ReadTypeInSameAssemblyWithoutScope()
        {
            const string ns   = "MyNamespace";
            const string name = "MyType";

            var definition = new TypeDefinition(ns, name, TypeAttributes.Public, _module.CorLibTypeFactory.Object.Type);

            _module.TopLevelTypes.Add(definition);

            var expected = definition.ToTypeSignature();
            var actual   = TypeNameParser.Parse(_module, $"{ns}.{name}");

            Assert.Equal(expected, actual, _comparer);
        }
Esempio n. 31
0
        public void TestCompilerGeneratedTypes([Values(
                                                    @"Foo.Bar+<Abc-Def<System-String\,System-Byte\[\]>-Convert>d__0",
                                                    @"Foo.Bar+<Foo-Bar<Abc-Def<System-Byte\[\]>\,Abc-Def<System-String>>-Convert>d__4`1",
                                                    @"Program\+IFoo`2\[\[System.Int32\, System.Private.CoreLib\, Version=4.0.0.0\, Culture=neutral\, PublicKeyToken=567\]\,\[System.String\, System.Private.CoreLib\, Version=4.0.0.0\, Culture=neutral\, PublicKeyToken=123\]\]"
                                                    )]
                                               string typeName)
        {
            var res = TypeNameParser.Parse(typeName);

            Assert.AreEqual(typeName, res.GetName());
            Assert.IsNull(res.GetAssemblyName());
            Assert.IsNull(res.GetArray());
            Assert.IsFalse(res.HasNamespace());
        }
Esempio n. 32
0
 /// <summary>
 /// Returns a reference to the type that the given alias stands for. For example, if alias is a type forwarder, return a reference to the forwarded type (in another assembly).
 /// </summary>
 internal INamedTypeReference/*?*/ GetReferenceToAliasedType(ExportedTypeAliasBase alias) {
   Assembly/*?*/ thisAssembly = this.Module as Assembly;
   if (thisAssembly == null) return null;
   uint exportedTypeRowId = alias.ExportedTypeRowId;
   if (exportedTypeRowId == 0) return null;
   ExportedTypeRow exportedTypeRow = this.PEFileReader.ExportedTypeTable[exportedTypeRowId];
   uint tokenType = exportedTypeRow.Implementation & TokenTypeIds.TokenTypeMask;
   uint rowId = exportedTypeRow.Implementation & TokenTypeIds.RIDMask;
   IName namespaceName = this.GetNameFromOffset(exportedTypeRow.TypeNamespace);
   IName mangledTypeName = this.GetNameFromOffset(exportedTypeRow.TypeName);
   IName unmangledTypeName = this.GetUnmangledNameFromOffset(exportedTypeRow.TypeName);
   switch (tokenType) {
     case TokenTypeIds.File: {
         FileReference/*?*/ fileRef = this.GetFileReferenceAt(rowId);
         if (fileRef == null) return null;
         var module = thisAssembly.FindMemberModuleNamed(fileRef.Name) as Module;
         if (module == null) return null;
         var foundType = module.PEFileToObjectModel.ResolveNamespaceTypeDefinition(namespaceName, mangledTypeName);
         if (foundType == null) return null;
         return foundType;
       }
     case TokenTypeIds.ExportedType: {
         ExportedTypeAliasBase/*?*/ parentExportedType = this.GetExportedTypeAtRowWorker(rowId);
         if (parentExportedType == null) return null;
         var parentModuleType = this.GetReferenceToAliasedType(parentExportedType);
         if (parentModuleType == null) return null;
         ITypeDefinition parentType = parentModuleType.ResolvedType;
         if (!(parentType is Dummy)) {
           foreach (ITypeDefinitionMember tdm in parentModuleType.ResolvedType.GetMembersNamed(unmangledTypeName, false)) {
             var modTypeRef = tdm as IMetadataReaderNamedTypeReference;
             if (modTypeRef != null)
               return modTypeRef;
           }
         } else {
           NamespaceTypeNameTypeReference/*?*/ nstr = parentModuleType as NamespaceTypeNameTypeReference;
           if (nstr != null) {
             var nestedTypeName = new NestedTypeName(this.NameTable, nstr.NamespaceTypeName, mangledTypeName);
             return nestedTypeName.GetAsNamedTypeReference(this, nstr.Module);
           }
           NestedTypeNameTypeReference/*?*/ netr = parentModuleType as NestedTypeNameTypeReference;
           if (netr != null) {
             var nestedTypeName = new NestedTypeName(this.NameTable, netr.NestedTypeName, mangledTypeName);
             return nestedTypeName.GetAsNamedTypeReference(this, netr.Module);
           }
         }
         return null;
       }
     case TokenTypeIds.AssemblyRef: {
         AssemblyReference/*?*/ assemRef = this.GetAssemblyReferenceAt(rowId);
         if (assemRef == null) return null;
         var internalAssembly = assemRef.ResolvedAssembly as Assembly;
         if (internalAssembly != null) {
           //Since we have already loaded the assembly that is supposed to hold this type, we may as well try and resolve it.
           PEFileToObjectModel assemblyPEFileToObjectModel = internalAssembly.PEFileToObjectModel;
           var type = assemblyPEFileToObjectModel.ResolveNamespaceTypeDefinition(namespaceName, mangledTypeName);
           if (type != null) return type;
           //The other assembly (internalAssembly) does not have a namespace type def for this reference.
           //Perhaps it has an alias that forwards to somewhere else... Not very likely happen in practice, I would hope.
           ExportedTypeAliasBase/*?*/ aliasType = assemblyPEFileToObjectModel.TryToResolveAsNamespaceTypeAlias(namespaceName, mangledTypeName);
           if (aliasType != null && aliasType != alias) return assemblyPEFileToObjectModel.GetReferenceToAliasedType(aliasType);
           //Although we can resolve the target assembly, we can neither resolve the aliased type, nor find a secondary alias.
           //This is mighty strange. Probably the host has fluffed assembly resolution and internalAssembly isn't really the
           //assembly we are looking for. We now have to give up and simply return an unresolved reference.
         }
         string fullTypeName = mangledTypeName.Value;
         if (namespaceName.Value.Length > 0) fullTypeName = namespaceName.Value+"."+fullTypeName;
         var parser = new TypeNameParser(this.NameTable, fullTypeName);
         return parser.ParseTypeName().GetAsTypeReference(this, assemRef) as INamedTypeReference;
       }
   }
   return null;
 }
Esempio n. 33
0
 internal ITypeReference/*?*/ GetSerializedTypeNameAsTypeReference(
   string serializedTypeName
 ) {
   TypeNameParser typeNameParser = new TypeNameParser(this.NameTable, serializedTypeName);
   TypeName/*?*/ typeName = typeNameParser.ParseTypeName();
   if (typeName == null) //  MDError...
     return null;
   return this.GetSerializedTypeNameAsTypeReference(typeName);
 }
Esempio n. 34
0
 /// <summary>
 /// Parses the specified typename string as obtained by
 /// <c>System.Object.GetType().FullName</c> or 
 /// <c>System.Object.GetType().AssemblyQualifiedName</c>.
 /// </summary>
 /// <param name="s">The typename string.</param>
 /// <returns>A <see cref="TypeName"/> representing the type name.</returns>
 public static TypeName Parse(string s) {
   TypeNameParser p = new TypeNameParser(s);
   try {
     return p.TransformTypeSpec();
   }
   catch (ParseError x) {
     if (p.Position > 0)
       throw new ParseError(String.Format(
         "Could not parse typename: {0}\n\"{1}====>{2}<===={3}",
         x.Message,
         s.Substring(0, p.Position),
         s[p.Position],
         s.Substring(p.Position, s.Length - p.Position)));
     else
       throw new ParseError(String.Format(
         "Could not parse typenname \"{0}\" at end of input: {1}",
         s,
         x.Message));
   }
 }
Esempio n. 35
0
        private void CreateInstance()
        {
            Contract.Requires(currentTask != null);
            Contract.Requires(currentTask.EntryPoint != null);
            Contract.Requires(!string.IsNullOrEmpty(currentTask.EntryPoint.QualifiedClassName));

            using (Perfomance.Trace("GeneralEngine::CreateInstance()").BindToConsole())
            {
                var type = Type.GetType(currentTask.EntryPoint.QualifiedClassName);
                if (type == null)
                {
                    var typeName = new TypeNameParser().Parse(currentTask.EntryPoint.QualifiedClassName);
                    type = currentLoadingAssembly.GetType(typeName.Name, false);
                    if (type == null)
                        throw new UnableToLoadTaskException(string.Format(
                            "Unable to load task: entry point class {0} doesn't exists.",
                            currentTask.EntryPoint.QualifiedClassName));
                }
                try
                {
                    var instance = Activator.CreateInstance(type);
                    taskInstance = instance as ITask;
                    if (taskInstance == null)
                        throw new UnableToLoadTaskException(string.Format(
                            "Unable to load task: entry point class {0} doesn't implement interface {1}.",
                            currentTask.EntryPoint.QualifiedClassName,
                            typeof(ITask).FullName));
                }
                catch (MissingMethodException inner)
                {
                    throw new UnableToLoadTaskException(string.Format(
                        "Unable to load task: entry point class {0} doesn't have a parameterless contructor.",
                        currentTask.EntryPoint.QualifiedClassName),
                                                        inner);
                }
                catch (TargetInvocationException inner)
                {
                    throw new UnableToLoadTaskException(string.Format(
                        "Unable to load task: entry point class {0} constructor has thrown an exception.",
                        currentTask.EntryPoint.QualifiedClassName),
                                                        inner);
                }
            }
        }
Esempio n. 36
0
 /// <summary>
 /// Finds the given aliased type in the exported type table.
 /// </summary>
 /// <param name="aliasAliasBase"></param>
 /// <returns></returns>
 internal IModuleTypeReference/*?*/ FindExportedType(
   ExportedTypeAliasBase aliasAliasBase
 ) {
   Assembly/*?*/ thisAssembly = this.Module as Assembly;
   if (thisAssembly == null)
     return null;
   uint exportedTypeRowId = aliasAliasBase.ExportedTypeRowId;
   if (exportedTypeRowId == 0)
     return null;
   ExportedTypeRow exportedTypeRow = this.PEFileReader.ExportedTypeTable[exportedTypeRowId];
   uint tokenType = exportedTypeRow.Implementation & TokenTypeIds.TokenTypeMask;
   uint rowId = exportedTypeRow.Implementation & TokenTypeIds.RIDMask;
   IName namespaceName = this.GetNameFromOffset(exportedTypeRow.TypeNamespace);
   IName typeName = this.GetNameFromOffset(exportedTypeRow.TypeName);
   switch (tokenType) {
     case TokenTypeIds.File: {
         FileReference/*?*/ fileRef = this.GetFileReferenceAt(rowId);
         if (fileRef == null) {
           return null;
         }
         Module/*?*/ module =thisAssembly.FindMemberModuleNamed(fileRef.Name);
         if (module == null) {
           return null;
         }
         TypeBase/*?*/ foundType = module.PEFileToObjectModel.ResolveNamespaceTypeDefinition(namespaceName, typeName);
         if (foundType == null) {
           return null;
         }
         return foundType;
       }
     case TokenTypeIds.ExportedType: {
         ExportedTypeAliasBase/*?*/ parentExportedType = this.GetExportedTypeAtRowWorker(rowId);
         if (parentExportedType == null) {
           return null;
         }
         IModuleTypeReference/*?*/ parentModuleType = this.FindExportedType(parentExportedType);
         if (parentModuleType == null) {
           return null;
         }
         ITypeDefinition parentType = parentModuleType.ResolvedType;
         if (parentType != Dummy.Type) {
           foreach (ITypeDefinitionMember tdm in parentModuleType.ResolvedType.GetMembersNamed(typeName, false)) {
             IModuleTypeReference/*?*/ modTypeRef = tdm as IModuleTypeReference;
             if (modTypeRef != null)
               return modTypeRef;
           }
         } else {
           NamespaceTypeNameTypeReference/*?*/ nstr = parentModuleType as NamespaceTypeNameTypeReference;
           if (nstr != null) {
             var nestedTypeName = new NestedTypeName(this.NameTable, nstr.NamespaceTypeName, typeName);
             return nestedTypeName.GetAsTypeReference(this, nstr.Module);
           }
           NestedTypeNameTypeReference/*?*/ netr = parentModuleType as NestedTypeNameTypeReference;
           if (netr != null) {
             var nestedTypeName = new NestedTypeName(this.NameTable, netr.NestedTypeName, typeName);
             return nestedTypeName.GetAsTypeReference(this, netr.Module);
           }
         }
         return null;
       }
     case TokenTypeIds.AssemblyRef: {
         AssemblyReference/*?*/ assemRef = this.GetAssemblyReferenceAt(rowId);
         if (assemRef == null) {
           return null;
         }
         var internalAssembly = assemRef.ResolvedAssembly as Assembly;
         if (internalAssembly != null) {
           PEFileToObjectModel assemblyPEFileToObjectModel = internalAssembly.PEFileToObjectModel;
           TypeBase/*?*/ type = assemblyPEFileToObjectModel.ResolveNamespaceTypeDefinition(namespaceName, typeName);
           if (type != null)
             return type;
           ExportedTypeAliasBase/*?*/ aliasType = assemblyPEFileToObjectModel.ResolveExportedNamespaceType(namespaceName, typeName);
           if (aliasType != null && aliasType != aliasAliasBase) {
             return assemblyPEFileToObjectModel.FindExportedType(aliasType);
           }
         } else {
           string fullTypeName = typeName.Value;
           if (namespaceName.Value.Length > 0)
             fullTypeName = namespaceName.Value+"."+typeName.Value;
           var parser = new TypeNameParser(this.NameTable, fullTypeName);
           return parser.ParseTypeName().GetAsTypeReference(this, assemRef);
         }
       }
       break;
   }
   return null;
 }
Esempio n. 37
0
 private bool ParseTypeArgumentsOptional(ref int arity)
 {
     bool flag2;
     this.SkipWhites();
     if (this.IsEOL)
     {
         return true;
     }
     if (!this.CurrentIs('['))
     {
         return true;
     }
     if ((this.NextWillBe(']', true) || this.NextWillBe(',', true)) || this.NextWillBe('*', true))
     {
         return true;
     }
     if (!this.Next(true))
     {
         return false;
     }
     this._info.TypeArguments.Capacity = arity;
 Label_0083:
     flag2 = false;
     if (this.CurrentIs('['))
     {
         flag2 = true;
         if (!this.Next(true))
         {
             return false;
         }
     }
     TypeNameParseInfo info = new TypeNameParseInfo();
     TypeNameParser parser = new TypeNameParser(this._data, this._p, this._end, info, true);
     if (!parser.Parse(flag2))
     {
         return false;
     }
     this._p = parser._p;
     this._info.TypeArguments.Add(info);
     this.SkipWhites();
     if (this.IsEOL)
     {
         return false;
     }
     if (flag2)
     {
         if (!this.CurrentIs(']'))
         {
             return false;
         }
         if (!this.Next(true))
         {
             return false;
         }
     }
     if (!this.CurrentIs(']'))
     {
         if (!this.CurrentIs(','))
         {
             return false;
         }
         if (!this.Next(true))
         {
             return false;
         }
         goto Label_0083;
     }
     if (this._info.TypeArguments.Count != arity)
     {
         return false;
     }
     this.Next(true);
     return true;
 }
Esempio n. 38
0
 public static TypeNameParseInfo Parse(string name)
 {
     TypeNameParseInfo info = new TypeNameParseInfo();
     char[] data = name.ToCharArray();
     TypeNameParser parser = new TypeNameParser(data, 0, data.Length, info, false);
     return (parser.Parse(true) ? info : null);
 }
        private ITypeElement HighlightUndefinedType(IXmlTag tag, string attributeName) {
            IXmlAttribute attribute = tag.GetAttribute(attributeName);
            if ((attribute == null) || (attribute.XmlName != attributeName) || (attribute.UnquotedValue == null)) {
                return null;
            }

            string fullQualifiedTypeName = attribute.UnquotedValue;
            Logger.LogMessage("Type is {0}", fullQualifiedTypeName);
            Parser parser = new Parser();
            IParserError error;
            parser.Parse(fullQualifiedTypeName, out error);
            if (error != ParserError.None) {
                AddHighlighting(attribute, new TypeHighlighting(string.Format("Error in type: {0}", error.Message)));
            }
            
            ITypeElement typeElement = PsiUtils.GetTypeElement(tag, m_Process.Solution, fullQualifiedTypeName);
            if ((typeElement == null) || (typeElement.Module == null)) {
                AddHighlighting(attribute, new TypeHighlighting(string.Format("Type '{0}' could not be resolved", fullQualifiedTypeName)));
            }
            else {
                // TODO: put TypeNameParser into Parser and refactor this
                TypeNameParser typeNameParser = new TypeNameParser(fullQualifiedTypeName, m_Assembly, m_Namespace);
                string assemblyName = typeNameParser.AssemblyName;
                if (typeElement.Module.Name != "mscorlib") {
                    BuildSettingsManager buildSettingsManager = BuildSettingsManager.GetInstance(typeElement.GetProjectFiles()[0].GetProject());
                    if (buildSettingsManager != null) {
                        IAssemblyFile outputAssemblyFile = buildSettingsManager.GetOutputAssemblyFile();
                        if ((outputAssemblyFile != null) && (outputAssemblyFile.Name != assemblyName)) {
                            AddHighlighting(attribute, new TypeHighlighting(string.Format("Assembly name '{0}' should be '{1}'", assemblyName, outputAssemblyFile.Name)));
                        }
                    }
                }
            }
            return typeElement;
        }