public bool?IsUnsafe(ITypeDefinitionMember member) { var field = member as IFieldDefinition; if (field != null) { return(field.Type.IsUnsafeType()); } var method = member as IMethodDefinition; if (method != null) { return(method.IsMethodUnsafe()); } var property = member as IPropertyDefinition; if (property != null) { return(property.Accessors.Any(a => CSharpCciExtensions.IsMethodUnsafe(a.ResolvedMethod))); } var evnt = member as IEventDefinition; if (evnt != null) { return(evnt.Accessors.Any(a => a.ResolvedMethod.IsMethodUnsafe())); } return(null); }
public void WriteIdentifier(string id, bool escape) { // Escape keywords if (escape && CSharpCciExtensions.IsKeyword(id)) { id = "@" + id; } _writer.WriteIdentifier(id); }
private void WriteTypeName(ITypeReference type, bool noSpace = false, bool isDynamic = false, bool useTypeKeywords = true, bool omitGenericTypeList = false) { if (isDynamic) { WriteKeyword("dynamic", noSpace: noSpace); return; } NameFormattingOptions namingOptions = NameFormattingOptions.TypeParameters; if (useTypeKeywords) { namingOptions |= NameFormattingOptions.UseTypeKeywords; } if (_forCompilationIncludeGlobalprefix) { namingOptions |= NameFormattingOptions.UseGlobalPrefix; } if (!_forCompilation) { namingOptions |= NameFormattingOptions.OmitContainingNamespace; } if (omitGenericTypeList) { namingOptions |= NameFormattingOptions.EmptyTypeParameterList; } string name = TypeHelper.GetTypeName(type, namingOptions); if (CSharpCciExtensions.IsKeyword(name)) { _writer.WriteKeyword(name); } else { _writer.WriteTypeName(name); } if (!noSpace) { WriteSpace(); } }
private void WriteTypeName(ITypeReference type, bool noSpace = false, IEnumerable <ICustomAttribute> attributes = null, bool useTypeKeywords = true, bool omitGenericTypeList = false) { if (attributes != null && IsDynamic(attributes)) { WriteKeyword("dynamic", noSpace: noSpace); return; } NameFormattingOptions namingOptions = NameFormattingOptions.TypeParameters | NameFormattingOptions.ContractNullable; if (useTypeKeywords) { namingOptions |= NameFormattingOptions.UseTypeKeywords; } if (_forCompilationIncludeGlobalprefix) { namingOptions |= NameFormattingOptions.UseGlobalPrefix; } if (!_forCompilation) { namingOptions |= NameFormattingOptions.OmitContainingNamespace; } if (omitGenericTypeList) { namingOptions |= NameFormattingOptions.EmptyTypeParameterList; } void WriteTypeNameInner(ITypeReference typeReference) { string name = TypeHelper.GetTypeName(typeReference, namingOptions); if (CSharpCciExtensions.IsKeyword(name)) { _writer.WriteKeyword(name); } else { _writer.WriteTypeName(name); } } var definition = type.GetDefinitionOrNull(); if (definition is IGenericTypeInstance genericType && genericType.IsValueTuple()) { string[] names = attributes.GetValueTupleNames(); _writer.WriteSymbol("("); int i = 0; foreach (var parameter in genericType.GenericArguments) { if (i != 0) { _writer.WriteSymbol(","); _writer.WriteSpace(); } WriteTypeNameInner(parameter); if (names?[i] != null) { _writer.WriteSpace(); _writer.WriteIdentifier(names[i]); } i++; } _writer.WriteSymbol(")"); }