本文整理汇总了C#中Microsoft.CodeAnalysis.CSharp.Symbols.Metadata.PE.PEModuleSymbol类的典型用法代码示例。如果您正苦于以下问题:C# PEModuleSymbol类的具体用法?C# PEModuleSymbol怎么用?C# PEModuleSymbol使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
PEModuleSymbol类属于Microsoft.CodeAnalysis.CSharp.Symbols.Metadata.PE命名空间,在下文中一共展示了PEModuleSymbol类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetDocumentationComment
internal static string GetDocumentationComment(
Symbol symbol,
PEModuleSymbol containingPEModule,
CultureInfo preferredCulture,
CancellationToken cancellationToken,
ref Tuple<CultureInfo, string> lazyDocComment)
{
// Have we cached anything?
if (lazyDocComment == null)
{
Interlocked.CompareExchange(
ref lazyDocComment,
Tuple.Create(
preferredCulture,
containingPEModule.DocumentationProvider.GetDocumentationForSymbol(
symbol.GetDocumentationCommentId(), preferredCulture, cancellationToken)),
null);
}
// Does the cached version match the culture we asked for?
if (object.Equals(lazyDocComment.Item1, preferredCulture))
{
return lazyDocComment.Item2;
}
// We've already cached a different culture - create a fresh version.
return containingPEModule.DocumentationProvider.GetDocumentationForSymbol(
symbol.GetDocumentationCommentId(), preferredCulture, cancellationToken);
}
示例2: PEFieldSymbol
internal PEFieldSymbol(
PEModuleSymbol moduleSymbol,
PENamedTypeSymbol containingType,
FieldDefinitionHandle fieldDef)
{
Debug.Assert((object)moduleSymbol != null);
Debug.Assert((object)containingType != null);
Debug.Assert(!fieldDef.IsNil);
_handle = fieldDef;
_containingType = containingType;
try
{
moduleSymbol.Module.GetFieldDefPropsOrThrow(fieldDef, out _name, out _flags);
}
catch (BadImageFormatException)
{
if ((object)_name == null)
{
_name = String.Empty;
}
_lazyUseSiteDiagnostic = new CSDiagnosticInfo(ErrorCode.ERR_BindToBogus, this);
}
}
示例3: InitializeObsoleteDataFromMetadata
/// <summary>
/// Initialize the ObsoleteAttributeData by fetching attributes and decoding ObsoleteAttributeData. This can be
/// done for Metadata symbol easily whereas trying to do this for source symbols could result in cycles.
/// </summary>
internal static void InitializeObsoleteDataFromMetadata(ref ObsoleteAttributeData data, EntityHandle token, PEModuleSymbol containingModule)
{
if (ReferenceEquals(data, ObsoleteAttributeData.Uninitialized))
{
ObsoleteAttributeData obsoleteAttributeData = GetObsoleteDataFromMetadata(token, containingModule);
Interlocked.CompareExchange(ref data, obsoleteAttributeData, ObsoleteAttributeData.Uninitialized);
}
}
示例4: PETypeParameterSymbol
internal PETypeParameterSymbol(
PEModuleSymbol moduleSymbol,
PEMethodSymbol definingMethod,
ushort ordinal,
GenericParameterHandle handle)
: this(moduleSymbol, (Symbol)definingMethod, ordinal, handle)
{
}
示例5: MemberRefMetadataDecoder
public MemberRefMetadataDecoder(
PEModuleSymbol moduleSymbol,
TypeSymbol containingType) :
base(moduleSymbol, containingType as PENamedTypeSymbol)
{
Debug.Assert((object)containingType != null);
_containingType = containingType;
}
示例6: GetObsoleteDataFromMetadata
/// <summary>
/// Get the ObsoleteAttributeData by fetching attributes and decoding ObsoleteAttributeData. This can be
/// done for Metadata symbol easily whereas trying to do this for source symbols could result in cycles.
/// </summary>
internal static ObsoleteAttributeData GetObsoleteDataFromMetadata(EntityHandle token, PEModuleSymbol containingModule)
{
ObsoleteAttributeData obsoleteAttributeData;
bool isObsolete = containingModule.Module.HasDeprecatedOrObsoleteAttribute(token, out obsoleteAttributeData);
Debug.Assert(isObsolete == (obsoleteAttributeData != null));
Debug.Assert(obsoleteAttributeData == null || !obsoleteAttributeData.IsUninitialized);
return obsoleteAttributeData;
}
示例7: PEParameterSymbol
internal PEParameterSymbol(
PEModuleSymbol moduleSymbol,
PEMethodSymbol containingSymbol,
int ordinal,
MetadataDecoder.ParamInfo parameter,
out bool isBad)
: this(moduleSymbol, containingSymbol, ordinal, parameter.IsByRef, parameter.HasByRefBeforeCustomModifiers, parameter.Type, parameter.Handle, parameter.CustomModifiers, out isBad)
{
}
示例8: InitializeObsoleteDataFromMetadata
/// <summary>
/// Initialize the ObsoleteAttributeData by fetching attributes and decoding ObsoleteAttributeData. This can be
/// done for Metadata symbol easily whereas trying to do this for source symbols could result in cycles.
/// </summary>
internal static void InitializeObsoleteDataFromMetadata(ref ObsoleteAttributeData data, Handle token, PEModuleSymbol containingModule)
{
if (ReferenceEquals(data, ObsoleteAttributeData.Uninitialized))
{
ObsoleteAttributeData obsoleteAttributeData;
bool isObsolete = containingModule.Module.HasDeprecatedOrObsoleteAttribute(token, out obsoleteAttributeData);
Debug.Assert(isObsolete == (obsoleteAttributeData != null));
Debug.Assert(obsoleteAttributeData == null || !obsoleteAttributeData.IsUninitialized);
Interlocked.CompareExchange(ref data, obsoleteAttributeData, ObsoleteAttributeData.Uninitialized);
}
}
示例9: PEAssemblySymbol
internal PEAssemblySymbol(PEAssembly assembly, DocumentationProvider documentationProvider, bool isLinked, MetadataImportOptions importOptions)
{
Debug.Assert(assembly != null);
Debug.Assert(documentationProvider != null);
_assembly = assembly;
_documentationProvider = documentationProvider;
var modules = new ModuleSymbol[assembly.Modules.Length];
for (int i = 0; i < assembly.Modules.Length; i++)
{
modules[i] = new PEModuleSymbol(this, assembly.Modules[i], importOptions, i);
}
_modules = modules.AsImmutableOrNull();
_isLinked = isLinked;
}
示例10: DecodeTupleTypesIfApplicable
public static TypeSymbol DecodeTupleTypesIfApplicable(
TypeSymbol metadataType,
EntityHandle targetSymbolToken,
PEModuleSymbol containingModule)
{
ImmutableArray<string> elementNames;
var hasTupleElementNamesAttribute = containingModule
.Module
.HasTupleElementNamesAttribute(targetSymbolToken, out elementNames);
// If we have the TupleElementNamesAttribute, but no names, that's
// bad metadata
if (hasTupleElementNamesAttribute && elementNames.IsDefaultOrEmpty)
{
return new UnsupportedMetadataTypeSymbol();
}
return DecodeTupleTypesInternal(metadataType, containingModule.ContainingAssembly, elementNames, hasTupleElementNamesAttribute);
}
示例11: TransformType
/// <summary>
/// Decodes the attributes applied to the given <see paramref="targetSymbol"/> from metadata and checks if <see cref="System.Runtime.CompilerServices.DynamicAttribute"/> is applied.
/// If so, it transforms the given <see paramref="metadataType"/>, using the decoded dynamic transforms attribute argument,
/// by replacing each occurrence of <see cref="System.Object"/> type with dynamic type.
/// If no <see cref="System.Runtime.CompilerServices.DynamicAttribute"/> is applied or the decoded dynamic transforms attribute argument is errorneous,
/// returns the unchanged <see paramref="metadataType"/>.
/// </summary>
/// <remarks>This method is a port of TypeManager::ImportDynamicTransformType from the native compiler.</remarks>
internal static TypeSymbol TransformType(
TypeSymbol metadataType,
int targetSymbolCustomModifierCount,
Handle targetSymbolToken,
PEModuleSymbol containingModule,
RefKind targetSymbolRefKind = RefKind.None)
{
Debug.Assert((object)metadataType != null);
ImmutableArray<bool> dynamicTransformFlags;
if (containingModule.Module.HasDynamicAttribute(targetSymbolToken, out dynamicTransformFlags))
{
return TransformTypeInternal(metadataType, containingModule.ContainingAssembly,
targetSymbolCustomModifierCount, targetSymbolRefKind, dynamicTransformFlags,
haveCustomModifierFlags: true);
}
// No DynamicAttribute applied to the target symbol, return unchanged metadataType.
return metadataType;
}
示例12: DecodeTupleTypesIfApplicable
public static TypeSymbol DecodeTupleTypesIfApplicable(
TypeSymbol metadataType,
EntityHandle targetSymbolToken,
PEModuleSymbol containingModule)
{
Debug.Assert((object)metadataType != null);
Debug.Assert((object)containingModule != null);
ImmutableArray<string> elementNames;
var hasTupleElementNamesAttribute = containingModule
.Module
.HasTupleElementNamesAttribute(targetSymbolToken, out elementNames);
// If we have the TupleElementNamesAttribute, but no names, that's
// bad metadata
if (hasTupleElementNamesAttribute && elementNames.IsDefaultOrEmpty)
{
return new UnsupportedMetadataTypeSymbol();
}
var decoder = new TupleTypeDecoder(elementNames,
containingModule.ContainingAssembly);
try
{
var decoded = decoder.DecodeType(metadataType);
// If not all of the names have been used, the metadata is bad
if (!hasTupleElementNamesAttribute ||
decoder._namesIndex == 0)
{
return decoded;
}
}
catch (InvalidOperationException)
{
// Indicates that the tuple info in the attribute didn't match
// the type. Bad metadata.
}
// Bad metadata
return new UnsupportedMetadataTypeSymbol();
}
示例13: Create
internal static PEPropertySymbol Create(
PEModuleSymbol moduleSymbol,
PENamedTypeSymbol containingType,
PropertyDefinitionHandle handle,
PEMethodSymbol getMethod,
PEMethodSymbol setMethod)
{
Debug.Assert((object)moduleSymbol != null);
Debug.Assert((object)containingType != null);
Debug.Assert(!handle.IsNil);
var metadataDecoder = new MetadataDecoder(moduleSymbol, containingType);
SignatureHeader callingConvention;
BadImageFormatException propEx;
var propertyParams = metadataDecoder.GetSignatureForProperty(handle, out callingConvention, out propEx);
Debug.Assert(propertyParams.Length > 0);
var returnInfo = propertyParams[0];
PEPropertySymbol result;
if (returnInfo.CustomModifiers.IsDefaultOrEmpty && returnInfo.RefCustomModifiers.IsDefaultOrEmpty)
{
result = new PEPropertySymbol(moduleSymbol, containingType, handle, getMethod, setMethod, 0, propertyParams, metadataDecoder);
}
else
{
result = new PEPropertySymbolWithCustomModifiers(moduleSymbol, containingType, handle, getMethod, setMethod, propertyParams, metadataDecoder);
}
if (propEx != null)
{
result._lazyUseSiteDiagnostic = new CSDiagnosticInfo(ErrorCode.ERR_BindToBogus, result);
}
return result;
}
示例14: GetParameters
private static ImmutableArray<ParameterSymbol> GetParameters(
PEModuleSymbol moduleSymbol,
PEPropertySymbol property,
MetadataDecoder.ParamInfo[] propertyParams,
MetadataDecoder.ParamInfo[] accessorParams,
out bool anyParameterIsBad)
{
anyParameterIsBad = false;
// First parameter is the property type.
if (propertyParams.Length < 2)
{
return ImmutableArray<ParameterSymbol>.Empty;
}
var numAccessorParams = accessorParams.Length;
var parameters = new ParameterSymbol[propertyParams.Length - 1];
for (int i = 1; i < propertyParams.Length; i++) // from 1 to skip property/return type
{
// NOTE: this is a best guess at the Dev10 behavior. The actual behavior is
// in the unmanaged helper code that Dev10 uses to load the metadata.
var propertyParam = propertyParams[i];
var paramHandle = i < numAccessorParams ? accessorParams[i].Handle : propertyParam.Handle;
var ordinal = i - 1;
bool isBad;
parameters[ordinal] = new PEParameterSymbol(moduleSymbol, property, ordinal, paramHandle, propertyParam, out isBad);
if (isBad)
{
anyParameterIsBad = true;
}
}
return parameters.AsImmutableOrNull();
}
示例15: PEPropertySymbol
internal PEPropertySymbol(
PEModuleSymbol moduleSymbol,
PENamedTypeSymbol containingType,
PropertyHandle handle,
PEMethodSymbol getMethod,
PEMethodSymbol setMethod)
{
Debug.Assert((object)moduleSymbol != null);
Debug.Assert((object)containingType != null);
Debug.Assert(!handle.IsNil);
this.containingType = containingType;
var module = moduleSymbol.Module;
PropertyAttributes mdFlags = 0;
BadImageFormatException mrEx = null;
try
{
module.GetPropertyDefPropsOrThrow(handle, out this.name, out mdFlags);
}
catch (BadImageFormatException e)
{
mrEx = e;
if ((object)this.name == null)
{
this.name = string.Empty;
}
}
this.getMethod = getMethod;
this.setMethod = setMethod;
this.handle = handle;
var metadataDecoder = new MetadataDecoder(moduleSymbol, containingType);
byte callingConvention;
BadImageFormatException propEx;
var propertyParams = metadataDecoder.GetSignatureForProperty(handle, out callingConvention, out propEx);
Debug.Assert(propertyParams.Length > 0);
byte unusedCallingConvention;
BadImageFormatException getEx = null;
var getMethodParams = (object)getMethod == null ? null : metadataDecoder.GetSignatureForMethod(getMethod.Handle, out unusedCallingConvention, out getEx);
BadImageFormatException setEx = null;
var setMethodParams = (object)setMethod == null ? null : metadataDecoder.GetSignatureForMethod(setMethod.Handle, out unusedCallingConvention, out setEx);
// NOTE: property parameter names are not recorded in metadata, so we have to
// use the parameter names from one of the indexers.
// NB: prefer setter names to getter names if both are present.
bool isBad;
this.parameters = GetParameters(moduleSymbol, this, propertyParams, setMethodParams ?? getMethodParams, out isBad);
if (propEx != null || getEx != null || setEx != null || mrEx != null || isBad)
{
lazyUseSiteDiagnostic = new CSDiagnosticInfo(ErrorCode.ERR_BindToBogus, this);
}
this.typeCustomModifiers = CSharpCustomModifier.Convert(propertyParams[0].CustomModifiers);
// CONSIDER: Can we make parameter type computation lazy?
TypeSymbol originalPropertyType = propertyParams[0].Type;
this.propertyType = DynamicTypeDecoder.TransformType(originalPropertyType, typeCustomModifiers.Length, handle, moduleSymbol);
// Dynamify object type if necessary
this.propertyType = this.propertyType.AsDynamicIfNoPia(this.containingType);
// A property is bogus and must be accessed by calling its accessors directly if the
// accessor signatures do not agree, both with each other and with the property,
// or if it has parameters and is not an indexer or indexed property.
bool callMethodsDirectly = !DoSignaturesMatch(module, metadataDecoder, propertyParams, this.getMethod, getMethodParams, this.setMethod, setMethodParams) ||
MustCallMethodsDirectlyCore();
if (!callMethodsDirectly)
{
if ((object)this.getMethod != null)
{
this.getMethod.SetAssociatedProperty(this, MethodKind.PropertyGet);
}
if ((object)this.setMethod != null)
{
this.setMethod.SetAssociatedProperty(this, MethodKind.PropertySet);
}
}
if (callMethodsDirectly)
{
flags |= Flags.CallMethodsDirectly;
}
if ((mdFlags & PropertyAttributes.SpecialName) != 0)
{
flags |= Flags.IsSpecialName;
}
if ((mdFlags & PropertyAttributes.RTSpecialName) != 0)
{
flags |= Flags.IsRuntimeSpecialName;
}
}