/// <summary> /// Checks a type definition to see if it inherits a target interface. /// </summary> /// <param name="source">Type to check for inheritance </param> /// <param name="interfaceName">The name of the interface</param> /// <param name="interfaceNamespace">Optional parameter that contains the target namespace for the interface.</param> /// <returns>True if inherited or false if not.</returns> public static bool InheritsInterface(this CsType source, string interfaceName, string interfaceNamespace = null) { if (source == null) { return(false); } if (!source.IsLoaded) { return(false); } if (!source.IsClass & !source.IsStructure) { return(false); } CsContainer containerData = source.IsClass ? source.GetClassModel() as CsContainer : source.GetStructureModel() as CsContainer; if (containerData == null) { return(false); } if (!containerData.IsLoaded) { return(false); } if (!containerData.InheritedInterfaces.Any()) { return(false); } var interfaceData = interfaceNamespace == null ? containerData.InheritedInterfaces.FirstOrDefault(i => interfaceName == i.Name) : containerData.InheritedInterfaces.FirstOrDefault(i => (interfaceNamespace == i.Namespace & interfaceName == i.Name)); return(interfaceData != null); }
/// <summary> /// Flag that determines if the type has a base class that is inherited by the type. /// </summary> /// <param name="source">The target type to check for base class implementation.</param> /// <param name="baseClassName">The name of the base class that is inherited.</param> /// <param name="baseClassNamespace">Optional parameter for the namespace of the base class.</param> /// <returns>True if inherited or false if not found.</returns> public static bool InheritsBaseClass(this CsType source, string baseClassName, string baseClassNamespace = null) { if (source == null) { return(false); } if (!source.IsLoaded) { return(false); } if (!source.IsClass) { return(false); } var classData = source.GetClassModel(); if (classData == null) { return(false); } return(classData.InheritsBaseClass(baseClassName, baseClassNamespace)); }
/// <summary> /// Extension method that creates the array portion definition of a type definition in C# syntax. /// </summary> /// <param name="source">The source type to get the array information to format.</param> /// <returns>The formatted array syntax for the target type, or null if no array data was provided in the type definition.</returns> public static string FormatCSharpArraySignatureSyntax(this CsType source) { var dotNetType = source as IDotNetType; return(dotNetType.FormatCSharpArraySignatureSyntax()); }
/// <summary> /// Extension method that generates the fully qualified type name from the <see cref="ICsType"/> model in the C# format. /// </summary> /// <param name="source">The source type to get the full type name from.</param> /// <returns>The fully qualified namespace and full type definition. Null if the type is missing or not loaded. </returns> public static string FormatCSharpFullTypeName(this CsType source) { var dotNetType = source as IDotNetType; return(dotNetType.FormatCSharpFullTypeName()); }
/// <summary> /// Extension method that returns a value declaration in the c# language format. /// </summary> /// <param name="source">The target type to create the value definition for.</param> /// <param name="value">The value to be formatted.</param> /// <returns>The definition of the value formatted for C#</returns> public static string FormatCSharpValueSyntax(this CsType source, string value) { var dotNetType = source as IDotNetType; return(dotNetType.FormatCSharpValueSyntax(value)); }
/// <summary> /// Extension method that generates the default value syntax for a parameter in the C# language. /// </summary> /// <param name="source">The target default value to format.</param> /// <param name="type">The target type of the value to be formatted.</param> /// <returns>The fully formatted syntax for the default value or null if data was missing.</returns> public static string FormatCSharpParameterDefaultValueSyntax(this CsParameterDefaultValue source, CsType type) { var dotNetParameterDefaultValue = source as IDotNetParameterDefaultValue; var dotNetType = type as IDotNetType; return(dotNetParameterDefaultValue.FormatCSharpParameterDefaultValueSyntax(dotNetType)); }
/// <summary> /// Constructor for the <see cref="CsParameter"/> /// </summary> /// <param name="isLoaded">Flag that determines if the model was loaded.</param> /// <param name="hasErrors">Flag that determine if errors were found creating the model.</param> /// <param name="loadedFromSource">Flag that determines if the model was loaded from source code or from an existing library.</param> /// <param name="language">The target language the model was generated from.</param> /// <param name="defaultValue">The default value assigned to this parameter.</param> /// <param name="sourceDocument">The source document that was used to build this model. This is optional parameter and can be null.</param> /// <param name="modelStore">Optional the lookup storage for models created during the compile or lookup of the model.</param> /// <param name="modelErrors">Optional the error that occured while creating the model.</param> /// <param name="attributes">Attributes assigned to this model.</param> /// <param name="lookupPath">The fully qualified path of the model that is stored in the model store.</param> /// <param name="name">The name of the parameter.</param> /// <param name="isOut">Parameter is assigned the out keyword.</param> /// <param name="isRef">Parameter is assigned the ref keyword.</param> /// <param name="isParams">Parameter supports a parameter array.</param> /// <param name="isOptional">Parameter is optional.</param> /// <param name="isGenericParameter">Is a generic parameter.</param> /// <param name="hasDefaultValue">Parameter has an assigned default value.</param> /// <param name="parentPath">The fully qualified path name for the parent model to this model.</param> /// <param name="parameterType">The type that this parameter supports.</param> protected CsParameter(bool isLoaded, bool hasErrors, bool loadedFromSource, SourceCodeType language, IReadOnlyList <CsAttribute> attributes, string lookupPath, string name, bool isOut, bool isRef, bool isParams, bool isOptional, bool isGenericParameter, bool hasDefaultValue, string parentPath, CsType parameterType, CsParameterDefaultValue defaultValue, string sourceDocument = null, ModelStore <ICsModel> modelStore = null, IReadOnlyList <ModelLoadException> modelErrors = null) : base(isLoaded, hasErrors, loadedFromSource, language, CsModelType.Parameter, sourceDocument, modelStore, modelErrors) { _attributes = attributes ?? ImmutableList <CsAttribute> .Empty; _lookupPath = lookupPath; _name = name; _isOut = isOut; _isRef = isRef; _isParams = isParams; _isOptional = isOptional; _isGenericParameter = isGenericParameter; _hasDefaultValue = hasDefaultValue; _parentPath = parentPath; _parameterType = parameterType; _defaultValue = defaultValue; }
/// <summary> /// Constructor for the <see cref="CsMethod"/> /// </summary> /// <param name="isLoaded">Flag that determines if the model was loaded.</param> /// <param name="hasErrors">Flag that determine if errors were found creating the model.</param> /// <param name="loadedFromSource">Flag that determines if the model was loaded from source code or from an existing library.</param> /// <param name="language">The target language the model was generated from.</param> /// <param name="parameters">The parameters assigned to the method.</param> /// <param name="sourceDocument">The source document that was used to build this model. This is optional parameter and can be null.</param> /// <param name="modelStore">Optional the lookup storage for models created during the compile or lookup of the model.</param> /// <param name="modelErrors">Optional the error that occured while creating the model.</param> /// <param name="attributes">List of the attributes assigned to this model.</param> /// <param name="sourceFiles">List of the fully qualified paths to the source code files this member is defined in.</param> /// <param name="hasDocumentation">Flag that determines if the model has XML documentation assigned to it.</param> /// <param name="documentation">The xml documentation assigned to the model.</param> /// <param name="lookupPath">The fully qualified model lookup path for this model.</param> /// <param name="name">The name of the model.</param> /// <param name="parentPath">THe fully qualified lookup path for the parent model to this one.</param> /// <param name="security">The security scope assigned to this model.</param> /// <param name="isGeneric">Flag that determines if the method is a generic definition.</param> /// <param name="hasStrongTypesInGenerics">Flag that determines if the generics use strong type definitions.</param> /// <param name="genericParameters">Generic parameters assigned to the method.</param> /// <param name="genericTypes">Target types for the generic parameters assigned to the method.</param> /// <param name="hasParameters">Flag that determines if the method had parameters.</param> /// <param name="isAbstract">Flag that determines if the model is abstract.</param> /// <param name="isVirtual">Flag that determines if the model is virtual.</param> /// <param name="isSealed">Flag that determines if the model is sealed.</param> /// <param name="isOverride">Flag that determines if the model is overridden.</param> /// <param name="isStatic">Flag that determines if the model is static.</param> /// <param name="isVoid">Flag that determines if the return type is void. </param> /// <param name="isAsync">Flag that determines if the method has the async keyword assigned.</param> /// <param name="isExtension">Flag that determines if the method is an extension method.</param> /// <param name="methodType">The type of method that was implemented.</param> /// <param name="returnType">The type definition for the return type.</param> protected CsMethod(bool isLoaded, bool hasErrors, bool loadedFromSource, SourceCodeType language, IReadOnlyList <CsAttribute> attributes, IReadOnlyList <string> sourceFiles, bool hasDocumentation, string documentation, string lookupPath, string name, string parentPath, CsSecurity security, bool isGeneric, bool hasStrongTypesInGenerics, IReadOnlyList <CsGenericParameter> genericParameters, IReadOnlyList <CsType> genericTypes, bool hasParameters, bool isAbstract, bool isVirtual, bool isSealed, bool isOverride, bool isStatic, bool isVoid, bool isAsync, bool isExtension, CsMethodType methodType, CsType returnType, IReadOnlyList <CsParameter> parameters, string sourceDocument = null, ModelStore <ICsModel> modelStore = null, IReadOnlyList <ModelLoadException> modelErrors = null) : base(isLoaded, hasErrors, loadedFromSource, language, CsModelType.Method, attributes, sourceFiles, hasDocumentation, documentation, lookupPath, name, parentPath, security, CsMemberType.Method, sourceDocument, modelStore, modelErrors) { _isGeneric = isGeneric; _hasStrongTypesInGenerics = hasStrongTypesInGenerics; _genericParameters = genericParameters ?? ImmutableList <CsGenericParameter> .Empty; _genericTypes = genericTypes ?? ImmutableList <CsType> .Empty; _hasParameters = hasParameters; _isAbstract = isAbstract; _isVirtual = isVirtual; _isSealed = isSealed; _isOverride = isOverride; _isStatic = isStatic; _isVoid = isVoid; _isAsync = isAsync; _isExtension = isExtension; _methodType = methodType; _returnType = returnType; _parameters = parameters ?? ImmutableList <CsParameter> .Empty; }
/// <summary> /// Constructor for the <see cref="CsGenericParameter"/> /// </summary> /// <param name="isLoaded">Flag that determines if the model was loaded.</param> /// <param name="hasErrors">Flag that determine if errors were found creating the model.</param> /// <param name="loadedFromSource">Flag that determines if the model was loaded from source code or from an existing library.</param> /// <param name="language">The target language the model was generated from.</param> /// <param name="modelType">The type of code model created.</param> /// <param name="hasOutKeyword">Flag that determines if parameter has out keyword assigned.</param> /// <param name="hasNewConstraint">Flag that determines if generic parameter supports new keyword.</param> /// <param name="hasClassConstraint">flag that determines if the generic parameter has a constraint requirement to classes.</param> /// <param name="hasStructConstraint">Flag that determines if the generic parameter has a constraint requirement to structures.</param> /// <param name="hasConstraintTypes">Flag that determines if the generic parameter has additional type constraints.</param> /// <param name="constrainingTypes">List of of additional constraints the generic parameter supports.</param> /// <param name="type">The type definition for the generic type</param> /// <param name="sourceDocument">The source document that was used to build this model. This is optional parameter and can be null.</param> /// <param name="modelStore">Optional the lookup storage for models created during the compile or lookup of the model.</param> /// <param name="modelErrors">Optional the error that occured while creating the model.</param> protected CsGenericParameter(bool isLoaded, bool hasErrors, bool loadedFromSource, SourceCodeType language, CsModelType modelType, bool hasOutKeyword, bool hasNewConstraint, bool hasClassConstraint, bool hasStructConstraint, bool hasConstraintTypes, IReadOnlyList <CsType> constrainingTypes, CsType type, string sourceDocument = null, ModelStore <ICsModel> modelStore = null, IReadOnlyList <ModelLoadException> modelErrors = null) : base(isLoaded, hasErrors, loadedFromSource, language, modelType, sourceDocument, modelStore, modelErrors) { _hasOutKeyword = hasOutKeyword; _hasNewConstraint = hasNewConstraint; _hasClassConstraint = hasClassConstraint; _hasStructConstraint = hasStructConstraint; _hasConstraintTypes = hasConstraintTypes; _constrainingTypes = constrainingTypes ?? ImmutableList <CsType> .Empty; _type = type; }
/// <summary> /// Constructor for the <see cref="CsAttributeParameterValue"/> /// </summary> /// <param name="isLoaded">Flag that determines if the model was loaded.</param> /// <param name="hasErrors">Flag that determine if errors were found creating the model.</param> /// <param name="loadedFromSource">Flag that determines if the model was loaded from source code or from an existing library.</param> /// <param name="language">The target language the model was generated from.</param> /// <param name="values">The list of values if the parameter has more then one value.</param> /// <param name="sourceDocument">The source document that was used to build this model. This is optional parameter and can be null.</param> /// <param name="modelStore">Optional the lookup storage for models created during the compile or lookup of the model.</param> /// <param name="modelErrors">Optional the error that occured while creating the model.</param> /// <param name="parameterKind">The kind of attribute parameter.</param> /// <param name="value">The value of the attribute parameter.</param> /// <param name="enumValue">The value of the enumeration if the parameter is an enumeration.</param> /// <param name="typeValue">The type if the parameter is a single value.</param> protected CsAttributeParameterValue(bool isLoaded, bool hasErrors, bool loadedFromSource, SourceCodeType language, AttributeParameterKind parameterKind, string value, string enumValue, CsType typeValue, IReadOnlyList <CsAttributeParameterValue> values, string sourceDocument = null, ModelStore <ICsModel> modelStore = null, IReadOnlyList <ModelLoadException> modelErrors = null) : base(isLoaded, hasErrors, loadedFromSource, language, CsModelType.AttributeParameterValue, sourceDocument, modelStore, modelErrors) { _parameterKind = parameterKind; _value = value; _enumValue = enumValue; _typeValue = typeValue; _values = values ?? ImmutableList <CsAttributeParameterValue> .Empty; }