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


C# IAssemblySymbol.GetAttributes方法代码示例

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


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

示例1: GetAssemblyAttributes

 public static IEnumerable<string> GetAssemblyAttributes(IAssemblySymbol assemblySymbol)
 {
     var attributes = assemblySymbol.GetAttributes();
     foreach (var attribute in attributes)
     {
         yield return attribute.ToString();
     }
 }
开发者ID:rgmills,项目名称:SourceBrowser,代码行数:8,代码来源:MetadataReading.cs

示例2: CreateInternalsVisibleToMap

        /// <summary>
        /// This method creates an initial cheap InternalsVisibleTo map from the given <paramref name="assembly"/> to the assembly names that have friend access to this assembly.
        /// This map is a superset of the actual InternalsVisibleTo map and is used for performance reasons only.
        /// While identifying depend projects that can reference a given symbol (see method <see cref="M:AddNonSubmissionDependentProjectsAsync"/>), we need to know a symbol's
        /// accessibility from referencing projects. This requires us to create a compilation for the referencing project just to check accessibility and can be performance intensive.
        /// Instead, we crack the assembly attributes just for the symbol's containing assembly here to enable cheap checks for friend assemblies in <see cref="M:AddNonSubmissionDependentProjectsAsync"/>.
        /// </summary>
        private static Lazy<HashSet<string>> CreateInternalsVisibleToMap(IAssemblySymbol assembly)
        {
            var internalsVisibleToMap = new Lazy<HashSet<string>>(() =>
            {
                var map = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
                foreach (var attr in assembly.GetAttributes().Where(IsInternalsVisibleToAttribute))
                {
                    var typeNameConstant = attr.ConstructorArguments.FirstOrDefault();
                    if (typeNameConstant.Type == null || typeNameConstant.Type.SpecialType != SpecialType.System_String)
                    {
                        continue;
                    }

                    var value = (string)typeNameConstant.Value;
                    var commaIndex = value.IndexOf(",");
                    var assemblyName = commaIndex >= 0 ? value.Substring(0, commaIndex).Trim() : value;

                    map.Add(assemblyName);
                }

                return map;
            }, isThreadSafe: true);
            return internalsVisibleToMap;
        }
开发者ID:riversky,项目名称:roslyn,代码行数:31,代码来源:DependentProjectsFinder.cs

示例3: TranslateMetadata

    private Assembly TranslateMetadata(IAssemblySymbol assemblySymbol) {
      Contract.Requires(assemblySymbol != null);
      Contract.Ensures(Contract.Result<Assembly>() != null);

      IAssemblyReference cciAssemblyReference = null;
      Assembly cciAssembly = null;
      if (assemblySymbolCache.TryGetValue(assemblySymbol, out cciAssemblyReference)) {
        cciAssembly = cciAssemblyReference as Assembly;
        System.Diagnostics.Debug.Assert(cciAssembly != null);
        return cciAssembly;
      }

      var coreAssembly = host.LoadAssembly(host.CoreAssemblySymbolicIdentity);
      var name = assemblySymbol.Identity.Name;
      var iname = nameTable.GetNameFor(name);
      cciAssembly = new Assembly() {
        Attributes = this.TranslateMetadata(assemblySymbol.GetAttributes()),
        Name = iname,
        Locations = Helper.WrapLocations(assemblySymbol.Locations),
        ModuleName = iname,
        Kind = ModuleKind.DynamicallyLinkedLibrary,
        RequiresStartupStub = this.host.PointerSize == 4,
        TargetRuntimeVersion = coreAssembly.TargetRuntimeVersion,
        Version = assemblySymbol.Identity.Version,
      };
      cciAssembly.AssemblyReferences.Add(coreAssembly);
      this.assemblySymbolCache.Add(assemblySymbol, cciAssembly);
      this.module = cciAssembly;

      var rootUnitNamespace = new RootUnitNamespace();
      cciAssembly.UnitNamespaceRoot = rootUnitNamespace;
      rootUnitNamespace.Unit = cciAssembly;
      this.namespaceSymbolCache.Add(assemblySymbol.GlobalNamespace, rootUnitNamespace);

      var moduleClass = new NamespaceTypeDefinition() {
        ContainingUnitNamespace = rootUnitNamespace,
        InternFactory = host.InternFactory,
        IsClass = true,
        Name = nameTable.GetNameFor("<Module>"),
      };
      cciAssembly.AllTypes.Add(moduleClass);


      foreach (var m in assemblySymbol.GlobalNamespace.GetMembers()) {

        var namespaceSymbol = m as INamespaceSymbol;
        if (namespaceSymbol != null) {
          var cciNtd = TranslateMetadata(namespaceSymbol);
          rootUnitNamespace.Members.Add(cciNtd);
          continue;
        }

        var typeSymbol = m as ITypeSymbol;
        if (typeSymbol != null) {
          var namedType = TranslateMetadata((INamedTypeSymbol) typeSymbol);
          // TODO: fix
          //namedType.Attributes = TranslateMetadata(typeSymbol.GetAttributes());
          var cciType = (INamespaceTypeDefinition) namedType;
          rootUnitNamespace.Members.Add(cciType);
          //cciAssembly.AllTypes.Add(cciType);
          continue;
        }

      }

      //if (this.entryPoint != null) {
      //  cciAssembly.Kind = ModuleKind.ConsoleApplication;
      //  cciAssembly.EntryPoint = this.entryPoint;
      //}

      return cciAssembly;
    }
开发者ID:asvishnyakov,项目名称:CodeContracts,代码行数:72,代码来源:ReferenceMapper.cs

示例4: MapNamespaces

 internal static int MapNamespaces(NamespaceInfoMap nsInfoMap, IAssemblySymbol assSymbol, bool isRef)
 {
     var count = 0;
     foreach (AttributeData attData in assSymbol.GetAttributes())
     {
         if (attData.AttributeClass.FullNameEquals(isRef ? __CompilerSchemaNamespaceAttributeNameParts : SchemaNamespaceAttributeNameParts))
         {
             var ctorArgs = attData.ConstructorArguments;
             string uri = null, dottedString = null;
             var ctorArgsLength = ctorArgs.Length;
             if (ctorArgsLength >= 2)
             {
                 uri = ctorArgs[0].Value as string;
                 if (uri != null)
                 {
                     dottedString = ctorArgs[1].Value as string;
                 }
             }
             if (dottedString == null)
             {
                 if (isRef)
                 {
                     CompilerContext.ErrorAndThrow(new DiagMsgEx(DiagCodeEx.Invalid__CompilerSchemaNamespaceAttribute,
                         assSymbol.Identity.Name), default(TextSpan));
                 }
                 else
                 {
                     CompilerContext.ErrorAndThrow(new DiagMsgEx(DiagCodeEx.InvalidSchemaNamespaceAttribute),
                         GetTextSpan(attData));
                 }
             }
             NamespaceInfo nsInfo;
             if (!nsInfoMap.TryGetValue(uri, out nsInfo))
             {
                 if (isRef)
                 {
                     continue;
                 }
                 else
                 {
                     CompilerContext.ErrorAndThrow(new DiagMsgEx(DiagCodeEx.InvalidSchemaNamespaceAttributeUri, uri),
                         GetTextSpan(attData));
                 }
             }
             if (nsInfo.DottedName != null)
             {
                 if (isRef)
                 {
                     CompilerContext.ErrorAndThrow(new DiagMsgEx(DiagCodeEx.Duplicate__CompilerSchemaNamespaceAttributeUri,
                         uri, assSymbol.Identity.Name), default(TextSpan));
                 }
                 else
                 {
                     CompilerContext.ErrorAndThrow(new DiagMsgEx(DiagCodeEx.DuplicateSchemaNamespaceAttributeUri, uri),
                         GetTextSpan(attData));
                 }
             }
             CSDottedName dottedName;
             if (!CSDottedName.TryParse(dottedString, out dottedName))
             {
                 if (isRef)
                 {
                     CompilerContext.ErrorAndThrow(new DiagMsgEx(DiagCodeEx.Invalid__CompilerSchemaNamespaceAttributeNamespaceName,
                         dottedString, assSymbol.Identity.Name), default(TextSpan));
                 }
                 else
                 {
                     CompilerContext.ErrorAndThrow(new DiagMsgEx(DiagCodeEx.InvalidSchemaNamespaceAttributeNamespaceName, dottedString),
                         GetTextSpan(attData));
                 }
             }
             nsInfo.DottedName = dottedName;
             nsInfo.IsRef = isRef;
             ++count;
             if (isRef)
             {
                 if (ctorArgsLength >= 4)
                 {
                     var ca2 = ctorArgs[2];
                     var ca3 = ctorArgs[3];
                     nsInfo.SetRefData(ca2.IsNull ? null : ca2.Values.Select(i => i.Value as string),
                        ca3.IsNull ? null : ca3.Values.Select(i => i.Value as string));
                 }
                 else
                 {
                     CompilerContext.ErrorAndThrow(new DiagMsgEx(DiagCodeEx.Invalid__CompilerSchemaNamespaceAttribute,
                         assSymbol.Identity.Name), default(TextSpan));
                 }
             }
         }
     }
     return count;
 }
开发者ID:knat,项目名称:SData,代码行数:93,代码来源:CSEX.cs


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