本文整理汇总了C#中Microsoft.CodeAnalysis.Emit.EmitContext类的典型用法代码示例。如果您正苦于以下问题:C# EmitContext类的具体用法?C# EmitContext怎么用?C# EmitContext使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
EmitContext类属于Microsoft.CodeAnalysis.Emit命名空间,在下文中一共展示了EmitContext类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: GetMetadataConstantValue
internal Cci.IMetadataConstant GetMetadataConstantValue(EmitContext context)
{
if (!HasMetadataConstantValue)
{
return null;
}
ConstantValue constant = this.ExplicitDefaultConstantValue;
TypeSymbol type;
if (constant.SpecialType != SpecialType.None)
{
// preserve the exact type of the constant for primitive types,
// e.g. it should be Int16 for [DefaultParameterValue((short)1)]int x
type = this.ContainingAssembly.GetSpecialType(constant.SpecialType);
}
else
{
// default(struct), enum
type = this.Type;
}
return ((PEModuleBuilder)context.Module).CreateConstant(type, constant.Value,
syntaxNodeOpt: (CSharpSyntaxNode)context.SyntaxNodeOpt,
diagnostics: context.Diagnostics);
}
开发者ID:CAPCHIK,项目名称:roslyn,代码行数:25,代码来源:ParameterSymbolAdapter.cs
示例2:
Cci.INamedTypeReference Cci.IGenericTypeInstanceReference.GetGenericType(EmitContext context)
{
System.Diagnostics.Debug.Assert(UnderlyingNamedType.OriginalDefinition.IsDefinition);
PEModuleBuilder moduleBeingBuilt = (PEModuleBuilder)context.Module;
return moduleBeingBuilt.Translate(this.UnderlyingNamedType.OriginalDefinition, syntaxNodeOpt: (CSharpSyntaxNode)context.SyntaxNodeOpt,
diagnostics: context.Diagnostics, needDeclaration: true);
}
开发者ID:XieShuquan,项目名称:roslyn,代码行数:7,代码来源:SpecializedGenericNestedTypeInstanceReference.cs
示例3: PEDeltaAssemblyBuilder
public PEDeltaAssemblyBuilder(
SourceAssemblySymbol sourceAssembly,
string outputName,
OutputKind outputKind,
ModulePropertiesForSerialization serializationProperties,
IEnumerable<ResourceDescription> manifestResources,
Func<AssemblySymbol, AssemblyIdentity> assemblySymbolMapper,
EmitBaseline previousGeneration,
IEnumerable<SemanticEdit> edits)
: base(sourceAssembly, outputName, outputKind, serializationProperties, manifestResources, assemblySymbolMapper, additionalTypes: ImmutableArray<NamedTypeSymbol>.Empty, metadataOnly:false)
{
var context = new EmitContext(this, null, new DiagnosticBag());
var module = previousGeneration.OriginalMetadata;
var compilation = sourceAssembly.DeclaringCompilation;
var metadataAssembly = compilation.GetBoundReferenceManager().CreatePEAssemblyForAssemblyMetadata(AssemblyMetadata.Create(module), MetadataImportOptions.All);
var metadataDecoder = new Microsoft.CodeAnalysis.CSharp.Symbols.Metadata.PE.MetadataDecoder(metadataAssembly.PrimaryModule);
previousGeneration = EnsureInitialized(previousGeneration, metadataDecoder);
var matchToMetadata = new SymbolMatcher(previousGeneration.AnonymousTypeMap, sourceAssembly, context, metadataAssembly);
SymbolMatcher matchToPrevious = null;
if (previousGeneration.Ordinal > 0)
{
var previousAssembly = ((CSharpCompilation)previousGeneration.Compilation).SourceAssembly;
var previousContext = new EmitContext((PEModuleBuilder)previousGeneration.PEModuleBuilder, null, new DiagnosticBag());
matchToPrevious = new SymbolMatcher(previousGeneration.AnonymousTypeMap, sourceAssembly, context, previousAssembly, previousContext);
}
this.previousDefinitions = new CSharpDefinitionMap(previousGeneration.OriginalMetadata.Module, edits, metadataDecoder, matchToMetadata, matchToPrevious);
this.previousGeneration = previousGeneration;
this.changes = new SymbolChanges(this.previousDefinitions, edits);
}
开发者ID:pheede,项目名称:roslyn,代码行数:33,代码来源:PEDeltaAssemblyBuilder.cs
示例4:
Cci.INestedTypeReference Cci.ISpecializedNestedTypeReference.GetUnspecializedVersion(EmitContext context)
{
Debug.Assert(UnderlyingNamedType.OriginalDefinition.IsDefinition);
var result = ((PEModuleBuilder)context.Module).Translate(this.UnderlyingNamedType.OriginalDefinition,
(CSharpSyntaxNode)context.SyntaxNodeOpt, context.Diagnostics, needDeclaration: true).AsNestedTypeReference;
Debug.Assert(result != null);
return result;
}
开发者ID:XieShuquan,项目名称:roslyn,代码行数:9,代码来源:SpecializedNestedTypeReference.cs
示例5: return
Cci.IMethodReference Cci.IGenericMethodInstanceReference.GetGenericMethod(EmitContext context)
{
// NoPia method might come through here.
return ((PEModuleBuilder)context.Module).Translate(
UnderlyingMethod.OriginalDefinition,
syntaxNodeOpt: context.SyntaxNodeOpt,
diagnostics: context.Diagnostics,
needDeclaration: true);
}
开发者ID:iolevel,项目名称:peachpie,代码行数:9,代码来源:GenericMethodInstanceReference.cs
示例6: foreach
IEnumerable<Cci.ITypeReference> Cci.IGenericMethodInstanceReference.GetGenericArguments(EmitContext context)
{
PEModuleBuilder moduleBeingBuilt = (PEModuleBuilder)context.Module;
foreach (var arg in UnderlyingMethod.TypeArguments)
{
yield return moduleBeingBuilt.Translate(arg, syntaxNodeOpt: (CSharpSyntaxNode)context.SyntaxNodeOpt, diagnostics: context.Diagnostics);
}
}
开发者ID:CAPCHIK,项目名称:roslyn,代码行数:9,代码来源:SpecializedGenericMethodInstanceReference.cs
示例7: SerializeMethodDebugInfo
public byte[] SerializeMethodDebugInfo(EmitContext context, IMethodBody methodBody, uint methodToken, bool isEncDelta, bool suppressNewCustomDebugInfo, out bool emitExternNamespaces)
{
emitExternNamespaces = false;
// CONSIDER: this may not be the same "first" method as in Dev10, but
// it shouldn't matter since all methods will still forward to a method
// containing the appropriate information.
if (_methodBodyWithModuleInfo == null) //UNDONE: || edit-and-continue
{
// This module level information could go on every method (and does in
// the edit-and-continue case), but - as an optimization - we'll just
// put it on the first method we happen to encounter and then put a
// reference to the first method's token in every other method (so they
// can find the information).
if (context.Module.GetAssemblyReferenceAliases(context).Any())
{
_methodTokenWithModuleInfo = methodToken;
_methodBodyWithModuleInfo = methodBody;
emitExternNamespaces = true;
}
}
var customDebugInfo = ArrayBuilder<MemoryStream>.GetInstance();
SerializeIteratorClassMetadata(methodBody, customDebugInfo);
// NOTE: This is an attempt to match Dev10's apparent behavior. For iterator methods (i.e. the method
// that appears in source, not the synthesized ones), Dev10 only emits the ForwardIterator and IteratorLocal
// custom debug info (e.g. there will be no information about the usings that were in scope).
// NOTE: There seems to be an unusual behavior in ISymUnmanagedWriter where, if all the methods in a type are
// iterator methods, no custom debug info is emitted for any method. Adding a single non-iterator
// method causes the custom debug info to be produced for all methods (including the iterator methods).
// Since we are making the same ISymUnmanagedWriter calls as Dev10, we see the same behavior (i.e. this
// is not a regression).
if (methodBody.StateMachineTypeName == null)
{
SerializeNamespaceScopeMetadata(context, methodBody, customDebugInfo);
SerializeStateMachineLocalScopes(methodBody, customDebugInfo);
}
if (!suppressNewCustomDebugInfo)
{
SerializeDynamicLocalInfo(methodBody, customDebugInfo);
// delta doesn't need this information - we use information recorded by previous generation emit
if (!isEncDelta)
{
var encMethodInfo = MetadataWriter.GetEncMethodDebugInfo(methodBody);
SerializeCustomDebugInformation(encMethodInfo, customDebugInfo);
}
}
byte[] result = SerializeCustomDebugMetadata(customDebugInfo);
customDebugInfo.Free();
return result;
}
开发者ID:elemk0vv,项目名称:roslyn-1,代码行数:56,代码来源:CustomDebugInfoWriter.cs
示例8: ReferenceEquals
Cci.IAssemblyReference Cci.IModuleReference.GetContainingAssembly(EmitContext context)
{
if (this.moduleBeingBuilt.OutputKind.IsNetModule() &&
ReferenceEquals(moduleBeingBuilt.SourceModule.ContainingAssembly, underlyingModule.ContainingAssembly))
{
return null;
}
return moduleBeingBuilt.Translate(underlyingModule.ContainingAssembly, context.Diagnostics);
}
开发者ID:modulexcite,项目名称:pattern-matching-csharp,代码行数:10,代码来源:ModuleReference.cs
示例9: PEDeltaAssemblyBuilder
public PEDeltaAssemblyBuilder(
SourceAssemblySymbol sourceAssembly,
EmitOptions emitOptions,
OutputKind outputKind,
Cci.ModulePropertiesForSerialization serializationProperties,
IEnumerable<ResourceDescription> manifestResources,
EmitBaseline previousGeneration,
IEnumerable<SemanticEdit> edits,
Func<ISymbol, bool> isAddedSymbol)
: base(sourceAssembly, emitOptions, outputKind, serializationProperties, manifestResources, additionalTypes: ImmutableArray<NamedTypeSymbol>.Empty)
{
var initialBaseline = previousGeneration.InitialBaseline;
var context = new EmitContext(this, null, new DiagnosticBag());
// Hydrate symbols from initial metadata. Once we do so it is important to reuse these symbols across all generations,
// in order for the symbol matcher to be able to use reference equality once it maps symbols to initial metadata.
var metadataSymbols = GetOrCreateMetadataSymbols(initialBaseline, sourceAssembly.DeclaringCompilation);
var metadataDecoder = (MetadataDecoder)metadataSymbols.MetadataDecoder;
var metadataAssembly = (PEAssemblySymbol)metadataDecoder.ModuleSymbol.ContainingAssembly;
var matchToMetadata = new CSharpSymbolMatcher(metadataSymbols.AnonymousTypes, sourceAssembly, context, metadataAssembly);
CSharpSymbolMatcher matchToPrevious = null;
if (previousGeneration.Ordinal > 0)
{
var previousAssembly = ((CSharpCompilation)previousGeneration.Compilation).SourceAssembly;
var previousContext = new EmitContext((PEModuleBuilder)previousGeneration.PEModuleBuilder, null, new DiagnosticBag());
matchToPrevious = new CSharpSymbolMatcher(
previousGeneration.AnonymousTypeMap,
sourceAssembly: sourceAssembly,
sourceContext: context,
otherAssembly: previousAssembly,
otherContext: previousContext,
otherSynthesizedMembersOpt: previousGeneration.SynthesizedMembers);
}
_previousDefinitions = new CSharpDefinitionMap(previousGeneration.OriginalMetadata.Module, edits, metadataDecoder, matchToMetadata, matchToPrevious);
_previousGeneration = previousGeneration;
_changes = new SymbolChanges(_previousDefinitions, edits, isAddedSymbol);
// Workaround for https://github.com/dotnet/roslyn/issues/3192.
// When compiling state machine we stash types of awaiters and state-machine hoisted variables,
// so that next generation can look variables up and reuse their slots if possible.
//
// When we are about to allocate a slot for a lifted variable while compiling the next generation
// we map its type to the previous generation and then check the slot types that we stashed earlier.
// If the variable type matches we reuse it. In order to compare the previous variable type with the current one
// both need to be completely lowered (translated). Standard translation only goes one level deep.
// Generic arguments are not translated until they are needed by metadata writer.
//
// In order to get the fully lowered form we run the type symbols of stashed variables thru a deep translator
// that translates the symbol recursively.
_deepTranslator = new CSharpSymbolMatcher.DeepTranslator(sourceAssembly.GetSpecialType(SpecialType.System_Object));
}
开发者ID:GeertVL,项目名称:roslyn,代码行数:55,代码来源:PEDeltaAssemblyBuilder.cs
示例10: VisitTypeReference
private static void VisitTypeReference(Cci.ITypeReference typeReference, EmitContext context)
{
Debug.Assert(typeReference != null);
Cci.IArrayTypeReference arrayType = typeReference as Cci.IArrayTypeReference;
if (arrayType != null)
{
VisitTypeReference(arrayType.GetElementType(context), context);
return;
}
Cci.IPointerTypeReference pointerType = typeReference as Cci.IPointerTypeReference;
if (pointerType != null)
{
VisitTypeReference(pointerType.GetTargetType(context), context);
return;
}
Debug.Assert(!(typeReference is Cci.IManagedPointerTypeReference));
//Cci.IManagedPointerTypeReference managedPointerType = typeReference as Cci.IManagedPointerTypeReference;
//if (managedPointerType != null)
//{
// VisitTypeReference(managedPointerType.GetTargetType(this.context));
// return;
//}
Cci.IModifiedTypeReference modifiedType = typeReference as Cci.IModifiedTypeReference;
if (modifiedType != null)
{
foreach (var custModifier in modifiedType.CustomModifiers)
{
VisitTypeReference(custModifier.GetModifier(context), context);
}
VisitTypeReference(modifiedType.UnmodifiedType, context);
return;
}
// Visit containing type
Cci.INestedTypeReference nestedType = typeReference.AsNestedTypeReference;
if (nestedType != null)
{
VisitTypeReference(nestedType.GetContainingType(context), context);
}
// Visit generic arguments
Cci.IGenericTypeInstanceReference genericInstance = typeReference.AsGenericTypeInstanceReference;
if (genericInstance != null)
{
foreach (var arg in genericInstance.GetGenericArguments(context))
{
VisitTypeReference(arg, context);
}
}
}
开发者ID:Rickinio,项目名称:roslyn,代码行数:54,代码来源:ReferenceDependencyWalker.cs
示例11: foreach
ImmutableArray<Cci.ITypeReference> Cci.IGenericTypeInstanceReference.GetGenericArguments(EmitContext context)
{
PEModuleBuilder moduleBeingBuilt = (PEModuleBuilder)context.Module;
var builder = ArrayBuilder<Cci.ITypeReference>.GetInstance();
foreach (TypeSymbol type in UnderlyingNamedType.TypeArgumentsNoUseSiteDiagnostics)
{
builder.Add(moduleBeingBuilt.Translate(type, syntaxNodeOpt: (CSharpSyntaxNode)context.SyntaxNodeOpt, diagnostics: context.Diagnostics));
}
return builder.ToImmutableAndFree();
}
开发者ID:XieShuquan,项目名称:roslyn,代码行数:11,代码来源:SpecializedGenericNestedTypeInstanceReference.cs
示例12:
Cci.PrimitiveTypeCode Cci.ITypeReference.TypeCode(EmitContext context)
{
Debug.Assert(this.IsDefinitionOrDistinct());
if (this.IsDefinition)
{
return this.PrimitiveTypeCode;
}
return Cci.PrimitiveTypeCode.NotPrimitive;
}
开发者ID:pheede,项目名称:roslyn,代码行数:11,代码来源:NamedTypeSymbolAdapter.cs
示例13: GetConsolidatedTypeArguments
internal static void GetConsolidatedTypeArguments(this ITypeReference typeReference, ArrayBuilder<ITypeReference> consolidatedTypeArguments, EmitContext context)
{
INestedTypeReference nestedTypeReference = typeReference.AsNestedTypeReference;
nestedTypeReference?.GetContainingType(context).GetConsolidatedTypeArguments(consolidatedTypeArguments, context);
IGenericTypeInstanceReference genTypeInstance = typeReference.AsGenericTypeInstanceReference;
if (genTypeInstance != null)
{
consolidatedTypeArguments.AddRange(genTypeInstance.GetGenericArguments(context));
}
}
开发者ID:Rickinio,项目名称:roslyn,代码行数:11,代码来源:ITypeReferenceExtensions.cs
示例14:
Cci.ITypeReference Cci.IPointerTypeReference.GetTargetType(EmitContext context)
{
var type = ((PEModuleBuilder)context.Module).Translate(this.PointedAtType, syntaxNodeOpt: (CSharpSyntaxNode)context.SyntaxNodeOpt, diagnostics: context.Diagnostics);
if (this.CustomModifiers.Length == 0)
{
return type;
}
else
{
return new Cci.ModifiedTypeReference(type, this.CustomModifiers.As<Cci.ICustomModifier>());
}
}
开发者ID:Rickinio,项目名称:roslyn,代码行数:13,代码来源:PointerTypeSymbolAdapter.cs
示例15: return
Cci.ITypeReference Cci.ITypeMemberReference.GetContainingType(EmitContext context)
{
PEModuleBuilder moduleBeingBuilt = (PEModuleBuilder)context.Module;
Debug.Assert(this.IsDefinitionOrDistinct());
if (!this.IsDefinition)
{
return moduleBeingBuilt.Translate(this.ContainingType, context.SyntaxNodeOpt, context.Diagnostics);
}
return (Cci.ITypeReference)this.ContainingType;
}
开发者ID:iolevel,项目名称:peachpie,代码行数:13,代码来源:FieldSymbolAdapter.cs
示例16: GetNamedArguments
/// <summary>
/// Zero or more named arguments that specify values for fields and properties of the attribute.
/// </summary>
public ImmutableArray<Cci.IMetadataNamedArgument> GetNamedArguments(EmitContext context)
{
// Perform fixup
Cci.ITypeReference stringType = context.Module.GetPlatformType(Cci.PlatformType.SystemString, context);
#if DEBUG
// Must have exactly 1 named argument.
var namedArgs = this.sourceAttribute.GetNamedArguments(context);
Debug.Assert(namedArgs.Count() == 1);
// Named argument must be 'File' property of string type
var fileArg = namedArgs.First();
Debug.Assert(fileArg.ArgumentName == FilePropertyName);
Debug.Assert(context.Module.IsPlatformType(fileArg.Type, Cci.PlatformType.SystemString));
// Named argument value must be a non-empty string
Debug.Assert(fileArg.ArgumentValue is Cci.IMetadataConstant);
var fileName = (string)((Cci.IMetadataConstant)fileArg.ArgumentValue).Value;
Debug.Assert(!String.IsNullOrEmpty(fileName));
// PermissionSetAttribute type must have a writable public string type property member 'Hex'
Debug.Assert(((INamedTypeSymbol)this.sourceAttribute.GetType(context)).GetMembers(HexPropertyName).Any(
member => member.Kind == SymbolKind.Property && ((IPropertySymbol)member).Type.SpecialType == SpecialType.System_String));
#endif
string hexFileContent;
// Read the file contents at the resolved file path into a byte array.
// May throw PermissionSetFileReadException, which is handled in Compilation.Emit.
var resolver = context.ModuleBuilder.CommonCompilation.Options.XmlReferenceResolver;
// If the resolver isn't available we won't get here since we had to use it to resolve the path.
Debug.Assert(resolver != null);
try
{
using (Stream stream = resolver.OpenReadChecked(resolvedPermissionSetFilePath))
{
// Convert the byte array contents into a string in hexa-decimal format.
hexFileContent = ConvertToHex(stream);
}
}
catch (IOException e)
{
throw new PermissionSetFileReadException(e.Message, resolvedPermissionSetFilePath);
}
// Synthesize a named attribute argument "Hex = hexFileContent".
return ImmutableArray.Create<Cci.IMetadataNamedArgument>(new HexPropertyMetadataNamedArgument(stringType, new MetadataConstant(stringType, hexFileContent)));
}
开发者ID:pheede,项目名称:roslyn,代码行数:53,代码来源:PermissionSetAttribute.cs
示例17:
Cci.ITypeReference Cci.IFieldReference.GetType(EmitContext context)
{
var customModifiers = underlyingField.CustomModifiers;
var type = ((PEModuleBuilder)context.Module).Translate(underlyingField.Type, syntaxNodeOpt: (CSharpSyntaxNode)context.SyntaxNodeOpt, diagnostics: context.Diagnostics);
if (customModifiers.Length == 0)
{
return type;
}
else
{
return new Cci.ModifiedTypeReference(type, customModifiers);
}
}
开发者ID:pheede,项目名称:roslyn,代码行数:14,代码来源:SpecializedFieldReference.cs
示例18:
Cci.ITypeReference Cci.IArrayTypeReference.GetElementType(EmitContext context)
{
PEModuleBuilder moduleBeingBuilt = (PEModuleBuilder)context.Module;
var type = moduleBeingBuilt.Translate(this.ElementType, syntaxNodeOpt: (CSharpSyntaxNode)context.SyntaxNodeOpt, diagnostics: context.Diagnostics);
if (this.CustomModifiers.Length == 0)
{
return type;
}
else
{
return new Cci.ModifiedTypeReference(type, this.CustomModifiers.As<Cci.ICustomModifier>());
}
}
开发者ID:GloryChou,项目名称:roslyn,代码行数:15,代码来源:ArrayTypeSymbolAdapter.cs
示例19: foreach
ImmutableArray<Cci.IMetadataNamedArgument> Cci.ICustomAttribute.GetNamedArguments(EmitContext context)
{
var commonArgs = this.CommonNamedArguments;
if (commonArgs.IsEmpty)
{
return ImmutableArray<Cci.IMetadataNamedArgument>.Empty;
}
var builder = ArrayBuilder<Cci.IMetadataNamedArgument>.GetInstance();
foreach (var namedArgument in commonArgs)
{
builder.Add(CreateMetadataNamedArgument(namedArgument.Key, namedArgument.Value, context));
}
return builder.ToImmutableAndFree();
}
开发者ID:iolevel,项目名称:peachpie,代码行数:15,代码来源:AttributeDataAdapter.cs
示例20: GetUninstantiatedGenericType
internal static ITypeReference GetUninstantiatedGenericType(this ITypeReference typeReference, EmitContext context)
{
IGenericTypeInstanceReference genericTypeInstanceReference = typeReference.AsGenericTypeInstanceReference;
if (genericTypeInstanceReference != null)
{
return genericTypeInstanceReference.GetGenericType(context);
}
ISpecializedNestedTypeReference specializedNestedType = typeReference.AsSpecializedNestedTypeReference;
if (specializedNestedType != null)
{
return specializedNestedType.GetUnspecializedVersion(context);
}
return typeReference;
}
开发者ID:XieShuquan,项目名称:roslyn,代码行数:16,代码来源:ITypeReferenceExtensions.cs
注:本文中的Microsoft.CodeAnalysis.Emit.EmitContext类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论