public TypeSyntax GetVariableTypeSyntax(bool isImplicitlyTyped, IReferencedType type) { TypeSyntax typeSyntax; if (isImplicitlyTyped) { typeSyntax = SyntaxFactory.ParseTypeName("var"); typeSyntax = BuildSyntaxHelpers.AttachWhitespaceToFirstAndLast(typeSyntax, type.Whitespace2Set.First()); } else { typeSyntax = (TypeSyntax)RDom.CSharp.GetSyntaxGroup(type).First(); } return(typeSyntax); //if (itemAsVariable.IsImplicitlyTyped) //{ return SyntaxFactory.IdentifierName("var"); } //var type = itemAsVariable.Type; //if (itemAsVariable.IsAliased) //{ // var typeName = Mappings.AliasFromSystemType(type.Name); // return SyntaxFactory.IdentifierName(typeName); //} //return (TypeSyntax)(RDomCSharp.Factory.BuildSyntax(type)); }
/// <summary> /// Constructor to use when creating a RoslynDom from scratch /// </summary> /// <param name="name"> /// Name of the field /// </param> /// <param name="typeName"> /// Type name of the field</param> /// <param name="declaredAccessModifier"> /// The accessibilty (scope) modifier. Default is the most restrictive scope, private. /// </param> /// <param name="isStatic"> /// Pass true for an static class /// </param> /// <param name="isNew"> /// Pass true for an new class /// </param> public RDomField(string name, IReferencedType returnType, AccessModifier declaredAccessModifier = AccessModifier.Private, bool isStatic = false, bool isNew = false, bool isReadOnly = false, bool isVolatile = false, bool isConstant = false) : this(name, declaredAccessModifier, isStatic, isNew, isReadOnly, isVolatile, isConstant) { _returnType = returnType; }
/// <summary> /// Constructor to use when creating a RoslynDom from scratch /// </summary> /// <param name="name"> /// Name of the event /// </param> /// <param name="typeName"> /// Type name of the event</param> /// <param name="accessModifier"> /// The accessibilty (scope) modifier. Default is the most restrictive scope, private. /// </param> /// <param name="isAbstract"> /// Pass true for an abstract class /// </param> /// <param name="isVirtual"> /// Pass true for an virtual class /// </param> /// <param name="isOverride"> /// Pass true for an override class /// </param> /// <param name="isSealed"> /// Pass true for an sealed class /// </param> /// <param name="isStatic"> /// Pass true for an static class /// </param> /// <param name="isNew"> /// Pass true for an new class /// </param> public RDomEvent(string name, IReferencedType type, AccessModifier declaredAccessModifier = AccessModifier.Private, bool isAbstract = false, bool isVirtual = false, bool isOverride = false, bool isSealed = false, bool isStatic = false, bool isNew = false) : this(name, declaredAccessModifier, isAbstract, isVirtual, isOverride, isSealed, isStatic, isNew) { _type = type; }
public RDomProperty(string name, IReferencedType propertyType, AccessModifier accessModifier = AccessModifier.Private, bool isAbstract = false, bool isVirtual = false, bool isOverride = false, bool isSealed = false, bool isStatic = false, bool isNew = false, bool canGet = false, bool canSet = false) : this(name, accessModifier, isAbstract, isVirtual, isOverride, isSealed, isStatic, isNew, canGet, canSet) { PropertyType = propertyType; }
public RDomProperty(string name, IReferencedType propertyType, AccessModifier declaredAccessModifier = AccessModifier.Private, bool isAbstract = false, bool isVirtual = false, bool isOverride = false, bool isSealed = false, bool isStatic = false, bool isNew = false, bool isWriteOnly = false, bool isReadOnly = false) : this(name, declaredAccessModifier, isAbstract, isVirtual, isOverride, isSealed, isStatic, isNew, isWriteOnly, isReadOnly) { PropertyType = propertyType; }
public RDomParameter(string name, IReferencedType type, object defaultValue, LiteralKind defaultValueType, string defaultConstantIdentifier, int ordinal = 0, bool isOut = false, bool isRef = false, bool isParamArray = false) : this(name, defaultValue, defaultValueType, defaultConstantIdentifier, ordinal, isOut, isRef, isParamArray) { _type = type; }
public RDomMethod(string name, IReferencedType returnType, AccessModifier declaredAccessModifier = AccessModifier.Private, bool isAbstract = false, bool isVirtual = false, bool isOverride = false, bool isSealed = false, bool isNew = false, bool isStatic = false, bool isExtensionMethod = false) : this(name, declaredAccessModifier, isAbstract, isVirtual, isOverride, isSealed, isNew, isStatic, isExtensionMethod) { _returnType = returnType; }
public static string CleanName(IReferencedType type) { string typeName = type.QualifiedName; if (type.DisplayAlias) { typeName = AliasFromTypeName(typeName); } else { typeName = RemoveUsingPrefixes(type, typeName); } return(typeName); }
private void StoreConstraintWhitespace(TypeConstraintSyntax syntax, IReferencedType newItem) { CreateFromWorker.StoreListMemberWhitespace(syntax, SyntaxKind.CommaToken, LanguageElement.Identifier, newItem); //var whitespace2 = newItem.Whitespace2Set[LanguageElement.Identifier]; //if (string.IsNullOrEmpty(whitespace2.LeadingWhitespace)) //{ // var prevNodeOrToken = syntax.Parent // .ChildNodesAndTokens() // .PreviousSiblings(syntax) // .LastOrDefault(); // var sepKind = SyntaxKind.CommaToken; // if (prevNodeOrToken.Kind() == sepKind) // { // var commaToken = prevNodeOrToken.AsToken(); // whitespace2.LeadingWhitespace = commaToken.TrailingTrivia.ToString(); // } //} }
// Not sure if this belongs here or in BuildSyntaxHelpers public TypeSyntax TypeSyntaxFromType(IReferencedType type) { // Type syntax is realy ugly to build, so I build it and then hack hte type arg whitespace var typeName = CleanName(type); if (type.TypeArguments.Any()) { typeName += "<"; foreach (var tArg in type.TypeArguments) { var display = BuildSyntax(tArg).FirstOrDefault().ToFullString(); typeName += display; typeName += (tArg == type.TypeArguments.Last() ? "" : ", "); //typeName += tArg.QualifiedName + // (tArg == type.TypeArguments.Last() // ? "" // : ", "); } typeName += ">"; } if (type.IsArray) { typeName += "[]"; } var node = SyntaxFactory.ParseTypeName(typeName); var typeArgNode = node.ChildNodes().OfType <TypeArgumentListSyntax>().FirstOrDefault(); if (typeArgNode != null) { var newStartToken = BuildSyntaxHelpers.AttachWhitespaceToToken(typeArgNode.LessThanToken, type.Whitespace2Set[LanguageElement.TypeParameterStartDelimiter]); var newEndToken = BuildSyntaxHelpers.AttachWhitespaceToToken(typeArgNode.GreaterThanToken, type.Whitespace2Set[LanguageElement.TypeParameterEndDelimiter]); var newTypeArgNode = typeArgNode.WithLessThanToken(newStartToken).WithGreaterThanToken(newEndToken); //var newTypeArgNode = typeArgNode.WithLessThanToken(newStartToken); node = node.ReplaceNode(typeArgNode, newTypeArgNode); } return(node); }
private static List <string> GetNamespaceToDrop(IReferencedType type) { IDom context = type; var list = new List <string>(); while (context != null) { var contextAsStemContainer = context as IStemContainer; if (contextAsStemContainer != null) { var asNamespace = context as INamespace; if (asNamespace != null) { list.AddRange(GetNamespaceSubParts(asNamespace.Name)); } list.AddRange(contextAsStemContainer.UsingDirectives.Select(x => x.Name)); } context = context.Parent; } return(list); }
//private static string RemoveUsingPrefixes(IReferencedType type, string qualifiedName) //{ // // C# does not support partial namespace usings right now // var nsName = qualifiedName.SubstringBeforeLast("."); // if (string.IsNullOrWhiteSpace(nsName)) { return qualifiedName; } // var typeName = qualifiedName.SubstringAfterLast("."); // IDom context = type; // var list = new List<IUsingDirective>(); // while (context != null) // { // var contextAsStemContainer = context as IStemContainer; // if (contextAsStemContainer != null) // { list.AddRange(contextAsStemContainer.UsingDirectives); } // context = context.Parent; // } // foreach (var usingDirective in list) // { // if (usingDirective.Name == nsName) // { return typeName; } // } // return qualifiedName; //} private static string RemoveUsingPrefixes(IReferencedType type, string qualifiedName) { // C# does not support partial namespace usings right now var nsName = qualifiedName.SubstringBeforeLast("."); if (string.IsNullOrWhiteSpace(nsName)) { return(qualifiedName); } var typeName = qualifiedName.SubstringAfterLast("."); var list = GetNamespaceToDrop(type); foreach (var usingName in list) { if (usingName == nsName) { return(typeName); } } return(qualifiedName); }
public TypeSyntax GetVariableTypeSyntax(bool isImplicitlyTyped, IReferencedType type) { TypeSyntax typeSyntax; if (isImplicitlyTyped) { typeSyntax = SyntaxFactory.ParseTypeName("var"); typeSyntax = BuildSyntaxHelpers.AttachWhitespaceToFirstAndLast(typeSyntax, type.Whitespace2Set.First()); } else { typeSyntax = (TypeSyntax)RDom.CSharp.GetSyntaxGroup(type).First(); } return typeSyntax; //if (itemAsVariable.IsImplicitlyTyped) //{ return SyntaxFactory.IdentifierName("var"); } //var type = itemAsVariable.Type; //if (itemAsVariable.IsAliased) //{ // var typeName = Mappings.AliasFromSystemType(type.Name); // return SyntaxFactory.IdentifierName(typeName); //} //return (TypeSyntax)(RDomCSharp.Factory.BuildSyntax(type)); }
protected RDomBaseVariable(string name, IReferencedType type, IExpression initializer, bool isImplicitlyTyped, bool isAliased, VariableKind variableKind) : this(name, initializer, isImplicitlyTyped, isAliased, variableKind) { _type = type; }
public RDomClass(string metadataName, IReferencedType baseType, AccessModifier declaredAccessModifier = AccessModifier.Private, bool isAbstract = false, bool isSealed = false, bool isStatic = false, bool isPartial = false) : this(metadataName, declaredAccessModifier, isAbstract, isSealed, isStatic, isPartial) { _baseType = baseType; }
public RDomVariableDeclaration( string name, IReferencedType type, IExpression initializer = null, bool isImplicitlyTyped = false, bool isAliased = false, VariableKind variableKind = VariableKind.Local) : base(name, type, initializer, isImplicitlyTyped, isAliased, variableKind) { }
public RDomConversionOperator(string name, IReferencedType type, bool isImplicit) : this(name, isImplicit) { _type = type; }
public RDomParameter(string name, IReferencedType type, int ordinal = 0, bool isOut = false, bool isRef = false, bool isParamArray = false) : this(name, type, null, LiteralKind.Unknown, null, ordinal, isOut, isRef, isParamArray) { }
public RDomEnum(string name, string metadataName, IReferencedType underlyingType, AccessModifier declaredAccessModifier = AccessModifier.Private) : this(name, metadataName, declaredAccessModifier) { _underlyingType = underlyingType; }
public RDomDeclarationStatement(string name, IReferencedType type, IExpression initializer = null, bool isImplicitlyTyped = false, bool isAliased = false, bool isConst = false, VariableKind variableKind = VariableKind.Local) : base(name, type, initializer, isImplicitlyTyped, isAliased, variableKind) { _isConst = IsConst; }
public RDomOperator(string name, IReferencedType type, Operator op) : this(name, op) { _type = type; }
private object GetDefaultValue(IReferencedType propertyType) { if (propertyType.Name == "Boolean") return false; if (propertyType.Name == "String") return null; if (propertyType.Name == "AccessModifier") return AccessModifier.Private; if (propertyType.Name == "IStructuredDocumentation") return null; if (propertyType.Name == "Boolean") return false; if (propertyType.Name == "Int32") return false; if (propertyType.Name == "Variance") return Variance.None; if (propertyType.Name == "LiteralKind") return LiteralKind.Unknown; if (propertyType.Name == "Type") return null; if (propertyType.Name == "AssignmentOperator") return AssignmentOperator.Equals; if (propertyType.Name == "ConstructorInitializerType") return ConstructorInitializerType.None; if (propertyType.Name == "IExpression") return null; // TODO: FIgure out how to specify default as that is all you can do with Guid if (propertyType.Name == "Boolean") return false; if (propertyType.Name == "IReferencedType") return false; // force an error if (propertyType.Name == "IVariableDeclaration") return false; // force an error if (propertyType.Name == "VariableKind") return false; // force an error if (propertyType.Name == "ExpressionType") return false; // force an error if (propertyType.Name == "Operator") return false; // force an error if (propertyType.Name == "INamedTypeSymbol") return false; // force an error return false; // force an error }
public RDomCatchStatement(IReferencedType exceptionType = null, IVariableDeclaration variable = null, IExpression condition = null) : this(variable, condition) { _exceptionType = exceptionType; }
private object GetDefaultValue(IReferencedType propertyType) { if (propertyType.Name == "Boolean") { return(false); } if (propertyType.Name == "String") { return(null); } if (propertyType.Name == "AccessModifier") { return(AccessModifier.Private); } if (propertyType.Name == "IStructuredDocumentation") { return(null); } if (propertyType.Name == "Boolean") { return(false); } if (propertyType.Name == "Int32") { return(false); } if (propertyType.Name == "Variance") { return(Variance.None); } if (propertyType.Name == "LiteralKind") { return(LiteralKind.Unknown); } if (propertyType.Name == "Type") { return(null); } if (propertyType.Name == "AssignmentOperator") { return(AssignmentOperator.Equals); } if (propertyType.Name == "ConstructorInitializerType") { return(ConstructorInitializerType.None); } if (propertyType.Name == "IExpression") { return(null); } // TODO: FIgure out how to specify default as that is all you can do with Guid if (propertyType.Name == "Boolean") { return(false); } if (propertyType.Name == "IReferencedType") { return(false); // force an error } if (propertyType.Name == "IVariableDeclaration") { return(false); // force an error } if (propertyType.Name == "VariableKind") { return(false); // force an error } if (propertyType.Name == "ExpressionType") { return(false); // force an error } if (propertyType.Name == "Operator") { return(false); // force an error } if (propertyType.Name == "INamedTypeSymbol") { return(false); // force an error } return(false); // force an error }