当前位置: 首页>>代码示例>>C#>>正文


C# ICompilation.FindType方法代码示例

本文整理汇总了C#中ICompilation.FindType方法的典型用法代码示例。如果您正苦于以下问题:C# ICompilation.FindType方法的具体用法?C# ICompilation.FindType怎么用?C# ICompilation.FindType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ICompilation的用法示例。


在下文中一共展示了ICompilation.FindType方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ResolveNamespaces

		IEnumerable<INamespace> ResolveNamespaces(ICompilation compilation)
		{
			IType xmlnsDefinition = compilation.FindType(typeof(System.Windows.Markup.XmlnsDefinitionAttribute));
			if (XmlNamespace.StartsWith("clr-namespace:", StringComparison.Ordinal)) {
				string name = XmlNamespace.Substring("clr-namespace:".Length);
				IAssembly asm = compilation.MainAssembly;
				int asmIndex = name.IndexOf(";assembly=", StringComparison.Ordinal);
				if (asmIndex >= 0) {
					string asmName = name.Substring(asmIndex + ";assembly=".Length);
					asm = compilation.ReferencedAssemblies.FirstOrDefault(a => a.AssemblyName == asmName) ?? compilation.MainAssembly;
					name = name.Substring(0, asmIndex);
				}
				string[] parts = name.Split('.');
				var @namespace = FindNamespace(asm, parts);
				if (@namespace != null) yield return @namespace;
			} else {
				foreach (IAssembly asm in compilation.Assemblies) {
					foreach (IAttribute attr in asm.AssemblyAttributes) {
						if (xmlnsDefinition.Equals(attr.AttributeType) && attr.PositionalArguments.Count == 2) {
							string xmlns = attr.PositionalArguments[0].ConstantValue as string;
							if (xmlns != XmlNamespace) continue;
							string ns = attr.PositionalArguments[1].ConstantValue as string;
							if (ns == null) continue;
							var @namespace = FindNamespace(asm, ns.Split('.'));
							if (@namespace != null) yield return @namespace;
						}
					}
				}
			}
		}
开发者ID:Paccc,项目名称:SharpDevelop,代码行数:30,代码来源:XamlContext.cs

示例2: Create

		/// <summary>
		/// Creates a task type.
		/// </summary>
		public static IType Create(ICompilation compilation, IType elementType)
		{
			if (compilation == null)
				throw new ArgumentNullException("compilation");
			if (elementType == null)
				throw new ArgumentNullException("elementType");
			
			if (elementType.Kind == TypeKind.Void)
				return compilation.FindType(KnownTypeCode.Task);
			IType taskType = compilation.FindType(KnownTypeCode.TaskOfT);
			ITypeDefinition taskTypeDef = taskType.GetDefinition();
			if (taskTypeDef != null)
				return new ParameterizedType(taskTypeDef, new [] { elementType });
			else
				return taskType;
		}
开发者ID:kristjan84,项目名称:SharpDevelop,代码行数:19,代码来源:TaskType.cs

示例3: CreateSuppressAttribute

		static IAttribute CreateSuppressAttribute(ICompilation compilation, FxCopTaskTag tag)
		{
			// [SuppressMessage("Microsoft.Performance", "CA1801:ReviewUnusedParameters", MessageId:="fileIdentifier"]
			IType attributeType = compilation.FindType(new FullTypeName(FullAttributeName));
			IType stringType = compilation.FindType(KnownTypeCode.String);
			
			KeyValuePair<IMember, ResolveResult>[] namedArgs = null;
			if (tag.MessageID != null) {
				IMember messageId = attributeType.GetProperties(p => p.Name == "MessageId").FirstOrDefault();
				namedArgs = new[] { new KeyValuePair<IMember, ResolveResult>(messageId, new ConstantResolveResult(stringType, tag.MessageID)) };
			}
			
			return new DefaultAttribute(
				attributeType, new[] {
					new ConstantResolveResult(stringType, tag.Category),
					new ConstantResolveResult(stringType, tag.CheckID)
				}, namedArgs);
		}
开发者ID:Paccc,项目名称:SharpDevelop,代码行数:18,代码来源:SuppressMessageCommand.cs

示例4: UnpackTask

		/// <summary>
		/// Gets the T in Task&lt;T&gt;.
		/// Returns void for non-generic Task.
		/// Any other type is returned unmodified.
		/// </summary>
		public static IType UnpackTask(ICompilation compilation, IType type)
		{
			if (!IsTask(type))
				return type;
			if (type.TypeParameterCount == 0)
				return compilation.FindType(KnownTypeCode.Void);
			else
				return type.TypeArguments[0];
		}
开发者ID:kristjan84,项目名称:SharpDevelop,代码行数:14,代码来源:TaskType.cs

示例5: GetDesignedClass

		protected IType GetDesignedClass(ICompilation compilation)
		{
			var xamlContext = viewContent.DesignContext as Designer.Xaml.XamlDesignContext;
			if (xamlContext != null) {
				string className = xamlContext.ClassName;
				if (!string.IsNullOrEmpty(className)) {
					return compilation.FindType(new FullTypeName(className));
				}
			}
			return null;
		}
开发者ID:Paccc,项目名称:SharpDevelop,代码行数:11,代码来源:AbstractEventHandlerService.cs

示例6: Create

		/// <summary>
		/// Creates a nullable type.
		/// </summary>
		public static IType Create(ICompilation compilation, IType elementType)
		{
			if (compilation == null)
				throw new ArgumentNullException("compilation");
			if (elementType == null)
				throw new ArgumentNullException("elementType");
			
			IType nullableType = compilation.FindType(KnownTypeCode.NullableOfT);
			ITypeDefinition nullableTypeDef = nullableType.GetDefinition();
			if (nullableTypeDef != null)
				return new ParameterizedType(nullableTypeDef, new [] { elementType });
			else
				return nullableType;
		}
开发者ID:0xb1dd1e,项目名称:NRefactory,代码行数:17,代码来源:NullableType.cs

示例7: PreferAttributeTypeWithSuffix

		internal static bool PreferAttributeTypeWithSuffix(IType t1, IType t2, ICompilation compilation)
		{
			if (t2.Kind == TypeKind.Unknown) return false;
			if (t1.Kind == TypeKind.Unknown) return true;
			
			var attrTypeDef = compilation.FindType(KnownTypeCode.Attribute).GetDefinition();
			if (attrTypeDef != null) {
				bool t1IsAttribute = (t1.GetDefinition() != null && t1.GetDefinition().IsDerivedFrom(attrTypeDef));
				bool t2IsAttribute = (t2.GetDefinition() != null && t2.GetDefinition().IsDerivedFrom(attrTypeDef));
				if (t2IsAttribute && !t1IsAttribute)
					return true;
				// If both types exist and are attributes, C# considers that to be an ambiguity, but we are less strict.
			}
			return false;
		}
开发者ID:sphynx79,项目名称:dotfiles,代码行数:15,代码来源:AttributeTypeReference.cs

示例8: SetUp

		public void SetUp()
		{
			pc = new CSharpProjectContent();
			pc = pc.SetAssemblyName("MyAssembly");
			parsedFile = new CSharpParser().Parse(new StringReader(program), "program.cs").ToTypeSystem();
			pc = pc.UpdateProjectContent(null, parsedFile);
			pc = pc.AddAssemblyReferences(new [] { CecilLoaderTests.Mscorlib });
			
			compilation = pc.CreateCompilation();
			
			baseClass = compilation.RootNamespace.GetTypeDefinition("Base", 1);
			nestedClass = baseClass.NestedTypes.Single();
			derivedClass = compilation.RootNamespace.GetTypeDefinition("Derived", 2);
			systemClass = compilation.FindType("NS.System, MyAssembly").GetDefinition();
		}
开发者ID:N3X15,项目名称:ILSpy,代码行数:15,代码来源:TypeSystemAstBuilderTests.cs

示例9: StructImplementingIEquatable

		public void StructImplementingIEquatable()
		{
			// struct S : IEquatable<S> {}
			// don't use a Cecil-loaded struct for this test; we're testing the implicit addition of System.ValueType
			var s = new DefaultUnresolvedTypeDefinition(string.Empty, "S");
			s.Kind = TypeKind.Struct;
			s.BaseTypes.Add(new ParameterizedTypeReference(typeof(IEquatable<>).ToTypeReference(), new[] { s }));
			compilation = TypeSystemHelper.CreateCompilation(s);
			ITypeDefinition resolvedS = Resolve(s);
			IType[] expected = {
				resolvedS,
				s.BaseTypes[0].Resolve(new SimpleTypeResolveContext(resolvedS)),
				compilation.FindType(typeof(object)),
				compilation.FindType(typeof(ValueType))
			};
			Assert.AreEqual(expected,
			                resolvedS.GetAllBaseTypes().OrderBy(t => t.ReflectionName).ToArray());
		}
开发者ID:0xb1dd1e,项目名称:NRefactory,代码行数:18,代码来源:GetAllBaseTypesTest.cs

示例10: ClassDerivingFromTwoInstanciationsOfIEnumerable

		public void ClassDerivingFromTwoInstanciationsOfIEnumerable()
		{
			// class C : IEnumerable<int>, IEnumerable<uint> {}
			var c = new DefaultUnresolvedTypeDefinition(string.Empty, "C");
			c.BaseTypes.Add(typeof(IEnumerable<int>).ToTypeReference());
			c.BaseTypes.Add(typeof(IEnumerable<uint>).ToTypeReference());
			compilation = TypeSystemHelper.CreateCompilation(c);
			ITypeDefinition resolvedC = Resolve(c);
			IType[] expected = {
				resolvedC,
				compilation.FindType(typeof(IEnumerable<int>)),
				compilation.FindType(typeof(IEnumerable<uint>)),
				compilation.FindType(typeof(IEnumerable)),
				compilation.FindType(typeof(object))
			};
			Assert.AreEqual(expected,
			                resolvedC.GetAllBaseTypes().OrderBy(t => t.ReflectionName).ToArray());
		}
开发者ID:0xb1dd1e,项目名称:NRefactory,代码行数:18,代码来源:GetAllBaseTypesTest.cs

示例11: Rewrite

        public IList<JsStatement> Rewrite(IEnumerable<JsType> types, ICompilation compilation)
        {
            var netSystemType = compilation.FindType(KnownTypeCode.Type).GetDefinition();
            var systemType = new JsTypeReferenceExpression(netSystemType.ParentAssembly, _metadataImporter.GetTypeSemantics(netSystemType).Name);

            var result = new List<JsStatement>();

            var orderedTypes = types.OrderBy(t => t.Name).ToList();
            string currentNs = "";
            foreach (var t in orderedTypes) {
                try {
                    var globalMethodsPrefix = _metadataImporter.GetGlobalMethodsPrefix(t.CSharpTypeDefinition);

                    string ns = GetNamespace(t.Name);
                    if (ns != currentNs && globalMethodsPrefix == null) {
                        result.Add(new JsExpressionStatement(JsExpression.Invocation(JsExpression.MemberAccess(systemType, RegisterNamespace), JsExpression.String(ns))));
                        currentNs = ns;
                    }
                    result.Add(new JsComment("//////////////////////////////////////////////////////////////////////////////" + Environment.NewLine + " " + t.Name));

                    var typeRef = new JsTypeReferenceExpression(compilation.MainAssembly, t.Name);
                    if (t is JsClass) {
                        var c = (JsClass)t;
                        if (globalMethodsPrefix != null) {
                            if (globalMethodsPrefix == "") {
                                result.AddRange(c.StaticMethods.Select(m => new JsExpressionStatement(JsExpression.Binary(ExpressionNodeType.Assign, JsExpression.MemberAccess(JsExpression.Identifier("window"), m.Name), m.Definition))));
                            }
                            else {
                                result.AddRange(c.StaticMethods.Select(m => new JsExpressionStatement(JsExpression.Assign(MakeNestedMemberAccess(globalMethodsPrefix + "." + m.Name), m.Definition))));
                            }
                        }
                        else if (_metadataImporter.IsResources(t.CSharpTypeDefinition)) {
                            result.Add(GenerateResourcesClass(c));
                        }
                        else {
                            var unnamedCtor = c.UnnamedConstructor ?? JsExpression.FunctionDefinition(new string[0], JsBlockStatement.EmptyStatement);

                            if (c.TypeArgumentNames.Count == 0) {
                                result.Add(new JsExpressionStatement(JsExpression.Assign(typeRef, unnamedCtor)));
                                AddClassMembers(c, typeRef, compilation, result);
                            }
                            else {
                                var stmts = new List<JsStatement> { new JsVariableDeclarationStatement(InstantiatedGenericTypeVariableName, unnamedCtor) };
                                AddClassMembers(c, JsExpression.Identifier(InstantiatedGenericTypeVariableName), compilation, stmts);
                                stmts.AddRange(c.StaticInitStatements);
                                stmts.Add(new JsReturnStatement(JsExpression.Identifier(InstantiatedGenericTypeVariableName)));
                                result.Add(new JsExpressionStatement(JsExpression.Assign(typeRef, JsExpression.FunctionDefinition(c.TypeArgumentNames, new JsBlockStatement(stmts)))));
                                result.Add(new JsExpressionStatement(JsExpression.Invocation(JsExpression.MemberAccess(typeRef, c.ClassType == JsClass.ClassTypeEnum.Interface ? RegisterGenericInterface : RegisterGenericClass), JsExpression.String(c.Name), JsExpression.Number(c.TypeArgumentNames.Count))));
                            }
                        }
                    }
                    else if (t is JsEnum) {
                        var e = (JsEnum)t;
                        bool flags = GetAttributePositionalArgs(t.CSharpTypeDefinition, FlagsAttribute, "System") != null;
                        result.Add(new JsExpressionStatement(JsExpression.Assign(typeRef, JsExpression.FunctionDefinition(new string[0], JsBlockStatement.EmptyStatement))));
                        result.Add(new JsExpressionStatement(JsExpression.Assign(JsExpression.MemberAccess(typeRef, Prototype), JsExpression.ObjectLiteral(e.Values.Select(v => new JsObjectLiteralProperty(v.Name, (_metadataImporter.IsNamedValues(t.CSharpTypeDefinition) ? JsExpression.String(v.Name) : JsExpression.Number(v.Value))))))));
                        result.Add(new JsExpressionStatement(JsExpression.Invocation(JsExpression.MemberAccess(typeRef, RegisterEnum), JsExpression.String(t.Name), JsExpression.Boolean(flags))));
                    }
                }
                catch (Exception ex) {
                    _errorReporter.Region = t.CSharpTypeDefinition.Region;
                    _errorReporter.InternalError(ex, "Error formatting type " + t.CSharpTypeDefinition.FullName);
                }
            }

            var typesToRegister = orderedTypes.OfType<JsClass>()
                                        .Where(c =>    c.TypeArgumentNames.Count == 0
                                                    && _metadataImporter.GetGlobalMethodsPrefix(c.CSharpTypeDefinition) == null
                                                    && !_metadataImporter.IsResources(c.CSharpTypeDefinition))
                                        .ToList();

            result.AddRange(TopologicalSortTypesByInheritance(typesToRegister)
                            .Select(c => {
                                             try {
                                                 var typeRef = new JsTypeReferenceExpression(compilation.MainAssembly, c.Name);
                                                 if (c.ClassType == JsClass.ClassTypeEnum.Interface) {
                                                     return JsExpression.Invocation(JsExpression.MemberAccess(typeRef, RegisterInterface), JsExpression.String(c.Name), JsExpression.ArrayLiteral(c.ImplementedInterfaces));
                                                 }
                                                 else {
                                                     return CreateRegisterClassCall(JsExpression.String(c.Name), c.BaseClass, c.ImplementedInterfaces, typeRef);
                                                 }
                                             }
                                             catch (Exception ex) {
                                                 _errorReporter.Region = c.CSharpTypeDefinition.Region;
                                                 _errorReporter.InternalError(ex, "Error formatting type " + c.CSharpTypeDefinition.FullName);
                                                 return JsExpression.Number(0);
                                             }
                                         })
                            .Select(expr => new JsExpressionStatement(expr)));
            result.AddRange(orderedTypes.OfType<JsClass>().Where(c => c.TypeArgumentNames.Count == 0 && !_metadataImporter.IsResources(c.CSharpTypeDefinition)).SelectMany(t => t.StaticInitStatements));

            return result;
        }
开发者ID:tml,项目名称:SaltarelleCompiler,代码行数:93,代码来源:ScriptSharpOOPEmulator.cs

示例12: CreateListForXmlnsCompletion

		public IEnumerable<ICompletionItem> CreateListForXmlnsCompletion(ICompilation compilation)
		{
			this.compilation = compilation;
			
			List<XmlnsCompletionItem> list = new List<XmlnsCompletionItem>();
			IType xmlnsAttrType = compilation.FindType(typeof(System.Windows.Markup.XmlnsDefinitionAttribute));
			foreach (IAssembly asm in compilation.ReferencedAssemblies) {
				foreach (IAttribute att in asm.AssemblyAttributes) {
					if (att.PositionalArguments.Count == 2 && att.AttributeType.Equals(xmlnsAttrType)) {
						ResolveResult arg1 = att.PositionalArguments[0];
						if (arg1.IsCompileTimeConstant && arg1.ConstantValue is string) {
							list.Add(new XmlnsCompletionItem((string)arg1.ConstantValue, true));
						}
					}
				}
				
				foreach (INamespace @namespace in TreeTraversal.PreOrder(asm.RootNamespace, ns => ns.ChildNamespaces)) {
					list.Add(new XmlnsCompletionItem(@namespace.FullName, asm.AssemblyName));
				}
			}
			
			foreach (INamespace @namespace in TreeTraversal.PreOrder(compilation.MainAssembly.RootNamespace, ns => ns.ChildNamespaces)) {
				list.Add(new XmlnsCompletionItem(@namespace.FullName, false));
			}
			
			list.Add(new XmlnsCompletionItem(XamlConst.MarkupCompatibilityNamespace, true));
			
			return list
				.Distinct(new XmlnsEqualityComparer())
				.OrderBy(item => item, new XmlnsComparer());
		}
开发者ID:hefnerliu,项目名称:SharpDevelop,代码行数:31,代码来源:CompletionDataGenerator.cs

示例13: FindEventDeclaration

		IEvent FindEventDeclaration(ICompilation compilation, Type declaringType, string name)
		{
			return compilation.FindType(declaringType).GetEvents(ue => ue.Name == name).FirstOrDefault();
		}
开发者ID:Paccc,项目名称:SharpDevelop,代码行数:4,代码来源:AbstractEventHandlerService.cs


注:本文中的ICompilation.FindType方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。