diff --git a/Reinforced.Typings/AccessModifier.cs b/Reinforced.Typings/AccessModifier.cs index 4892eb64..8efe4f61 100644 --- a/Reinforced.Typings/AccessModifier.cs +++ b/Reinforced.Typings/AccessModifier.cs @@ -1,27 +1,23 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace Reinforced.Typings +namespace Reinforced.Typings { /// - /// Represents member's access modifier + /// Represents member's access modifier /// public enum AccessModifier { /// - /// private + /// private /// Private, + /// - /// protected + /// protected /// Protected, + /// - /// public + /// public /// Public } -} +} \ No newline at end of file diff --git a/Reinforced.Typings/Attributes/IAutoexportSwitchAttribute.cs b/Reinforced.Typings/Attributes/IAutoexportSwitchAttribute.cs index 5daca0af..c5b82b00 100644 --- a/Reinforced.Typings/Attributes/IAutoexportSwitchAttribute.cs +++ b/Reinforced.Typings/Attributes/IAutoexportSwitchAttribute.cs @@ -3,33 +3,33 @@ namespace Reinforced.Typings.Attributes { /// - /// Interface containing base properties for some attributes + /// Interface containing base properties for some attributes /// public interface IAutoexportSwitchAttribute { /// - /// When true, code for all methods will be automatically generated + /// When true, code for all methods will be automatically generated /// bool AutoExportMethods { get; set; } /// - /// When true, code for all properties will be automatically generated + /// When true, code for all properties will be automatically generated /// bool AutoExportProperties { get; set; } /// - /// When true, code for all fields will be automatically generated + /// When true, code for all fields will be automatically generated /// bool AutoExportFields { get; } - + /// - /// Reference to code geenrator which will be applied to every method + /// Reference to code geenrator which will be applied to every method /// Type DefaultMethodCodeGenerator { get; } /// - /// When true, code for all constructors will be automatically generated + /// When true, code for all constructors will be automatically generated /// bool AutoExportConstructors { get; } } -} +} \ No newline at end of file diff --git a/Reinforced.Typings/Attributes/INameOverrideAttribute.cs b/Reinforced.Typings/Attributes/INameOverrideAttribute.cs index 553cd7c2..649632ab 100644 --- a/Reinforced.Typings/Attributes/INameOverrideAttribute.cs +++ b/Reinforced.Typings/Attributes/INameOverrideAttribute.cs @@ -1,30 +1,24 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace Reinforced.Typings.Attributes +namespace Reinforced.Typings.Attributes { /// - /// Configuration interface for members supporting names overriding + /// Configuration interface for members supporting names overriding /// public interface INameOverrideAttribute { /// - /// Name override + /// Name override /// string Name { get; set; } } /// - /// Configuration interface for members supporting camelCasing from attribute + /// Configuration interface for members supporting camelCasing from attribute /// public interface ICamelCaseableAttribute { /// - /// camelCase flag + /// camelCase flag /// bool ShouldBeCamelCased { get; set; } } -} +} \ No newline at end of file diff --git a/Reinforced.Typings/Attributes/TsAddTypeReference.cs b/Reinforced.Typings/Attributes/TsAddTypeReference.cs index 466e4b05..6ce6ad5d 100644 --- a/Reinforced.Typings/Attributes/TsAddTypeReference.cs +++ b/Reinforced.Typings/Attributes/TsAddTypeReference.cs @@ -1,30 +1,16 @@ using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace Reinforced.Typings.Attributes { - /// - /// This attribute is used to add reference directive to file containing single TS class typing. - /// It is only used while splitting generated type sto different files + /// This attribute is used to add reference directive to file containing single TS class typing. + /// It is only used while splitting generated type sto different files /// + [AttributeUsage(AttributeTargets.Class | AttributeTargets.Interface | AttributeTargets.Enum, AllowMultiple = true)] public class TsAddTypeReferenceAttribute : Attribute { /// - /// Type that should be referenced - /// - public Type Type { get; set; } - - /// - /// Raw reference path that will be added to target file - /// - public string RawPath { get; set; } - - /// - /// Constructs new instance of TsAddTypeReferenceAttribute using referenced type + /// Constructs new instance of TsAddTypeReferenceAttribute using referenced type /// /// Type reference public TsAddTypeReferenceAttribute(Type type) @@ -33,12 +19,22 @@ public TsAddTypeReferenceAttribute(Type type) } /// - /// Constructs new instance of TsAddTypeReferenceAttribute using referenced type + /// Constructs new instance of TsAddTypeReferenceAttribute using referenced type /// /// Raw reference public TsAddTypeReferenceAttribute(string rawPath) { RawPath = rawPath; } + + /// + /// Type that should be referenced + /// + public Type Type { get; set; } + + /// + /// Raw reference path that will be added to target file + /// + public string RawPath { get; set; } } -} +} \ No newline at end of file diff --git a/Reinforced.Typings/Attributes/TsAttributeBase.cs b/Reinforced.Typings/Attributes/TsAttributeBase.cs index 73b3bd09..759dd9ff 100644 --- a/Reinforced.Typings/Attributes/TsAttributeBase.cs +++ b/Reinforced.Typings/Attributes/TsAttributeBase.cs @@ -3,14 +3,14 @@ namespace Reinforced.Typings.Attributes { /// - /// Base for all attributes + /// Base for all attributes /// public abstract class TsAttributeBase : Attribute { /// - /// Dummy function body generator - /// If empty then it's being generated empty/return null body. + /// Dummy function body generator + /// If empty then it's being generated empty/return null body. /// public virtual Type CodeGeneratorType { get; set; } } -} +} \ No newline at end of file diff --git a/Reinforced.Typings/Attributes/TsBaseParamAttribute.cs b/Reinforced.Typings/Attributes/TsBaseParamAttribute.cs index a87aa90e..22659b76 100644 --- a/Reinforced.Typings/Attributes/TsBaseParamAttribute.cs +++ b/Reinforced.Typings/Attributes/TsBaseParamAttribute.cs @@ -1,32 +1,28 @@ using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace Reinforced.Typings.Attributes { /// - /// Denotes parameter name and constant value for constructor's :base call - /// We need this attribute because it is programmatically impossible to determine :base call parameters - /// via reflection. So in this case we need some help from user's side + /// Denotes parameter name and constant value for constructor's :base call + /// We need this attribute because it is programmatically impossible to determine :base call parameters + /// via reflection. So in this case we need some help from user's side /// [AttributeUsage(AttributeTargets.Constructor)] public class TsBaseParamAttribute : Attribute { /// - /// Parameters for super() call - /// Here should be stored TypeScript expressions - /// - public string[] Values { get; set; } - - /// - /// Creates instance of TsBaseParamAttribute + /// Creates instance of TsBaseParamAttribute /// /// Set of TypeScript expressions to be supplied for super() call public TsBaseParamAttribute(params string[] values) { Values = values; } + + /// + /// Parameters for super() call + /// Here should be stored TypeScript expressions + /// + public string[] Values { get; set; } } -} +} \ No newline at end of file diff --git a/Reinforced.Typings/Attributes/TsClassAttribute.cs b/Reinforced.Typings/Attributes/TsClassAttribute.cs index 9f83964f..8122c0cc 100644 --- a/Reinforced.Typings/Attributes/TsClassAttribute.cs +++ b/Reinforced.Typings/Attributes/TsClassAttribute.cs @@ -3,45 +3,45 @@ namespace Reinforced.Typings.Attributes { /// - /// This attribute will export member as typescript class definition + /// This attribute will export member as typescript class definition /// [AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct)] public class TsClassAttribute : TsDeclarationAttributeBase, IAutoexportSwitchAttribute { /// - /// Export all methods automatically or not. + /// Constructs new instance of TsClassAttribute + /// + public TsClassAttribute() + { + AutoExportProperties = true; + AutoExportMethods = true; + IncludeNamespace = true; + AutoExportConstructors = false; + } + + /// + /// Export all methods automatically or not. /// public virtual bool AutoExportMethods { get; set; } /// - /// Export all properties automatically or not. + /// Export all properties automatically or not. /// public virtual bool AutoExportProperties { get; set; } /// - /// Export all fields automatically or not. + /// Export all fields automatically or not. /// public virtual bool AutoExportFields { get; set; } /// - /// Reference to code geenrator which will be applied to every method + /// Reference to code geenrator which will be applied to every method /// public virtual Type DefaultMethodCodeGenerator { get; set; } /// - /// When true, code for all constructors will be automatically generated + /// When true, code for all constructors will be automatically generated /// public bool AutoExportConstructors { get; set; } - - /// - /// Constructs new instance of TsClassAttribute - /// - public TsClassAttribute() - { - AutoExportProperties = true; - AutoExportMethods = true; - IncludeNamespace = true; - AutoExportConstructors = false; - } } -} +} \ No newline at end of file diff --git a/Reinforced.Typings/Attributes/TsDeclarationAttributeBase.cs b/Reinforced.Typings/Attributes/TsDeclarationAttributeBase.cs index b9f8cc10..be62fb26 100644 --- a/Reinforced.Typings/Attributes/TsDeclarationAttributeBase.cs +++ b/Reinforced.Typings/Attributes/TsDeclarationAttributeBase.cs @@ -1,31 +1,31 @@ namespace Reinforced.Typings.Attributes { /// - /// Base attribute for so-called compilation unit (class, enum, interface etc) + /// Base attribute for so-called compilation unit (class, enum, interface etc) /// public abstract class TsDeclarationAttributeBase : TsAttributeBase, INameOverrideAttribute { /// - /// Place to corresponding namespace + /// Constructs new instance of TsDeclarationAttributeBase /// - public virtual bool IncludeNamespace { get; set; } + protected TsDeclarationAttributeBase() + { + IncludeNamespace = true; + } /// - /// Overrides name + /// Place to corresponding namespace /// - public virtual string Name { get; set; } + public virtual bool IncludeNamespace { get; set; } /// - /// Overrides namespace + /// Overrides namespace /// public virtual string Namespace { get; set; } /// - /// Constructs new instance of TsDeclarationAttributeBase + /// Overrides name /// - protected TsDeclarationAttributeBase() - { - IncludeNamespace = true; - } + public virtual string Name { get; set; } } -} +} \ No newline at end of file diff --git a/Reinforced.Typings/Attributes/TsEnumAttribute.cs b/Reinforced.Typings/Attributes/TsEnumAttribute.cs index cde6b716..615fa373 100644 --- a/Reinforced.Typings/Attributes/TsEnumAttribute.cs +++ b/Reinforced.Typings/Attributes/TsEnumAttribute.cs @@ -3,11 +3,10 @@ namespace Reinforced.Typings.Attributes { /// - /// Exports enum as TypeScript Enum + /// Exports enum as TypeScript Enum /// [AttributeUsage(AttributeTargets.Enum)] public class TsEnumAttribute : TsDeclarationAttributeBase { - } -} +} \ No newline at end of file diff --git a/Reinforced.Typings/Attributes/TsFile.cs b/Reinforced.Typings/Attributes/TsFile.cs new file mode 100644 index 00000000..012c9d96 --- /dev/null +++ b/Reinforced.Typings/Attributes/TsFile.cs @@ -0,0 +1,26 @@ +using System; + +namespace Reinforced.Typings.Attributes +{ + /// + /// Specifies file where to put generated code for type. + /// This attribute is being ignored when RtDivideTypesAmongFiles is false. + /// + [AttributeUsage(AttributeTargets.Class | AttributeTargets.Interface | AttributeTargets.Enum)] + public class TsFile : Attribute + { + /// + /// Constructs new TsFile attribute + /// + /// File name (related to RtTargetDirectory) where to put generated code + public TsFile(string fileName) + { + FileName = fileName; + } + + /// + /// File name (related to RtTargetDirectory) where to put generated code + /// + public string FileName { get; set; } + } +} \ No newline at end of file diff --git a/Reinforced.Typings/Attributes/TsFunctionAttribute.cs b/Reinforced.Typings/Attributes/TsFunctionAttribute.cs index 1188285e..9f220fc8 100644 --- a/Reinforced.Typings/Attributes/TsFunctionAttribute.cs +++ b/Reinforced.Typings/Attributes/TsFunctionAttribute.cs @@ -3,11 +3,10 @@ namespace Reinforced.Typings.Attributes { /// - /// Overrides function export + /// Overrides function export /// [AttributeUsage(AttributeTargets.Method)] public class TsFunctionAttribute : TsTypedMemberAttributeBase { - } -} +} \ No newline at end of file diff --git a/Reinforced.Typings/Attributes/TsGenericAttribute.cs b/Reinforced.Typings/Attributes/TsGenericAttribute.cs index 9a466e04..a7950516 100644 --- a/Reinforced.Typings/Attributes/TsGenericAttribute.cs +++ b/Reinforced.Typings/Attributes/TsGenericAttribute.cs @@ -3,13 +3,13 @@ namespace Reinforced.Typings.Attributes { /// - /// Denotes type for generic attribute + /// Denotes type for generic attribute /// [AttributeUsage(AttributeTargets.GenericParameter)] public class TsGenericAttribute : TsTypedAttributeBase { /// - /// Constructs new instance of TsGenericAttribute + /// Constructs new instance of TsGenericAttribute /// /// Raw TypeScript type name public TsGenericAttribute(string type) @@ -18,7 +18,7 @@ public TsGenericAttribute(string type) } /// - /// Constructs new instance of TsGenericAttribute + /// Constructs new instance of TsGenericAttribute /// /// Type to be resolved to TypeScript name during export public TsGenericAttribute(Type strongType) @@ -26,4 +26,4 @@ public TsGenericAttribute(Type strongType) StrongType = strongType; } } -} +} \ No newline at end of file diff --git a/Reinforced.Typings/Attributes/TsIgnoreAttribute.cs b/Reinforced.Typings/Attributes/TsIgnoreAttribute.cs index b08cb411..9d829292 100644 --- a/Reinforced.Typings/Attributes/TsIgnoreAttribute.cs +++ b/Reinforced.Typings/Attributes/TsIgnoreAttribute.cs @@ -3,10 +3,12 @@ namespace Reinforced.Typings.Attributes { /// - /// Instructs DynTyping do not to export mentioned member + /// Instructs DynTyping do not to export mentioned member /// - [AttributeUsage(AttributeTargets.Property|AttributeTargets.Field|AttributeTargets.Method|AttributeTargets.Parameter|AttributeTargets.Constructor)] + [AttributeUsage( + AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Method | AttributeTargets.Parameter | + AttributeTargets.Constructor)] public class TsIgnoreAttribute : Attribute { } -} +} \ No newline at end of file diff --git a/Reinforced.Typings/Attributes/TsInterfaceAttribute.cs b/Reinforced.Typings/Attributes/TsInterfaceAttribute.cs index 0ead6da5..8cef4bab 100644 --- a/Reinforced.Typings/Attributes/TsInterfaceAttribute.cs +++ b/Reinforced.Typings/Attributes/TsInterfaceAttribute.cs @@ -3,23 +3,34 @@ namespace Reinforced.Typings.Attributes { /// - /// Exports specified class or interface as typescript interface + /// Exports specified class or interface as typescript interface /// [AttributeUsage(AttributeTargets.Class | AttributeTargets.Interface | AttributeTargets.Struct)] public class TsInterfaceAttribute : TsDeclarationAttributeBase, IAutoexportSwitchAttribute { /// - /// Automatically appends I prefix if non-interfaces + /// Constructs new instance of TsInterfaceAttribute + /// + public TsInterfaceAttribute() + { + AutoI = true; + IncludeNamespace = true; + AutoExportMethods = true; + AutoExportProperties = true; + } + + /// + /// Automatically appends I prefix if non-interfaces /// public virtual bool AutoI { get; set; } - + /// - /// Export all methods automatically or not. + /// Export all methods automatically or not. /// public virtual bool AutoExportMethods { get; set; } /// - /// Export all properties automatically or not. + /// Export all properties automatically or not. /// public virtual bool AutoExportProperties { get; set; } @@ -37,16 +48,5 @@ bool IAutoexportSwitchAttribute.AutoExportConstructors { get { return false; } } - - /// - /// Constructs new instance of TsInterfaceAttribute - /// - public TsInterfaceAttribute() - { - AutoI = true; - IncludeNamespace = true; - AutoExportMethods = true; - AutoExportProperties = true; - } } -} +} \ No newline at end of file diff --git a/Reinforced.Typings/Attributes/TsParameterAttribute.cs b/Reinforced.Typings/Attributes/TsParameterAttribute.cs index daa9fce3..d6e337b5 100644 --- a/Reinforced.Typings/Attributes/TsParameterAttribute.cs +++ b/Reinforced.Typings/Attributes/TsParameterAttribute.cs @@ -3,14 +3,14 @@ namespace Reinforced.Typings.Attributes { /// - /// Overrides settings for exporting parameters + /// Overrides settings for exporting parameters /// [AttributeUsage(AttributeTargets.Parameter)] public class TsParameterAttribute : TsTypedMemberAttributeBase { /// - /// Specifies default value + /// Specifies default value /// public virtual object DefaultValue { get; set; } } -} +} \ No newline at end of file diff --git a/Reinforced.Typings/Attributes/TsPropertyAttribute.cs b/Reinforced.Typings/Attributes/TsPropertyAttribute.cs index 435d758c..e7554b38 100644 --- a/Reinforced.Typings/Attributes/TsPropertyAttribute.cs +++ b/Reinforced.Typings/Attributes/TsPropertyAttribute.cs @@ -3,15 +3,14 @@ namespace Reinforced.Typings.Attributes { /// - /// Overrides property/field export settings + /// Overrides property/field export settings /// - [AttributeUsage(AttributeTargets.Property|AttributeTargets.Field)] + [AttributeUsage(AttributeTargets.Property | AttributeTargets.Field)] public class TsPropertyAttribute : TsTypedMemberAttributeBase { - /// - /// Forces property to be a nullable + /// Forces property to be a nullable /// public virtual bool ForceNullable { get; set; } } -} +} \ No newline at end of file diff --git a/Reinforced.Typings/Attributes/TsReferenceAttribute.cs b/Reinforced.Typings/Attributes/TsReferenceAttribute.cs index 4172d551..ace3f6da 100644 --- a/Reinforced.Typings/Attributes/TsReferenceAttribute.cs +++ b/Reinforced.Typings/Attributes/TsReferenceAttribute.cs @@ -3,23 +3,23 @@ namespace Reinforced.Typings.Attributes { /// - /// Specifies path of reference which required to be added to result .ts file + /// Specifies path of reference which required to be added to result .ts file /// - [AttributeUsage(AttributeTargets.Assembly,AllowMultiple = true)] + [AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)] public class TsReferenceAttribute : Attribute { /// - /// Path to referenced TS file - /// - public virtual string Path { get; private set; } - - /// - /// Constructs new instance of TsReferenceAttribute + /// Constructs new instance of TsReferenceAttribute /// /// Path that should be written as file to reference tag public TsReferenceAttribute(string path) { Path = path; } + + /// + /// Path to referenced TS file + /// + public virtual string Path { get; private set; } } -} +} \ No newline at end of file diff --git a/Reinforced.Typings/Attributes/TsTypedAttributeBase.cs b/Reinforced.Typings/Attributes/TsTypedAttributeBase.cs index a85cf5e7..41a50726 100644 --- a/Reinforced.Typings/Attributes/TsTypedAttributeBase.cs +++ b/Reinforced.Typings/Attributes/TsTypedAttributeBase.cs @@ -3,17 +3,17 @@ namespace Reinforced.Typings.Attributes { /// - /// Base attribute for typed members/parameters + /// Base attribute for typed members/parameters /// public abstract class TsTypedAttributeBase : TsAttributeBase { /// - /// Overrides member type + /// Overrides member type /// public virtual string Type { get; set; } /// - /// Overrides member type with managed type + /// Overrides member type with managed type /// public virtual Type StrongType { get; set; } } diff --git a/Reinforced.Typings/Attributes/TsTypedMemberAttributeBase.cs b/Reinforced.Typings/Attributes/TsTypedMemberAttributeBase.cs index 7bd80ab7..a027f704 100644 --- a/Reinforced.Typings/Attributes/TsTypedMemberAttributeBase.cs +++ b/Reinforced.Typings/Attributes/TsTypedMemberAttributeBase.cs @@ -1,23 +1,19 @@ -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace Reinforced.Typings.Attributes +namespace Reinforced.Typings.Attributes { /// - /// Base attribute for class members and method parameters + /// Base attribute for class members and method parameters /// - public abstract class TsTypedMemberAttributeBase : TsTypedAttributeBase, INameOverrideAttribute, ICamelCaseableAttribute + public abstract class TsTypedMemberAttributeBase : TsTypedAttributeBase, INameOverrideAttribute, + ICamelCaseableAttribute { /// - /// Overrides member name + /// When true them member name will be camelCased regardless configuration setting /// - public virtual string Name { get; set; } + public bool ShouldBeCamelCased { get; set; } /// - /// When true them member name will be camelCased regardless configuration setting + /// Overrides member name /// - public bool ShouldBeCamelCased { get; set; } + public virtual string Name { get; set; } } -} +} \ No newline at end of file diff --git a/Reinforced.Typings/Attributes/TsValueAttribute.cs b/Reinforced.Typings/Attributes/TsValueAttribute.cs index 6a5e863f..ac45f44f 100644 --- a/Reinforced.Typings/Attributes/TsValueAttribute.cs +++ b/Reinforced.Typings/Attributes/TsValueAttribute.cs @@ -3,14 +3,14 @@ namespace Reinforced.Typings.Attributes { /// - /// Specifies exporting enum value + /// Specifies exporting enum value /// [AttributeUsage(AttributeTargets.Field)] public class TsValueAttribute : TsAttributeBase, INameOverrideAttribute { /// - /// Overrides enum value name + /// Overrides enum value name /// public virtual string Name { get; set; } } -} +} \ No newline at end of file diff --git a/Reinforced.Typings/ConfigurationRepository.cs b/Reinforced.Typings/ConfigurationRepository.cs index 17de2086..38c04542 100644 --- a/Reinforced.Typings/ConfigurationRepository.cs +++ b/Reinforced.Typings/ConfigurationRepository.cs @@ -2,9 +2,8 @@ using System.Collections.Generic; using System.Linq; using System.Reflection; -using System.Text; -using System.Threading.Tasks; using Reinforced.Typings.Attributes; +using Reinforced.Typings.Fluent.Interfaces; namespace Reinforced.Typings { @@ -16,19 +15,51 @@ public static ConfigurationRepository Instance set { _instance = value; } } - private readonly Dictionary _attributesForType = new Dictionary(); - private readonly Dictionary _attributesForMethods = new Dictionary(); - private readonly Dictionary _attributesForProperties = new Dictionary(); - private readonly Dictionary _attributesForFields = new Dictionary(); - private readonly Dictionary _attributesForEnumValues = new Dictionary(); - private readonly Dictionary _attributesForParameters = new Dictionary(); - private readonly Dictionary> _referenceAttributes = new Dictionary>(); + #region private fields + + private readonly Dictionary _attributesForType = + new Dictionary(); + + private readonly Dictionary _attributesForMethods = + new Dictionary(); + + private readonly Dictionary _attributesForProperties = + new Dictionary(); + + private readonly Dictionary _attributesForFields = + new Dictionary(); + + private readonly Dictionary _attributesForEnumValues = + new Dictionary(); + + private readonly Dictionary _attributesForParameters = + new Dictionary(); + + private readonly Dictionary> _referenceAttributes = + new Dictionary>(); + + private readonly Dictionary _pathesToFiles = new Dictionary(); + private readonly Dictionary> _typesInFiles = new Dictionary>(); private readonly HashSet _ignored = new HashSet(); private static ConfigurationRepository _instance; private readonly List _references = new List(); private readonly List _additionalDocumentationPathes = new List(); + #endregion + + #region Fileds frontend + + public Dictionary PathesToFiles + { + get { return _pathesToFiles; } + } + + public Dictionary> TypesInFiles + { + get { return _typesInFiles; } + } + public List AdditionalDocumentationPathes { get { return _additionalDocumentationPathes; } @@ -84,10 +115,50 @@ public Dictionary AttributesForEnumValues get { return _attributesForEnumValues; } } + #endregion + + #region Division among files + + public void AddFileSeparationSettings(Type type, IReferenceConfigurationBuilder refs = null) + { + var refsList = ReferenceAttributes.GetOrCreate(type); + var attrs = type.GetCustomAttributes(); + if (attrs != null) refsList.AddRange(attrs); + var fileAttr = type.GetCustomAttribute(); + if (fileAttr != null) + { + TrackTypeFile(type, fileAttr.FileName); + } + + if (refs != null) + { + refsList.AddRange(refs.References); + TrackTypeFile(type, refs.PathToFile); + } + } + + private void TrackTypeFile(Type t, string fileName) + { + if (string.IsNullOrEmpty(fileName)) return; + var typesPerFile = _typesInFiles.GetOrCreate(fileName); + if (!typesPerFile.Contains(t)) typesPerFile.Add(t); + _pathesToFiles[t] = fileName; + } + + public string GetPathForFile(Type t) + { + if (_pathesToFiles.ContainsKey(t)) return _pathesToFiles[t]; + return null; + } + + #endregion + + #region Attribute retrieve methods + public TAttr ForType(Type t) where TAttr : TsDeclarationAttributeBase { - return _attributesForType.GetOr(t, ()=>t.GetCustomAttribute(false)) as TAttr; + return _attributesForType.GetOr(t, () => t.GetCustomAttribute(false)) as TAttr; } public TsDeclarationAttributeBase ForType(Type t) @@ -100,49 +171,59 @@ public TsFunctionAttribute ForMember(MethodInfo member) return _attributesForMethods.GetOr(member, () => member.GetCustomAttribute(false)); } + public TsTypedMemberAttributeBase ForMember(MemberInfo member) + { + if (member is PropertyInfo) return ForMember((PropertyInfo) member); + if (member is MethodInfo) return ForMember((MethodInfo) member); + if (member is FieldInfo) return ForMember((FieldInfo) member); + return null; + } + public T ForMember(MemberInfo member) where T : TsTypedMemberAttributeBase { - if (member is PropertyInfo) return (T)(object)ForMember((PropertyInfo)member); - if (member is MethodInfo) return (T)(object)ForMember((MethodInfo)member); - if (member is FieldInfo) return (T)(object)ForMember((FieldInfo)member); + if (member is PropertyInfo) return (T) (object) ForMember((PropertyInfo) member); + if (member is MethodInfo) return (T) (object) ForMember((MethodInfo) member); + if (member is FieldInfo) return (T) (object) ForMember((FieldInfo) member); return null; } - public bool IsIgnored(MemberInfo member) + public TsParameterAttribute ForMember(ParameterInfo member) { - if (member is PropertyInfo) return IsIgnored((PropertyInfo) member); - if (member is MethodInfo) return IsIgnored((MethodInfo)member); - if (member is FieldInfo) return IsIgnored((FieldInfo)member); - return false; + return _attributesForParameters.GetOr(member, () => member.GetCustomAttribute(false)); } - public bool IsIgnored(MethodInfo member) + + public TsPropertyAttribute ForMember(PropertyInfo member) { - return _ignored.Contains(member) || (member.GetCustomAttribute(false) != null); + return _attributesForProperties.GetOr(member, () => member.GetCustomAttribute(false)); } - public TsParameterAttribute ForMember(ParameterInfo member) + public TsPropertyAttribute ForMember(FieldInfo member) { - return _attributesForParameters.GetOr(member, () => member.GetCustomAttribute(false)); + return _attributesForFields.GetOr(member, () => member.GetCustomAttribute(false)); } - public bool IsIgnored(ParameterInfo member) + public TsBaseParamAttribute ForMember(ConstructorInfo member) { - return _ignored.Contains(member) || (member.GetCustomAttribute() != null); + return member.GetCustomAttribute(false); } - public TsPropertyAttribute ForMember(PropertyInfo member) + public TsValueAttribute ForEnumValue(FieldInfo member) { - return _attributesForProperties.GetOr(member, () => member.GetCustomAttribute(false)); + return _attributesForEnumValues.GetOr(member, () => member.GetCustomAttribute(false)); } - public bool IsIgnored(PropertyInfo member) + #endregion + + #region Ignorance tracking methods + + public bool IsIgnored(Type member) { - return _ignored.Contains(member) || (member.GetCustomAttribute() != null); + return ForType(member) == null; } - public TsPropertyAttribute ForMember(FieldInfo member) + public bool IsIgnored(ConstructorInfo member) { - return _attributesForFields.GetOr(member, () => member.GetCustomAttribute(false)); + return (member.GetCustomAttribute(false) != null); } public bool IsIgnored(FieldInfo member) @@ -150,19 +231,97 @@ public bool IsIgnored(FieldInfo member) return _ignored.Contains(member) || (member.GetCustomAttribute() != null); } - public TsBaseParamAttribute ForMember(ConstructorInfo member) + public bool IsIgnored(PropertyInfo member) { - return member.GetCustomAttribute(false); + return _ignored.Contains(member) || (member.GetCustomAttribute() != null); } - public bool IsIgnored(ConstructorInfo member) + public bool IsIgnored(ParameterInfo member) { - return (member.GetCustomAttribute(false) != null); + return _ignored.Contains(member) || (member.GetCustomAttribute() != null); } - public TsValueAttribute ForEnumValue(FieldInfo member) + public bool IsIgnored(MemberInfo member) { - return _attributesForEnumValues.GetOr(member, () => member.GetCustomAttribute(false)); + if (member is Type) return IsIgnored((Type) member); + if (member is PropertyInfo) return IsIgnored((PropertyInfo) member); + if (member is MethodInfo) return IsIgnored((MethodInfo) member); + if (member is FieldInfo) return IsIgnored((FieldInfo) member); + return false; + } + + public bool IsIgnored(MethodInfo member) + { + return _ignored.Contains(member) || (member.GetCustomAttribute(false) != null); } + + #endregion + + #region Determine what is exported + + public FieldInfo[] GetExportedFields(Type t) + { + if (IsIgnored(t)) return new FieldInfo[0]; + if (t.IsEnum) return new FieldInfo[0]; + + var typeAttr = ForType(t); + var aexpSwith = typeAttr as IAutoexportSwitchAttribute; + + if (aexpSwith != null) + { + var allMembers = + t.GetFields(TypeExtensions.MembersFlags).Where(TypeExtensions.TypeScriptMemberSearchPredicate); + if (!aexpSwith.AutoExportFields) + { + allMembers = allMembers.Where(c => ForMember(c) != null); + } + return allMembers.OfType().ToArray(); + } + return new FieldInfo[0]; + } + + public PropertyInfo[] GetExportedProperties(Type t) + { + if (IsIgnored(t)) return new PropertyInfo[0]; + if (t.IsEnum) return new PropertyInfo[0]; + + var typeAttr = ForType(t); + var aexpSwith = typeAttr as IAutoexportSwitchAttribute; + + if (aexpSwith != null) + { + var allMembers = + t.GetProperties(TypeExtensions.MembersFlags).Where(TypeExtensions.TypeScriptMemberSearchPredicate); + if (!aexpSwith.AutoExportProperties) + { + allMembers = allMembers.Where(c => ForMember(c) != null); + } + return allMembers.OfType().ToArray(); + } + return new PropertyInfo[0]; + } + + public MethodInfo[] GetExportedMethods(Type t) + { + if (IsIgnored(t)) return new MethodInfo[0]; + if (t.IsEnum) return new MethodInfo[0]; + + var typeAttr = ForType(t); + var aexpSwith = typeAttr as IAutoexportSwitchAttribute; + + if (aexpSwith != null) + { + var allMembers = + t.GetMethods(TypeExtensions.MembersFlags).Where(TypeExtensions.TypeScriptMemberSearchPredicate); + if (!aexpSwith.AutoExportMethods) + { + allMembers = allMembers.Where(c => ForMember(c) != null); + } + return allMembers.OfType().Where(c => !c.IsSpecialName).ToArray(); + } + return new MethodInfo[0]; + } + + #endregion } -} +} \ No newline at end of file diff --git a/Reinforced.Typings/DictionaryExtensions.cs b/Reinforced.Typings/DictionaryExtensions.cs index bc84c572..5b37cba3 100644 --- a/Reinforced.Typings/DictionaryExtensions.cs +++ b/Reinforced.Typings/DictionaryExtensions.cs @@ -1,6 +1,5 @@ using System; using System.Collections.Generic; -using Reinforced.Typings.Fluent; using Reinforced.Typings.Fluent.Interfaces; namespace Reinforced.Typings @@ -12,7 +11,8 @@ public static TV GetOrNull(this Dictionary dictionary, T key) if (!dictionary.ContainsKey(key)) return default(TV); return dictionary[key]; } - public static TV GetOr(this Dictionary dictionary, T key,Func or) + + public static TV GetOr(this Dictionary dictionary, T key, Func or) { if (!dictionary.ContainsKey(key)) { diff --git a/Reinforced.Typings/ExportSettings.cs b/Reinforced.Typings/ExportSettings.cs index 5f9041a6..fba4035a 100644 --- a/Reinforced.Typings/ExportSettings.cs +++ b/Reinforced.Typings/ExportSettings.cs @@ -6,29 +6,29 @@ namespace Reinforced.Typings { /// - /// TsExport exporting settings + /// TsExport exporting settings /// public class ExportSettings { - private bool _isLocked; - private string _targetFile; - private string _targetDirectory; - private bool _writeWarningComment; - private bool _hierarchical; - private Assembly[] _sourceAssemblies; - private bool _exportPureTyings; - private string _rootNamespace; private bool _camelCaseForMethods; private bool _camelCaseForProperties; + private Action _configurationMethod; private string _documentationFilePath; + private bool _exportPureTyings; private bool _generateDocumentation; - private Action _configurationMethod; + private bool _hierarchical; + private bool _isLocked; + private string _rootNamespace; + private Assembly[] _sourceAssemblies; + private string _targetDirectory; + private string _targetFile; + private bool _writeWarningComment; /// - /// The assemblies to extract typings from. - /// Important! TsExporter do not perform any job for loading assemblies. It is left upon a calling side. - /// That is because loading assemblies is highly dependent on calling side's AppDomain. - /// TsExporter shouldnt handle all this shit + /// The assemblies to extract typings from. + /// Important! TsExporter do not perform any job for loading assemblies. It is left upon a calling side. + /// That is because loading assemblies is highly dependent on calling side's AppDomain. + /// TsExporter shouldnt handle all this shit /// public Assembly[] SourceAssemblies { @@ -41,8 +41,8 @@ public Assembly[] SourceAssemblies } /// - /// True to create project hierarchy in target folder. - /// False to store generated typings in single file + /// True to create project hierarchy in target folder. + /// False to store generated typings in single file /// public bool Hierarchical { @@ -55,8 +55,8 @@ public bool Hierarchical } /// - /// True to write warning comment about auto-generated to every file. - /// False to do not + /// True to write warning comment about auto-generated to every file. + /// False to do not /// public bool WriteWarningComment { @@ -69,8 +69,8 @@ public bool WriteWarningComment } /// - /// Target directory where to store generated typing files. - /// This parameter is not used when Hierarcy is false + /// Target directory where to store generated typing files. + /// This parameter is not used when Hierarcy is false /// public string TargetDirectory { @@ -83,8 +83,8 @@ public string TargetDirectory } /// - /// Target file where to store generated sources. - /// This parameter is not used when Hierarchy is true + /// Target file where to store generated sources. + /// This parameter is not used when Hierarchy is true /// public string TargetFile { @@ -97,8 +97,8 @@ public string TargetFile } /// - /// If true, export will be performed in .d.ts manner (only typings, declare module etc). - /// Otherwise, export will be performed to regulat .ts file + /// If true, export will be performed in .d.ts manner (only typings, declare module etc). + /// Otherwise, export will be performed to regulat .ts file /// public bool ExportPureTypings { @@ -111,8 +111,8 @@ public bool ExportPureTypings } /// - /// Specifies root namespace for hierarchical export. - /// Helps to avoid creating redundant directories when hierarchical export. + /// Specifies root namespace for hierarchical export. + /// Helps to avoid creating redundant directories when hierarchical export. /// public string RootNamespace { @@ -125,7 +125,7 @@ public string RootNamespace } /// - /// Use camelCase for methods naming + /// Use camelCase for methods naming /// public bool CamelCaseForMethods { @@ -138,7 +138,7 @@ public bool CamelCaseForMethods } /// - /// Use camelCase for properties naming + /// Use camelCase for properties naming /// public bool CamelCaseForProperties { @@ -151,7 +151,7 @@ public bool CamelCaseForProperties } /// - /// Path to assembly's XMLDOC file + /// Path to assembly's XMLDOC file /// public string DocumentationFilePath { @@ -164,7 +164,7 @@ public string DocumentationFilePath } /// - /// Fluent configuration method + /// Fluent configuration method /// public Action ConfigurationMethod { @@ -177,7 +177,7 @@ public Action ConfigurationMethod } /// - /// Enables or disables documentation generator + /// Enables or disables documentation generator /// public bool GenerateDocumentation { @@ -191,28 +191,27 @@ public bool GenerateDocumentation internal string References { get; set; } + /// + /// Documentation manager + /// + public DocumentationManager Documentation { get; internal set; } + + internal string CurrentNamespace { get; set; } + + /// + /// There is a case when you are exporting base class as interface. It may lead to some unusual handling of generation, + /// so I'm using this property to denote such cases and fix it in-place + /// + internal bool SpecialCase { get; set; } internal void Lock() { _isLocked = true; } - internal void Unlock() { _isLocked = false; } - - /// - /// Documentation manager - /// - public DocumentationManager Documentation { get; internal set; } - - internal string CurrentNamespace { get; set; } - - /// - /// There is a case when you are exporting base class as interface. It may lead to some unusual handling of generation, so I'm using this property to denote such cases and fix it in-place - /// - internal bool SpecialCase { get; set; } } -} +} \ No newline at end of file diff --git a/Reinforced.Typings/FilesOperations.cs b/Reinforced.Typings/FilesOperations.cs index 34bf745e..206527f6 100644 --- a/Reinforced.Typings/FilesOperations.cs +++ b/Reinforced.Typings/FilesOperations.cs @@ -51,6 +51,10 @@ public string GetTmpFile(string fileName) public string GetPathForType(Type t) { + var fromConfiguration = ConfigurationRepository.Instance.GetPathForFile(t); + if (!string.IsNullOrEmpty(fromConfiguration)) + return Path.Combine(_settings.TargetDirectory, fromConfiguration).Replace("/", "\\"); + var ns = t.GetNamespace(); var tn = t.GetName(); @@ -62,49 +66,49 @@ public string GetPathForType(Type t) if (string.IsNullOrEmpty(ns)) return Path.Combine(_settings.TargetDirectory, tn); if (!string.IsNullOrEmpty(_settings.RootNamespace)) { - ns = ns.Replace(_settings.RootNamespace, String.Empty); + ns = ns.Replace(_settings.RootNamespace, string.Empty); } ns = ns.Trim('.').Replace('.', '\\'); - var pth = Path.Combine(!string.IsNullOrEmpty(ns) ? Path.Combine(_settings.TargetDirectory, ns) : _settings.TargetDirectory, tn); + var pth = + Path.Combine( + !string.IsNullOrEmpty(ns) ? Path.Combine(_settings.TargetDirectory, ns) : _settings.TargetDirectory, + tn); return pth; } - public string GetRelativePathForType(Type t, string currentNamespace) + public string GetRelativePathForType(Type typeToReference, Type currentlyExportingType) { - currentNamespace = currentNamespace.Replace(_settings.RootNamespace, String.Empty); - - currentNamespace = currentNamespace.Replace('.', '\\').Trim('\\'); - - var path = GetPathForType(t).Replace(_settings.TargetDirectory, String.Empty); - var fileName = Path.GetFileName(path); - var desiredNamespace = Path.GetDirectoryName(path).Trim('\\'); + var currentFile = GetPathForType(currentlyExportingType); + var desiredFile = GetPathForType(typeToReference); + var desiredFileName = Path.GetFileName(desiredFile); - var relPath = GetRelativeNamespacePath(currentNamespace, desiredNamespace); + var relPath = GetRelativeNamespacePath(Path.GetDirectoryName(currentFile), + Path.GetDirectoryName(desiredFile)); - relPath = Path.Combine(relPath, fileName); + relPath = Path.Combine(relPath, desiredFileName); relPath = relPath.Replace('\\', '/'); return relPath; } private string GetRelativeNamespacePath(string currentNamespace, string desiredNamespace) { - if (currentNamespace==desiredNamespace) return String.Empty; + if (currentNamespace == desiredNamespace) return string.Empty; if (string.IsNullOrEmpty(currentNamespace)) return desiredNamespace; - + var current = currentNamespace.Split('\\'); var desired = desiredNamespace.Split('\\'); - - StringBuilder result = new StringBuilder(); + + var result = new StringBuilder(); if (string.IsNullOrEmpty(desiredNamespace)) { - for (int i = 0; i < current.Length; i++) result.Append("..\\"); + for (var i = 0; i < current.Length; i++) result.Append("..\\"); } else { - int level = current.Length - 1; + var level = current.Length - 1; while (level >= 0 && (current.I(level) != desired.I(level))) { result.Append("..\\"); @@ -123,7 +127,6 @@ public void ClearTempRegistry() { _tmpFiles.Clear(); } - } internal static class ArrayExtensions @@ -134,4 +137,4 @@ public static T I(this T[] array, int idx) return array[idx]; } } -} +} \ No newline at end of file diff --git a/Reinforced.Typings/Fluent/ClassConfigurationBuilder.cs b/Reinforced.Typings/Fluent/ClassConfigurationBuilder.cs index 4869200c..92cd910d 100644 --- a/Reinforced.Typings/Fluent/ClassConfigurationBuilder.cs +++ b/Reinforced.Typings/Fluent/ClassConfigurationBuilder.cs @@ -1,29 +1,17 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using Reinforced.Typings.Attributes; +using Reinforced.Typings.Attributes; using Reinforced.Typings.Fluent.Interfaces; namespace Reinforced.Typings.Fluent { /// - /// Export configuration builder for class + /// Export configuration builder for class /// /// public class ClassConfigurationBuilder : TypeConfigurationBuilder, IClassConfigurationBuilder { - private TsClassAttribute AttributePrototype { get; set; } - - TsClassAttribute IExportConfiguration.AttributePrototype - { - get { return this.AttributePrototype; } - } - internal ClassConfigurationBuilder() { - AttributePrototype = new TsClassAttribute() + AttributePrototype = new TsClassAttribute { AutoExportConstructors = false, AutoExportFields = false, @@ -31,5 +19,12 @@ internal ClassConfigurationBuilder() AutoExportMethods = false }; } + + private TsClassAttribute AttributePrototype { get; set; } + + TsClassAttribute IExportConfiguration.AttributePrototype + { + get { return AttributePrototype; } + } } -} +} \ No newline at end of file diff --git a/Reinforced.Typings/Fluent/ConfigurationBuilder.cs b/Reinforced.Typings/Fluent/ConfigurationBuilder.cs index 8be86473..27c5f6a1 100644 --- a/Reinforced.Typings/Fluent/ConfigurationBuilder.cs +++ b/Reinforced.Typings/Fluent/ConfigurationBuilder.cs @@ -7,15 +7,20 @@ namespace Reinforced.Typings.Fluent { /// - /// Fluent configuration builder + /// Fluent configuration builder /// public class ConfigurationBuilder { - private readonly Dictionary _typeConfigurationBuilders = new Dictionary(); - private readonly Dictionary _enumConfigurationBuilders = new Dictionary(); - private readonly List _references = new List(); private readonly List _additionalDocumentationPathes = new List(); + private readonly Dictionary _enumConfigurationBuilders = + new Dictionary(); + + private readonly List _references = new List(); + + private readonly Dictionary _typeConfigurationBuilders = + new Dictionary(); + internal List AdditionalDocumentationPathes { get { return _additionalDocumentationPathes; } @@ -38,7 +43,7 @@ internal Dictionary EnumConfigurationBuilders internal ConfigurationRepository Build() { - ConfigurationRepository repository = new ConfigurationRepository(); + var repository = new ConfigurationRepository(); foreach (var kv in _typeConfigurationBuilders) { var cls = kv.Value as IClassConfigurationBuilder; @@ -65,15 +70,15 @@ internal ConfigurationRepository Build() var method = kvm.Key as MethodInfo; if (prop != null) { - repository.AttributesForProperties[prop] = (TsPropertyAttribute)kvm.Value.AttributePrototype; + repository.AttributesForProperties[prop] = (TsPropertyAttribute) kvm.Value.AttributePrototype; } if (field != null) { - repository.AttributesForFields[field] = (TsPropertyAttribute)kvm.Value.AttributePrototype; + repository.AttributesForFields[field] = (TsPropertyAttribute) kvm.Value.AttributePrototype; } if (method != null) { - repository.AttributesForMethods[method] = (TsFunctionAttribute)kvm.Value.AttributePrototype; + repository.AttributesForMethods[method] = (TsFunctionAttribute) kvm.Value.AttributePrototype; } } foreach (var kvp in kv.Value.ParametersConfiguration) @@ -85,7 +90,7 @@ internal ConfigurationRepository Build() } repository.AttributesForParameters[kvp.Key] = kvp.Value.AttributePrototype; } - AddReferences(repository, kv.Key, kv.Value); + repository.AddFileSeparationSettings(kv.Key, kv.Value); } foreach (var kv in _enumConfigurationBuilders) { @@ -95,19 +100,11 @@ internal ConfigurationRepository Build() repository.AttributesForEnumValues[enumValueExportConfiguration.Key] = enumValueExportConfiguration.Value.AttributePrototype; } - AddReferences(repository,kv.Key,kv.Value); + repository.AddFileSeparationSettings(kv.Key, kv.Value); } repository.References.AddRange(_references); repository.AdditionalDocumentationPathes.AddRange(_additionalDocumentationPathes); return repository; } - - private static void AddReferences(ConfigurationRepository repository,Type type,IReferenceConfigurationBuilder refs) - { - var refsList = repository.ReferenceAttributes.GetOrCreate(type); - refsList.AddRange(refs.References); - var attrs = type.GetCustomAttributes(); - if (attrs != null) refsList.AddRange(attrs); - } } -} +} \ No newline at end of file diff --git a/Reinforced.Typings/Fluent/ConfigurationBuildersExtensions.cs b/Reinforced.Typings/Fluent/ConfigurationBuildersExtensions.cs index 98275b30..d820c90b 100644 --- a/Reinforced.Typings/Fluent/ConfigurationBuildersExtensions.cs +++ b/Reinforced.Typings/Fluent/ConfigurationBuildersExtensions.cs @@ -8,16 +8,19 @@ namespace Reinforced.Typings.Fluent { /// - /// Extensions for configuration builders + /// Extensions for configuration builders /// public static class ConfigurationBuildersExtensions { - private static T ApplyMembersConfiguration(T tc, IEnumerable prop, Action configuration = null) + private static T ApplyMembersConfiguration(T tc, IEnumerable prop, + Action configuration = null) where T : ITypeConfigurationBuilder { foreach (var propertyInfo in prop) { - var conf = (PropertyExportConfiguration)tc.MembersConfiguration.GetOrCreate(propertyInfo, () => new PropertyExportConfiguration()); + var conf = + (PropertyExportConfiguration) + tc.MembersConfiguration.GetOrCreate(propertyInfo, () => new PropertyExportConfiguration()); if (configuration != null) configuration(conf); } return tc; @@ -28,84 +31,162 @@ private static T ApplyMethodsConfiguration(T tc, IEnumerable meth { foreach (var methodInfo in methds) { - var conf = (MethodExportConfiguration)tc.MembersConfiguration.GetOrCreate(methodInfo, () => new MethodExportConfiguration()); + var conf = + (MethodExportConfiguration) + tc.MembersConfiguration.GetOrCreate(methodInfo, () => new MethodExportConfiguration()); if (configuration != null) configuration(conf); } return tc; } + private static void ExtractParameters(ITypeConfigurationBuilder conf, LambdaExpression methodLambda) + { + var mex = methodLambda.Body as MethodCallExpression; + if (mex == null) + throw new Exception( + "MethodCallExpression should be provided for .WithMethod call. Please use only lamba expressions in this place."); + var mi = mex.Method; + + var methodParameters = mi.GetParameters(); + if (methodParameters.Length == 0) return; + + + var i = 0; + foreach (var expression in mex.Arguments) + { + var pi = methodParameters[i]; + i++; + + var call = expression as MethodCallExpression; + if (call != null) + { + if (call.Method.IsGenericMethod && + call.Method.GetGenericMethodDefinition() == Ts.ParametrizedParameterMethod) + { + var pcb = + (ParameterConfigurationBuilder) + conf.ParametersConfiguration.GetOrCreate(pi, () => new ParameterConfigurationBuilder()); + + var parsed = false; + var arg = call.Arguments[0] as LambdaExpression; + if (arg != null) + { + var delg = arg.Compile(); + delg.DynamicInvoke(pcb); + parsed = true; + } + var uarg = call.Arguments[0] as UnaryExpression; // convert expression + if (uarg != null) + { + var operand = uarg.Operand as MethodCallExpression; + if (operand != null) + { + var actionArg = operand.Object as ConstantExpression; + if (actionArg != null) + { + var value = actionArg.Value as MethodInfo; + if (value != null) + { + var param = Expression.Parameter(typeof (ParameterConfigurationBuilder)); + var newCall = Expression.Call(value, param); + var newLambda = Expression.Lambda(newCall, param); + var delg = newLambda.Compile(); + delg.DynamicInvoke(pcb); + parsed = true; + } + } + } + if (!parsed) + throw new Exception( + string.Format( + "Sorry, but {0} is not very good idea for parameter configuration. Try using simple lambda expression.", + call.Arguments[0])); + } + } + } + } + } + #region Properties /// - /// Include specified property to resulting typing + /// Include specified property to resulting typing /// /// Configuration builder /// Property to include /// Fluent - public static PropertyExportConfiguration WithProperty(this TypeConfigurationBuilder tc, Expression> property) + public static PropertyExportConfiguration WithProperty(this TypeConfigurationBuilder tc, + Expression> property) { var prop = LambdaHelpers.ParsePropertyLambda(property); ITypeConfigurationBuilder tcb = tc; - return (PropertyExportConfiguration)tcb.MembersConfiguration.GetOrCreate(prop, () => new PropertyExportConfiguration()); + return + (PropertyExportConfiguration) + tcb.MembersConfiguration.GetOrCreate(prop, () => new PropertyExportConfiguration()); } /// - /// Include specified property to resulting typing + /// Include specified property to resulting typing /// /// Configuration builder /// Property to include /// Configuration to be applied to selected property /// Fluent - public static InterfaceConfigurationBuilder WithProperty(this InterfaceConfigurationBuilder tc, Expression> property, Action configuration) + public static InterfaceConfigurationBuilder WithProperty(this InterfaceConfigurationBuilder tc, + Expression> property, Action configuration) { - return tc.WithProperties(new[] { LambdaHelpers.ParsePropertyLambda(property) }, configuration); + return tc.WithProperties(new[] {LambdaHelpers.ParsePropertyLambda(property)}, configuration); } /// - /// Include specified property to resulting typing + /// Include specified property to resulting typing /// /// Configuration builder /// Property to include /// Configuration to be applied to selected property /// Fluent - public static ClassConfigurationBuilder WithProperty(this ClassConfigurationBuilder tc, Expression> property, Action configuration) + public static ClassConfigurationBuilder WithProperty(this ClassConfigurationBuilder tc, + Expression> property, Action configuration) { - return tc.WithProperties(new[] { LambdaHelpers.ParsePropertyLambda(property) }, configuration); + return tc.WithProperties(new[] {LambdaHelpers.ParsePropertyLambda(property)}, configuration); } /// - /// Include specified properties to resulting typing + /// Include specified properties to resulting typing /// /// Configuration builder /// Properties to include /// Configuration to be applied to each property /// Fluent - public static T WithProperties(this T tc, IEnumerable properties, Action configuration = null) where T : ITypeConfigurationBuilder + public static T WithProperties(this T tc, IEnumerable properties, + Action configuration = null) where T : ITypeConfigurationBuilder { return ApplyMembersConfiguration(tc, properties, configuration); } /// - /// Include specified properties to resulting typing + /// Include specified properties to resulting typing /// /// Configuration builder /// Predicate function for properties to include /// Configuration to be applied to each property /// Fluent - public static T WithProperties(this T tc, Func predicate, Action configuration = null) where T : ITypeConfigurationBuilder + public static T WithProperties(this T tc, Func predicate, + Action configuration = null) where T : ITypeConfigurationBuilder { var prop = tc.Type.GetProperties(TypeExtensions.MembersFlags).Where(predicate); return tc.WithProperties(prop, configuration); } /// - /// Include specified properties to resulting typing + /// Include specified properties to resulting typing /// /// Configuration builder /// BindingFlags describing properties to include /// Configuration to be applied to each property /// Fluent - public static T WithProperties(this T tc, BindingFlags bindingFlags, Action configuration = null) + public static T WithProperties(this T tc, BindingFlags bindingFlags, + Action configuration = null) where T : ITypeConfigurationBuilder { var prop = tc.Type.GetProperties(bindingFlags); @@ -113,321 +194,363 @@ public static T WithProperties(this T tc, BindingFlags bindingFlags, Action

- /// Include all properties to resulting typing + /// Include all properties to resulting typing /// /// Configuration builder /// Configuration to be applied to each property /// Fluent - public static T WithAllProperties(this T tc, Action configuration = null) where T : ITypeConfigurationBuilder + public static T WithAllProperties(this T tc, Action configuration = null) + where T : ITypeConfigurationBuilder { var prop = tc.Type.GetProperties(TypeExtensions.MembersFlags); return tc.WithProperties(prop, configuration); } ///

- /// Include all public properties to resulting typing + /// Include all public properties to resulting typing /// /// Configuration builder /// Configuration to be applied to each property /// Fluent - public static T WithPublicProperties(this T tc, Action configuration = null) where T : ITypeConfigurationBuilder + public static T WithPublicProperties(this T tc, Action configuration = null) + where T : ITypeConfigurationBuilder { var prop = tc.Type.GetProperties(BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly); return tc.WithProperties(prop, configuration); } + #endregion #region Fields + /// - /// Include specified field to resulting typing + /// Include specified field to resulting typing /// /// Configuration builder /// Field to include /// Fluent - public static PropertyExportConfiguration WithField(this TypeConfigurationBuilder tc, Expression> field) + public static PropertyExportConfiguration WithField(this TypeConfigurationBuilder tc, + Expression> field) { var prop = LambdaHelpers.ParseFieldLambda(field); ITypeConfigurationBuilder tcb = tc; - return (PropertyExportConfiguration)tcb.MembersConfiguration.GetOrCreate(prop, () => new PropertyExportConfiguration()); + return + (PropertyExportConfiguration) + tcb.MembersConfiguration.GetOrCreate(prop, () => new PropertyExportConfiguration()); } /// - /// Include specified property to resulting typing + /// Include specified property to resulting typing /// /// Configuration builder /// Property to include /// Configuration to be applied to selected property /// Fluent - public static InterfaceConfigurationBuilder WithField(this InterfaceConfigurationBuilder tc, Expression> property, Action configuration) + public static InterfaceConfigurationBuilder WithField(this InterfaceConfigurationBuilder tc, + Expression> property, Action configuration) { - ApplyMembersConfiguration(tc, new[] { LambdaHelpers.ParseFieldLambda(property) }, configuration); + ApplyMembersConfiguration(tc, new[] {LambdaHelpers.ParseFieldLambda(property)}, configuration); return tc; } /// - /// Include specified property to resulting typing + /// Include specified property to resulting typing /// /// Configuration builder /// Property to include /// Configuration to be applied to selected property /// Fluent - public static ClassConfigurationBuilder WithField(this ClassConfigurationBuilder tc, Expression> property, Action configuration) + public static ClassConfigurationBuilder WithField(this ClassConfigurationBuilder tc, + Expression> property, Action configuration) { - return tc.WithFields(new[] { LambdaHelpers.ParseFieldLambda(property) }, configuration); + return tc.WithFields(new[] {LambdaHelpers.ParseFieldLambda(property)}, configuration); } /// - /// Include specified fields to resulting typing + /// Include specified fields to resulting typing /// /// Configuration builder /// Fields to include /// Configuration to be applied to each field /// Fluent - public static T WithFields(this T tc, IEnumerable fields, Action configuration = null) where T : ITypeConfigurationBuilder + public static T WithFields(this T tc, IEnumerable fields, + Action configuration = null) where T : ITypeConfigurationBuilder { return ApplyMembersConfiguration(tc, fields, configuration); } /// - /// Include specified fields to resulting typing + /// Include specified fields to resulting typing /// /// Configuration builder /// Predicate function that should mathc for fields to include /// Configuration to be applied to each field /// Fluent - public static T WithFields(this T tc, Func predicate, Action configuration = null) where T : ITypeConfigurationBuilder + public static T WithFields(this T tc, Func predicate, + Action configuration = null) where T : ITypeConfigurationBuilder { var prop = tc.Type.GetFields(TypeExtensions.MembersFlags).Where(predicate); return tc.WithFields(prop, configuration); } /// - /// Include all fields to resulting typing + /// Include all fields to resulting typing /// /// Configuration builder /// Configuration to be applied to each field /// Fluent - public static T WithAllFields(this T tc, Action configuration = null) where T : ITypeConfigurationBuilder + public static T WithAllFields(this T tc, Action configuration = null) + where T : ITypeConfigurationBuilder { var prop = tc.Type.GetFields(TypeExtensions.MembersFlags); return tc.WithFields(prop, configuration); } /// - /// Include all public fields to resulting typing + /// Include all public fields to resulting typing /// /// Configuration builder /// Configuration to be applied to each field /// Fluent - public static T WithPublicFields(this T tc, Action configuration = null) where T : ITypeConfigurationBuilder + public static T WithPublicFields(this T tc, Action configuration = null) + where T : ITypeConfigurationBuilder { var prop = tc.Type.GetFields(BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly); return tc.WithFields(prop, configuration); } /// - /// Include specified fields to resulting typing + /// Include specified fields to resulting typing /// /// Configuration builder /// BindingFlags describing fields to include /// Configuration to be applied to each field /// Fluent - public static T WithFields(this T tc, BindingFlags bindingFlags, Action configuration = null) where T : ITypeConfigurationBuilder + public static T WithFields(this T tc, BindingFlags bindingFlags, + Action configuration = null) where T : ITypeConfigurationBuilder { var prop = tc.Type.GetFields(bindingFlags); return tc.WithFields(prop, configuration); } + #endregion #region Methods + /// - /// Include specified method to resulting typing. - /// User to mock up method parameters or specify configuration for perticular method parameter + /// Include specified method to resulting typing. + /// User to mock up method parameters or specify configuration for perticular method + /// parameter /// /// Configuration builder /// Method to include /// Fluent - public static MethodExportConfiguration WithMethod(this TypeConfigurationBuilder tc, Expression> method) + public static MethodExportConfiguration WithMethod(this TypeConfigurationBuilder tc, + Expression> method) { var prop = LambdaHelpers.ParseMethodLambda(method); ITypeConfigurationBuilder tcb = tc; - var methodConf = (MethodExportConfiguration)tcb.MembersConfiguration.GetOrCreate(prop, () => new MethodExportConfiguration()); + var methodConf = + (MethodExportConfiguration) + tcb.MembersConfiguration.GetOrCreate(prop, () => new MethodExportConfiguration()); ExtractParameters(tcb, method); return methodConf; } /// - /// Include specified method to resulting typing. - /// User to mock up method parameters or specify configuration for perticular method parameter + /// Include specified method to resulting typing. + /// User to mock up method parameters or specify configuration for perticular method + /// parameter /// /// Configuration builder /// Method to include /// configuration to be applied to method /// Fluent - public static InterfaceConfigurationBuilder WithMethod(this InterfaceConfigurationBuilder tc, Expression> method, Action configuration) + public static InterfaceConfigurationBuilder WithMethod(this InterfaceConfigurationBuilder tc, + Expression> method, Action configuration) { - tc.WithMethods(new[] { LambdaHelpers.ParseMethodLambda(method) }, configuration); + tc.WithMethods(new[] {LambdaHelpers.ParseMethodLambda(method)}, configuration); ITypeConfigurationBuilder tcb = tc; ExtractParameters(tcb, method); return tc; } /// - /// Include specified method to resulting typing. - /// User to mock up method parameters or specify configuration for perticular method parameter + /// Include specified method to resulting typing. + /// User to mock up method parameters or specify configuration for perticular method + /// parameter /// /// Configuration builder /// Method to include /// Configuration to be applied to method /// Fluent - public static ClassConfigurationBuilder WithMethod(this ClassConfigurationBuilder tc, Expression> method, Action configuration) + public static ClassConfigurationBuilder WithMethod(this ClassConfigurationBuilder tc, + Expression> method, Action configuration) { - tc.WithMethods(new[] { LambdaHelpers.ParseMethodLambda(method) }, configuration); + tc.WithMethods(new[] {LambdaHelpers.ParseMethodLambda(method)}, configuration); ITypeConfigurationBuilder tcb = tc; ExtractParameters(tcb, method); return tc; } /// - /// Include specified method to resulting typing. - /// User to mock up method parameters or specify configuration for perticular method parameter + /// Include specified method to resulting typing. + /// User to mock up method parameters or specify configuration for perticular method + /// parameter /// /// Configuration builder /// Method to include /// Fluent - public static MethodExportConfiguration WithMethod(this TypeConfigurationBuilder tc, Expression> method) + public static MethodExportConfiguration WithMethod(this TypeConfigurationBuilder tc, + Expression> method) { var prop = LambdaHelpers.ParseMethodLambda(method); ITypeConfigurationBuilder tcb = tc; - var methodConf = (MethodExportConfiguration)tcb.MembersConfiguration.GetOrCreate(prop, () => new MethodExportConfiguration()); + var methodConf = + (MethodExportConfiguration) + tcb.MembersConfiguration.GetOrCreate(prop, () => new MethodExportConfiguration()); ExtractParameters(tcb, method); return methodConf; } /// - /// Include specified method to resulting typing. - /// User to mock up method parameters or specify configuration for perticular method parameter + /// Include specified method to resulting typing. + /// User to mock up method parameters or specify configuration for perticular method + /// parameter /// /// Configuration builder /// Method to include /// Configuration to be applied to method /// Fluent - public static InterfaceConfigurationBuilder WithMethod(this InterfaceConfigurationBuilder tc, Expression> method, Action configuration) + public static InterfaceConfigurationBuilder WithMethod(this InterfaceConfigurationBuilder tc, + Expression> method, Action configuration) { - tc.WithMethods(new[] { LambdaHelpers.ParseMethodLambda(method) }, configuration); + tc.WithMethods(new[] {LambdaHelpers.ParseMethodLambda(method)}, configuration); ITypeConfigurationBuilder tcb = tc; ExtractParameters(tcb, method); return tc; } /// - /// Include specified method to resulting typing. - /// User to mock up method parameters or specify configuration for perticular method parameter + /// Include specified method to resulting typing. + /// User to mock up method parameters or specify configuration for perticular method + /// parameter /// /// Configuration builder /// Method to include /// Configuration to be applied to method /// Fluent - public static ClassConfigurationBuilder WithMethod(this ClassConfigurationBuilder tc, Expression> method, Action configuration) + public static ClassConfigurationBuilder WithMethod(this ClassConfigurationBuilder tc, + Expression> method, Action configuration) { - tc.WithMethods(new[] { LambdaHelpers.ParseMethodLambda(method) }, configuration); + tc.WithMethods(new[] {LambdaHelpers.ParseMethodLambda(method)}, configuration); ITypeConfigurationBuilder tcb = tc; ExtractParameters(tcb, method); return tc; } /// - /// Include specified methods to resulting typing. + /// Include specified methods to resulting typing. /// /// Configuration builder /// Predicate function that should mathc for methods to include /// Configuration to be applied to each method /// Fluent - public static T WithMethods(this T tc, Func predicate, Action configuration = null) where T : ITypeConfigurationBuilder + public static T WithMethods(this T tc, Func predicate, + Action configuration = null) where T : ITypeConfigurationBuilder { var prop = tc.Type.GetMethods(TypeExtensions.MembersFlags).Where(predicate); return tc.WithMethods(prop, configuration); } /// - /// Include specified methods to resulting typing. + /// Include specified methods to resulting typing. /// /// Configuration builder /// BindingFlags describing methods to include /// Configuration to be applied to each method /// Fluent - public static T WithMethods(this T tc, BindingFlags bindingFlags, Action configuration = null) where T : ITypeConfigurationBuilder + public static T WithMethods(this T tc, BindingFlags bindingFlags, + Action configuration = null) where T : ITypeConfigurationBuilder { var prop = tc.Type.GetMethods(bindingFlags); return tc.WithMethods(prop, configuration); } /// - /// Include specified methods to resulting typing. + /// Include specified methods to resulting typing. /// /// Configuration builder /// Methods to include /// Configuration to be applied to each method /// Fluent - public static T WithMethods(this T tc, IEnumerable methods, Action configuration = null) where T : ITypeConfigurationBuilder + public static T WithMethods(this T tc, IEnumerable methods, + Action configuration = null) where T : ITypeConfigurationBuilder { return ApplyMethodsConfiguration(tc, methods, configuration); } /// - /// Include all methods to resulting typing + /// Include all methods to resulting typing /// /// Configuration builder /// Configuration to be applied to each method /// Fluent - public static T WithAllMethods(this T tc, Action configuration = null) where T : ITypeConfigurationBuilder + public static T WithAllMethods(this T tc, Action configuration = null) + where T : ITypeConfigurationBuilder { var prop = tc.Type.GetMethods(TypeExtensions.MembersFlags); return tc.WithMethods(prop, configuration); } /// - /// Include all methods to resulting typing + /// Include all methods to resulting typing /// /// Configuration builder /// Configuration to be applied to each method /// Fluent - public static T WithPublicMethods(this T tc, Action configuration = null) where T : ITypeConfigurationBuilder + public static T WithPublicMethods(this T tc, Action configuration = null) + where T : ITypeConfigurationBuilder { var prop = tc.Type.GetMethods(BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly); return tc.WithMethods(prop, configuration); } + #endregion #region Interfaces /// - /// Includes specified type to resulting typing exported as interface + /// Includes specified type to resulting typing exported as interface /// /// Type to include /// Configuration builder /// Fluent public static InterfaceConfigurationBuilder ExportAsInterface(this ConfigurationBuilder builder) { - return (InterfaceConfigurationBuilder)builder.TypeConfigurationBuilders.GetOrCreate(typeof(T), () => new InterfaceConfigurationBuilder()); + return + (InterfaceConfigurationBuilder) + builder.TypeConfigurationBuilders.GetOrCreate(typeof (T), + () => new InterfaceConfigurationBuilder()); } /// - /// Includes specified types to resulting typing exported as interfaces + /// Includes specified types to resulting typing exported as interfaces /// /// Configuration builder /// Types to include /// Configuration to be applied to each type /// Fluent - public static void ExportAsInterfaces(this ConfigurationBuilder builder, IEnumerable types, Action configuration = null) + public static void ExportAsInterfaces(this ConfigurationBuilder builder, IEnumerable types, + Action configuration = null) { foreach (var type in types) { var tp = type; - var conf = (IInterfaceConfigurationBuilder)builder.TypeConfigurationBuilders.GetOrCreate(type, () => + var conf = (IInterfaceConfigurationBuilder) builder.TypeConfigurationBuilders.GetOrCreate(type, () => { - var t = typeof(InterfaceConfigurationBuilder<>).MakeGenericType(tp); - return (ITypeConfigurationBuilder)Activator.CreateInstance(t, nonPublic: true); + var t = typeof (InterfaceConfigurationBuilder<>).MakeGenericType(tp); + return (ITypeConfigurationBuilder) Activator.CreateInstance(t, true); }); if (configuration != null) configuration(conf); } @@ -438,42 +561,46 @@ public static void ExportAsInterfaces(this ConfigurationBuilder builder, IEnumer #region Classes /// - /// Includes specified type to resulting typing exported as TypeScript class + /// Includes specified type to resulting typing exported as TypeScript class /// /// Type to include /// Configuration builder /// Fluent public static ClassConfigurationBuilder ExportAsClass(this ConfigurationBuilder builder) { - return (ClassConfigurationBuilder)builder.TypeConfigurationBuilders.GetOrCreate(typeof(T), () => new ClassConfigurationBuilder()); + return + (ClassConfigurationBuilder) + builder.TypeConfigurationBuilders.GetOrCreate(typeof (T), () => new ClassConfigurationBuilder()); } /// - /// Includes specified types to resulting typing exported as TypeScript classes + /// Includes specified types to resulting typing exported as TypeScript classes /// /// Configuration builder /// Types to include /// Configuration to be applied to each type /// Fluent - public static void ExportAsClasses(this ConfigurationBuilder builder, IEnumerable types, Action configuration = null) + public static void ExportAsClasses(this ConfigurationBuilder builder, IEnumerable types, + Action configuration = null) { foreach (var type in types) { var tp = type; - var conf = (IClassConfigurationBuilder)builder.TypeConfigurationBuilders.GetOrCreate(type, () => + var conf = (IClassConfigurationBuilder) builder.TypeConfigurationBuilders.GetOrCreate(type, () => { - var t = typeof(ClassConfigurationBuilder<>).MakeGenericType(tp); - return (IClassConfigurationBuilder)Activator.CreateInstance(t, nonPublic: true); + var t = typeof (ClassConfigurationBuilder<>).MakeGenericType(tp); + return (IClassConfigurationBuilder) Activator.CreateInstance(t, true); }); if (configuration != null) configuration(conf); } } + #endregion #region Enums /// - /// Includes specified type to resulting typing exported as TypeScript enumeration + /// Includes specified type to resulting typing exported as TypeScript enumeration /// /// Type to include /// Configuration builder @@ -481,32 +608,35 @@ public static void ExportAsClasses(this ConfigurationBuilder builder, IEnumerabl public static EnumConfigurationBuilder ExportAsEnum(this ConfigurationBuilder builder) where T : struct { - return (EnumConfigurationBuilder)builder.EnumConfigurationBuilders.GetOrCreate(typeof(T), () => new EnumConfigurationBuilder()); + return + (EnumConfigurationBuilder) + builder.EnumConfigurationBuilders.GetOrCreate(typeof (T), () => new EnumConfigurationBuilder()); } /// - /// Includes specified types to resulting typing exported as TypeScript enumerations + /// Includes specified types to resulting typing exported as TypeScript enumerations /// /// Configuration builder /// Types to include /// Configuration to be applied to each type /// Fluent - public static void ExportAsEnums(this ConfigurationBuilder builder, IEnumerable types, Action configuration = null) + public static void ExportAsEnums(this ConfigurationBuilder builder, IEnumerable types, + Action configuration = null) { foreach (var type in types) { var tp = type; var conf = builder.EnumConfigurationBuilders.GetOrCreate(type, () => { - var t = typeof(EnumConfigurationBuilder<>).MakeGenericType(tp); - return (IEnumConfigurationBuidler)Activator.CreateInstance(t, nonPublic: true); + var t = typeof (EnumConfigurationBuilder<>).MakeGenericType(tp); + return (IEnumConfigurationBuidler) Activator.CreateInstance(t, true); }); if (configuration != null) configuration(conf); } } /// - /// Retrieves configuration builder for particular enumeration value + /// Retrieves configuration builder for particular enumeration value /// /// Enumeration type /// Configuration builder @@ -515,15 +645,15 @@ public static void ExportAsEnums(this ConfigurationBuilder builder, IEnumerable< public static EnumValueExportConfiguration Value(this EnumConfigurationBuilder conf, T value) where T : struct { - var n = Enum.GetName(typeof(T), value); - var field = typeof(T).GetField(n); + var n = Enum.GetName(typeof (T), value); + var field = typeof (T).GetField(n); IEnumConfigurationBuidler ecb = conf; var c = ecb.ValueExportConfigurations.GetOrCreate(field, () => new EnumValueExportConfiguration()); return c; } /// - /// Retrieves configuration builder for particular enumeration value + /// Retrieves configuration builder for particular enumeration value /// /// Configuration builder /// String enum property name @@ -534,65 +664,7 @@ public static EnumValueExportConfiguration Value(this IEnumConfigurationBuidler var c = conf.ValueExportConfigurations.GetOrCreate(field, () => new EnumValueExportConfiguration()); return c; } - #endregion - - private static void ExtractParameters(ITypeConfigurationBuilder conf, LambdaExpression methodLambda) - { - var mex = methodLambda.Body as MethodCallExpression; - if (mex == null) throw new Exception("MethodCallExpression should be provided for .WithMethod call. Please use only lamba expressions in this place."); - var mi = mex.Method; - - var methodParameters = mi.GetParameters(); - if (methodParameters.Length == 0) return; - - - int i = 0; - foreach (var expression in mex.Arguments) - { - ParameterInfo pi = methodParameters[i]; - i++; - var call = expression as MethodCallExpression; - if (call != null) - { - if (call.Method.IsGenericMethod && call.Method.GetGenericMethodDefinition() == Ts.ParametrizedParameterMethod) - { - ParameterConfigurationBuilder pcb = (ParameterConfigurationBuilder)conf.ParametersConfiguration.GetOrCreate(pi, () => new ParameterConfigurationBuilder()); - - bool parsed = false; - var arg = call.Arguments[0] as LambdaExpression; - if (arg != null) - { - var delg = arg.Compile(); - delg.DynamicInvoke(pcb); - parsed = true; - } - var uarg = call.Arguments[0] as UnaryExpression; // convert expression - if (uarg != null) - { - var operand = uarg.Operand as MethodCallExpression; - if (operand != null) - { - var actionArg = operand.Object as ConstantExpression; - if (actionArg != null) - { - var value = actionArg.Value as MethodInfo; - if (value != null) - { - var param = Expression.Parameter(typeof(ParameterConfigurationBuilder)); - var newCall = Expression.Call(value, param); - var newLambda = Expression.Lambda(newCall, param); - var delg = newLambda.Compile(); - delg.DynamicInvoke(pcb); - parsed = true; - } - } - } - if (!parsed) throw new Exception(String.Format("Sorry, but {0} is not very good idea for parameter configuration. Try using simple lambda expression.", call.Arguments[0])); - } - } - } - } - } + #endregion } -} +} \ No newline at end of file diff --git a/Reinforced.Typings/Fluent/EnumConfigurationBuilder.cs b/Reinforced.Typings/Fluent/EnumConfigurationBuilder.cs index 229c754b..3d5eacdd 100644 --- a/Reinforced.Typings/Fluent/EnumConfigurationBuilder.cs +++ b/Reinforced.Typings/Fluent/EnumConfigurationBuilder.cs @@ -1,47 +1,50 @@ using System; using System.Collections.Generic; -using System.Linq; using System.Reflection; -using System.Text; -using System.Threading.Tasks; using Reinforced.Typings.Attributes; using Reinforced.Typings.Fluent.Interfaces; namespace Reinforced.Typings.Fluent { /// - /// Configuration builder for Enum type + /// Configuration builder for Enum type /// /// public class EnumConfigurationBuilder : IEnumConfigurationBuidler - where TEnum:struct + where TEnum : struct { - private readonly Dictionary _valueExportConfigurations = new Dictionary(); + private readonly ICollection _references = new List(); - Dictionary IEnumConfigurationBuidler.ValueExportConfigurations + private readonly Dictionary _valueExportConfigurations = + new Dictionary(); + + internal EnumConfigurationBuilder() { - get { return _valueExportConfigurations; } + AttributePrototype = new TsEnumAttribute(); } private TsEnumAttribute AttributePrototype { get; set; } - TsEnumAttribute IExportConfiguration.AttributePrototype + Dictionary IEnumConfigurationBuidler.ValueExportConfigurations { - get { return this.AttributePrototype; } + get { return _valueExportConfigurations; } } - internal EnumConfigurationBuilder() + TsEnumAttribute IExportConfiguration.AttributePrototype { - AttributePrototype = new TsEnumAttribute(); + get { return AttributePrototype; } } - Type IEnumConfigurationBuidler.EnumType { get { return typeof (TEnum); } } - - private readonly ICollection _references = new List(); + Type IEnumConfigurationBuidler.EnumType + { + get { return typeof (TEnum); } + } ICollection IReferenceConfigurationBuilder.References { - get { return this._references; } + get { return _references; } } + + string IReferenceConfigurationBuilder.PathToFile { get; set; } } -} +} \ No newline at end of file diff --git a/Reinforced.Typings/Fluent/EnumValueExportConfiguration.cs b/Reinforced.Typings/Fluent/EnumValueExportConfiguration.cs index d514c792..e1970de4 100644 --- a/Reinforced.Typings/Fluent/EnumValueExportConfiguration.cs +++ b/Reinforced.Typings/Fluent/EnumValueExportConfiguration.cs @@ -4,22 +4,22 @@ namespace Reinforced.Typings.Fluent { /// - /// Configuration for enum value export configuration + /// Configuration for enum value export configuration /// public class EnumValueExportConfiguration : IExportConfiguration, IIgnorable { - bool IIgnorable.Ignore { get; set; } + internal EnumValueExportConfiguration() + { + AttributePrototype = new TsValueAttribute(); + } internal TsValueAttribute AttributePrototype { get; set; } TsValueAttribute IExportConfiguration.AttributePrototype { - get { return this.AttributePrototype; } + get { return AttributePrototype; } } - internal EnumValueExportConfiguration() - { - AttributePrototype = new TsValueAttribute(); - } + bool IIgnorable.Ignore { get; set; } } } \ No newline at end of file diff --git a/Reinforced.Typings/Fluent/InterfaceConfigurationBuilder.cs b/Reinforced.Typings/Fluent/InterfaceConfigurationBuilder.cs index b030d709..1e6cbd43 100644 --- a/Reinforced.Typings/Fluent/InterfaceConfigurationBuilder.cs +++ b/Reinforced.Typings/Fluent/InterfaceConfigurationBuilder.cs @@ -1,33 +1,29 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using Reinforced.Typings.Attributes; +using Reinforced.Typings.Attributes; using Reinforced.Typings.Fluent.Interfaces; namespace Reinforced.Typings.Fluent { /// - /// Configuration builder for interface + /// Configuration builder for interface /// /// - public class InterfaceConfigurationBuilder : TypeConfigurationBuilder, IInterfaceConfigurationBuilder + public class InterfaceConfigurationBuilder : TypeConfigurationBuilder, + IInterfaceConfigurationBuilder { - private TsInterfaceAttribute AttributePrototype { get; set; } - - TsInterfaceAttribute IExportConfiguration.AttributePrototype - { - get { return this.AttributePrototype; } - } - internal InterfaceConfigurationBuilder() { - AttributePrototype = new TsInterfaceAttribute() + AttributePrototype = new TsInterfaceAttribute { AutoExportProperties = false, AutoExportMethods = false }; } + + private TsInterfaceAttribute AttributePrototype { get; set; } + + TsInterfaceAttribute IExportConfiguration.AttributePrototype + { + get { return AttributePrototype; } + } } -} +} \ No newline at end of file diff --git a/Reinforced.Typings/Fluent/Interfaces/IClassConfigurationBuilder.cs b/Reinforced.Typings/Fluent/Interfaces/IClassConfigurationBuilder.cs index bf331bf0..e04aaca3 100644 --- a/Reinforced.Typings/Fluent/Interfaces/IClassConfigurationBuilder.cs +++ b/Reinforced.Typings/Fluent/Interfaces/IClassConfigurationBuilder.cs @@ -3,11 +3,10 @@ namespace Reinforced.Typings.Fluent.Interfaces { /// - /// Technical interface for class configuration builder + /// Technical interface for class configuration builder /// public interface IClassConfigurationBuilder : ITypeConfigurationBuilder, IExportConfiguration { - } } \ No newline at end of file diff --git a/Reinforced.Typings/Fluent/Interfaces/IEnumConfigurationBuidler.cs b/Reinforced.Typings/Fluent/Interfaces/IEnumConfigurationBuidler.cs index 5d886f5a..a6dc5af3 100644 --- a/Reinforced.Typings/Fluent/Interfaces/IEnumConfigurationBuidler.cs +++ b/Reinforced.Typings/Fluent/Interfaces/IEnumConfigurationBuidler.cs @@ -6,17 +6,17 @@ namespace Reinforced.Typings.Fluent.Interfaces { /// - /// Technical interface for enumeration configuration builder + /// Technical interface for enumeration configuration builder /// public interface IEnumConfigurationBuidler : IExportConfiguration, IReferenceConfigurationBuilder { /// - /// Type of enumeration + /// Type of enumeration /// Type EnumType { get; } - + /// - /// Configurations for exported particular enumeration values + /// Configurations for exported particular enumeration values /// Dictionary ValueExportConfigurations { get; } } diff --git a/Reinforced.Typings/Fluent/Interfaces/IExportConfiguration.cs b/Reinforced.Typings/Fluent/Interfaces/IExportConfiguration.cs index 99f599f0..b40e6d4a 100644 --- a/Reinforced.Typings/Fluent/Interfaces/IExportConfiguration.cs +++ b/Reinforced.Typings/Fluent/Interfaces/IExportConfiguration.cs @@ -1,13 +1,13 @@ namespace Reinforced.Typings.Fluent.Interfaces { /// - /// Core fluent export configuration interface + /// Core fluent export configuration interface /// /// Attribute prototype for specified member public interface IExportConfiguration { /// - /// Attribute prototype + /// Attribute prototype /// TAttributePrototype AttributePrototype { get; } } diff --git a/Reinforced.Typings/Fluent/Interfaces/IIgnorable.cs b/Reinforced.Typings/Fluent/Interfaces/IIgnorable.cs index 63accf10..c7427754 100644 --- a/Reinforced.Typings/Fluent/Interfaces/IIgnorable.cs +++ b/Reinforced.Typings/Fluent/Interfaces/IIgnorable.cs @@ -1,13 +1,13 @@ namespace Reinforced.Typings.Fluent.Interfaces { /// - /// Configuration for members that are supporting ignoring + /// Configuration for members that are supporting ignoring /// public interface IIgnorable { /// - /// Ignore flag + /// Ignore flag /// bool Ignore { get; set; } } -} +} \ No newline at end of file diff --git a/Reinforced.Typings/Fluent/Interfaces/IInterfaceConfigurationBuilder.cs b/Reinforced.Typings/Fluent/Interfaces/IInterfaceConfigurationBuilder.cs index 0bc1199d..b446d784 100644 --- a/Reinforced.Typings/Fluent/Interfaces/IInterfaceConfigurationBuilder.cs +++ b/Reinforced.Typings/Fluent/Interfaces/IInterfaceConfigurationBuilder.cs @@ -3,11 +3,10 @@ namespace Reinforced.Typings.Fluent.Interfaces { /// - /// Technical interface for interface configuration builder + /// Technical interface for interface configuration builder /// public interface IInterfaceConfigurationBuilder : ITypeConfigurationBuilder, IExportConfiguration { - } } \ No newline at end of file diff --git a/Reinforced.Typings/Fluent/Interfaces/IReferenceConfigurationBuilder.cs b/Reinforced.Typings/Fluent/Interfaces/IReferenceConfigurationBuilder.cs index d6b65dc3..2ce47d6e 100644 --- a/Reinforced.Typings/Fluent/Interfaces/IReferenceConfigurationBuilder.cs +++ b/Reinforced.Typings/Fluent/Interfaces/IReferenceConfigurationBuilder.cs @@ -4,13 +4,18 @@ namespace Reinforced.Typings.Fluent.Interfaces { /// - /// Configuration interface for members supporting custom typescript-per-file references + /// Configuration interface for members supporting custom typescript-per-file references /// public interface IReferenceConfigurationBuilder { /// - /// Reference paths list + /// Reference paths list /// ICollection References { get; } + + /// + /// Path to file where to put generated code + /// + string PathToFile { get; set; } } -} +} \ No newline at end of file diff --git a/Reinforced.Typings/Fluent/Interfaces/ITypeConfigurationBuilder.cs b/Reinforced.Typings/Fluent/Interfaces/ITypeConfigurationBuilder.cs index aafd64c3..9b3c6261 100644 --- a/Reinforced.Typings/Fluent/Interfaces/ITypeConfigurationBuilder.cs +++ b/Reinforced.Typings/Fluent/Interfaces/ITypeConfigurationBuilder.cs @@ -6,23 +6,23 @@ namespace Reinforced.Typings.Fluent.Interfaces { /// - /// Technical interface for type (class/interface) configuration builder + /// Technical interface for type (class/interface) configuration builder /// public interface ITypeConfigurationBuilder : IReferenceConfigurationBuilder { /// - /// Configurations for method parameters + /// Configurations for method parameters /// Dictionary> ParametersConfiguration { get; } /// - /// Configurations for type members + /// Configurations for type members /// Dictionary> MembersConfiguration { get; } /// - /// Type is being configured + /// Type is being configured /// - Type Type { get; } + Type Type { get; } } } \ No newline at end of file diff --git a/Reinforced.Typings/Fluent/LambdaHelpers.cs b/Reinforced.Typings/Fluent/LambdaHelpers.cs index 707ea833..5087acc6 100644 --- a/Reinforced.Typings/Fluent/LambdaHelpers.cs +++ b/Reinforced.Typings/Fluent/LambdaHelpers.cs @@ -5,13 +5,12 @@ namespace Reinforced.Typings.Fluent { /// - /// Set of helper reflection methods + /// Set of helper reflection methods /// internal static class LambdaHelpers { - /// - /// Parses supplied lambda expression and retrieves PropertyInfo from it + /// Parses supplied lambda expression and retrieves PropertyInfo from it /// /// T1 /// T2 @@ -27,7 +26,7 @@ public static PropertyInfo ParsePropertyLambda(Expression> } /// - /// Parses supplied lambda expression and retrieves PropertyInfo from it + /// Parses supplied lambda expression and retrieves PropertyInfo from it /// /// Property Lambda expression /// PropertyInfo referenced by this expression @@ -41,7 +40,7 @@ public static PropertyInfo ParsePropertyLambda(LambdaExpression lambda) } /// - /// Parses supplied lambda expression and retrieves PropertyInfo from it + /// Parses supplied lambda expression and retrieves PropertyInfo from it /// /// T1 /// T2 @@ -57,7 +56,7 @@ public static FieldInfo ParseFieldLambda(Expression> lambda } /// - /// Parses supplied lambda expression and retrieves PropertyInfo from it + /// Parses supplied lambda expression and retrieves PropertyInfo from it /// /// Property Lambda expression /// PropertyInfo referenced by this expression @@ -71,15 +70,17 @@ public static FieldInfo ParseFieldLambda(LambdaExpression lambda) } /// - /// Parses supplied lambda expression and retrieves PropertyInfo from it + /// Parses supplied lambda expression and retrieves PropertyInfo from it /// /// Property Lambda expression /// PropertyInfo referenced by this expression public static MethodInfo ParseMethodLambda(LambdaExpression lambda) { var mex = lambda.Body as MethodCallExpression; - if (mex == null) throw new Exception("MethodCallExpression should be provided for .WithMethod call. Please use only lamba expressions in this place."); + if (mex == null) + throw new Exception( + "MethodCallExpression should be provided for .WithMethod call. Please use only lamba expressions in this place."); return mex.Method; } } -} +} \ No newline at end of file diff --git a/Reinforced.Typings/Fluent/MethodExportConfiguration.cs b/Reinforced.Typings/Fluent/MethodExportConfiguration.cs index 5b1d37a5..d9e96323 100644 --- a/Reinforced.Typings/Fluent/MethodExportConfiguration.cs +++ b/Reinforced.Typings/Fluent/MethodExportConfiguration.cs @@ -4,21 +4,22 @@ namespace Reinforced.Typings.Fluent { /// - /// Fluent configuration builder for exported methods + /// Fluent configuration builder for exported methods /// public class MethodExportConfiguration : IExportConfiguration, IIgnorable { - bool IIgnorable.Ignore { get; set; } + internal MethodExportConfiguration() + { + AttributePrototype = new TsFunctionAttribute(); + } + private TsFunctionAttribute AttributePrototype { get; set; } TsFunctionAttribute IExportConfiguration.AttributePrototype { - get { return this.AttributePrototype; } + get { return AttributePrototype; } } - internal MethodExportConfiguration() - { - AttributePrototype = new TsFunctionAttribute(); - } + bool IIgnorable.Ignore { get; set; } } } \ No newline at end of file diff --git a/Reinforced.Typings/Fluent/Parameter.cs b/Reinforced.Typings/Fluent/Parameter.cs index 47ac023f..5d281ca0 100644 --- a/Reinforced.Typings/Fluent/Parameter.cs +++ b/Reinforced.Typings/Fluent/Parameter.cs @@ -1,20 +1,24 @@ using System; -using System.Collections.Generic; -using System.Linq; using System.Linq.Expressions; using System.Reflection; -using System.Text; -using System.Threading.Tasks; namespace Reinforced.Typings.Fluent { /// - /// Shortcut for method parameters mocking + /// Shortcut for method parameters mocking /// public class Ts { + internal static MethodInfo ParametrizedParameterMethod; + + static Ts() + { + Expression> lambda = () => Parameter(a => a.Ignore()); + ParametrizedParameterMethod = LambdaHelpers.ParseMethodLambda(lambda).GetGenericMethodDefinition(); + } + /// - /// Parameter mock for specified type + /// Parameter mock for specified type /// /// Parameter type /// Mock @@ -24,7 +28,7 @@ public static T Parameter() } /// - /// Parameter mock with parameter configuration + /// Parameter mock with parameter configuration /// /// Parameter type /// Fluent parameter configuration @@ -33,13 +37,5 @@ public static T Parameter(Action configuration { return default(T); } - - internal static MethodInfo ParametrizedParameterMethod; - - static Ts() - { - Expression> lambda = () => Parameter(a => a.Ignore()); - ParametrizedParameterMethod = LambdaHelpers.ParseMethodLambda(lambda).GetGenericMethodDefinition(); - } } -} +} \ No newline at end of file diff --git a/Reinforced.Typings/Fluent/ParameterConfigurationBuilder.cs b/Reinforced.Typings/Fluent/ParameterConfigurationBuilder.cs index 4be72388..a30565d1 100644 --- a/Reinforced.Typings/Fluent/ParameterConfigurationBuilder.cs +++ b/Reinforced.Typings/Fluent/ParameterConfigurationBuilder.cs @@ -4,20 +4,22 @@ namespace Reinforced.Typings.Fluent { /// - /// Parameter configuration builder + /// Parameter configuration builder /// public class ParameterConfigurationBuilder : IExportConfiguration, IIgnorable { - bool IIgnorable.Ignore { get; set; } - private TsParameterAttribute AttributePrototype { get; set; } - TsParameterAttribute IExportConfiguration.AttributePrototype + internal ParameterConfigurationBuilder() { - get { return this.AttributePrototype; } + AttributePrototype = new TsParameterAttribute(); } - internal ParameterConfigurationBuilder() + private TsParameterAttribute AttributePrototype { get; set; } + + TsParameterAttribute IExportConfiguration.AttributePrototype { - AttributePrototype = new TsParameterAttribute(); + get { return AttributePrototype; } } + + bool IIgnorable.Ignore { get; set; } } -} +} \ No newline at end of file diff --git a/Reinforced.Typings/Fluent/PropertyExportConfiguration.cs b/Reinforced.Typings/Fluent/PropertyExportConfiguration.cs index 686729be..4e3272e2 100644 --- a/Reinforced.Typings/Fluent/PropertyExportConfiguration.cs +++ b/Reinforced.Typings/Fluent/PropertyExportConfiguration.cs @@ -4,19 +4,22 @@ namespace Reinforced.Typings.Fluent { /// - /// Fluent configuration builder for exported properties + /// Fluent configuration builder for exported properties /// public class PropertyExportConfiguration : IExportConfiguration, IIgnorable { - bool IIgnorable.Ignore { get; set; } - private TsPropertyAttribute AttributePrototype { get; set; } - TsPropertyAttribute IExportConfiguration.AttributePrototype - { - get { return this.AttributePrototype; } - } internal PropertyExportConfiguration() { AttributePrototype = new TsPropertyAttribute(); } + + private TsPropertyAttribute AttributePrototype { get; set; } + + TsPropertyAttribute IExportConfiguration.AttributePrototype + { + get { return AttributePrototype; } + } + + bool IIgnorable.Ignore { get; set; } } } \ No newline at end of file diff --git a/Reinforced.Typings/Fluent/TypeConfigurationBuilder.cs b/Reinforced.Typings/Fluent/TypeConfigurationBuilder.cs index b1d74dd8..6e729783 100644 --- a/Reinforced.Typings/Fluent/TypeConfigurationBuilder.cs +++ b/Reinforced.Typings/Fluent/TypeConfigurationBuilder.cs @@ -1,42 +1,46 @@ using System; using System.Collections.Generic; -using System.Linq; using System.Reflection; -using System.Text; -using System.Threading.Tasks; using Reinforced.Typings.Attributes; using Reinforced.Typings.Fluent.Interfaces; namespace Reinforced.Typings.Fluent { /// - /// Configuration builder for type + /// Configuration builder for type /// /// public abstract class TypeConfigurationBuilder : ITypeConfigurationBuilder { - Type ITypeConfigurationBuilder.Type { get { return typeof(TType); } } + private readonly Dictionary> _membersConfiguration = + new Dictionary>(); - private readonly Dictionary> _membersConfiguration = new Dictionary>(); - private readonly Dictionary> _parametersConfiguration = new Dictionary>(); + private readonly Dictionary> _parametersConfiguration + = new Dictionary>(); + private readonly ICollection _references = new List(); - Dictionary> ITypeConfigurationBuilder.ParametersConfiguration + Type ITypeConfigurationBuilder.Type { - get { return _parametersConfiguration; } + get { return typeof (TType); } } + Dictionary> ITypeConfigurationBuilder. + ParametersConfiguration + { + get { return _parametersConfiguration; } + } Dictionary> ITypeConfigurationBuilder.MembersConfiguration { get { return _membersConfiguration; } } - private readonly ICollection _references = new List(); - ICollection IReferenceConfigurationBuilder.References { - get { return this._references; } + get { return _references; } } + + string IReferenceConfigurationBuilder.PathToFile { get; set; } } -} +} \ No newline at end of file diff --git a/Reinforced.Typings/Fluent/TypingsConfigurationExtensions.cs b/Reinforced.Typings/Fluent/TypingsConfigurationExtensions.cs index a9bcdec9..1510e388 100644 --- a/Reinforced.Typings/Fluent/TypingsConfigurationExtensions.cs +++ b/Reinforced.Typings/Fluent/TypingsConfigurationExtensions.cs @@ -8,12 +8,12 @@ namespace Reinforced.Typings.Fluent { /// - /// Extensions for fluent configuration + /// Extensions for fluent configuration /// public static class TypingsConfigurationExtensions { /// - /// Ignores specified mambers during exporting + /// Ignores specified mambers during exporting /// public static T Ignore(this T conf) where T : IIgnorable { @@ -22,10 +22,12 @@ public static T Ignore(this T conf) where T : IIgnorable } #region CodeGenerator extensions + /// - /// Specifies code generator for member + /// Specifies code generator for member /// - public static IExportConfiguration WithCodeGenerator(this IExportConfiguration conf) + public static IExportConfiguration WithCodeGenerator( + this IExportConfiguration conf) where T : ITsCodeGenerator { conf.AttributePrototype.CodeGeneratorType = typeof (T); @@ -33,80 +35,102 @@ public static IExportConfiguration WithCodeGenerator(this I } /// - /// Specifies code generator for member + /// Specifies code generator for member /// - public static IExportConfiguration WithCodeGenerator(this IExportConfiguration conf) + public static IExportConfiguration WithCodeGenerator( + this IExportConfiguration conf) where T : ITsCodeGenerator { - conf.AttributePrototype.CodeGeneratorType = typeof(T); + conf.AttributePrototype.CodeGeneratorType = typeof (T); return conf; } /// - /// Specifies code generator for member + /// Specifies code generator for member /// - public static IExportConfiguration WithCodeGenerator(this IExportConfiguration conf) + public static IExportConfiguration WithCodeGenerator( + this IExportConfiguration conf) where T : ITsCodeGenerator { - conf.AttributePrototype.CodeGeneratorType = typeof(T); + conf.AttributePrototype.CodeGeneratorType = typeof (T); return conf; } /// - /// Specifies code generator for member + /// Specifies code generator for member /// - public static IExportConfiguration WithCodeGenerator(this IExportConfiguration conf) + public static IExportConfiguration WithCodeGenerator( + this IExportConfiguration conf) where T : ITsCodeGenerator { - conf.AttributePrototype.CodeGeneratorType = typeof(T); + conf.AttributePrototype.CodeGeneratorType = typeof (T); return conf; } /// - /// Specifies code generator for member + /// Specifies code generator for member /// - public static IExportConfiguration WithCodeGenerator(this IExportConfiguration conf) + public static IExportConfiguration WithCodeGenerator( + this IExportConfiguration conf) where T : ITsCodeGenerator { - conf.AttributePrototype.CodeGeneratorType = typeof(T); + conf.AttributePrototype.CodeGeneratorType = typeof (T); return conf; } /// - /// Specifies code generator for member + /// Specifies code generator for member /// - public static IExportConfiguration WithCodeGenerator(this IExportConfiguration conf) + public static IExportConfiguration WithCodeGenerator( + this IExportConfiguration conf) where T : ITsCodeGenerator { - conf.AttributePrototype.CodeGeneratorType = typeof(T); + conf.AttributePrototype.CodeGeneratorType = typeof (T); return conf; } + #endregion #region Reference extensions /// - /// Adds reference directive to file containing single TS class typing. - /// This method is only used while splitting generated types to different files + /// Adds reference directive to file containing single TS class typing. + /// This method is only used while splitting generated types to different files /// /// Configurator /// Path to referenced file - public static T AddReference(this T configuration,string referenceFile) where T : IReferenceConfigurationBuilder + public static T AddReference(this T configuration, string referenceFile) + where T : IReferenceConfigurationBuilder { configuration.References.Add(new TsAddTypeReferenceAttribute(referenceFile)); return configuration; } + /// - /// Adds reference directive to file containing single TS class typing. - /// This method is only used while splitting generated types to different files + /// Adds reference directive to file containing single TS class typing. + /// This method is only used while splitting generated types to different files /// /// Configurator /// Another generated type that should be referenced - public static T AddReference(this T configuration, Type referencedType) where T : IReferenceConfigurationBuilder + public static T AddReference(this T configuration, Type referencedType) + where T : IReferenceConfigurationBuilder { configuration.References.Add(new TsAddTypeReferenceAttribute(referencedType)); return configuration; } + + /// + /// Overrides target file name where specified name will be exported. + /// This option will only be processed when RtDivideTypesAmongFiles is true. + /// + /// Configurator + /// Target file path override. Related to RtTargetDirectory + public static T ExportTo(this T configuration, string fileName) where T : IReferenceConfigurationBuilder + { + configuration.PathToFile = fileName; + return configuration; + } + #endregion #region Auto export control - temporary disabled @@ -168,11 +192,13 @@ public static T AddReference(this T configuration, Type referencedType) where // conf.AttributePrototype.DefaultMethodCodeGenerator = typeof(T); // return conf; //} + #endregion #region Names and namespaces + /// - /// Overrides name of specified member + /// Overrides name of specified member /// /// Configuration /// Custom name to be used @@ -183,7 +209,7 @@ public static T OverrideName(this T conf, string name) where T : IExportConfi } /// - /// Forces member name to be camelCase + /// Forces member name to be camelCase /// /// Configuration public static T CamelCase(this T conf) where T : IExportConfiguration @@ -193,31 +219,35 @@ public static T CamelCase(this T conf) where T : IExportConfiguration - /// Configures exporter dont to export member to corresponding namespace + /// Configures exporter dont to export member to corresponding namespace /// - public static T DontIncludeToNamespace(this T conf,bool include = false) where T : IExportConfiguration + public static T DontIncludeToNamespace(this T conf, bool include = false) + where T : IExportConfiguration { conf.AttributePrototype.IncludeNamespace = include; return conf; } /// - /// Configures exporter to export type to specified namespace + /// Configures exporter to export type to specified namespace /// /// Configuration /// Namespace name - public static T OverrideNamespace(this T conf, string nameSpace) where T : IExportConfiguration + public static T OverrideNamespace(this T conf, string nameSpace) + where T : IExportConfiguration { conf.AttributePrototype.Namespace = nameSpace; return conf; } + #endregion #region Types and strong types + /// - /// Overrides member type name on export with textual string. - /// Beware of using this setting because specified type may not present in your TypeScript code and - /// this will lead to TypeScript compilation errors + /// Overrides member type name on export with textual string. + /// Beware of using this setting because specified type may not present in your TypeScript code and + /// this will lead to TypeScript compilation errors /// /// Configurator /// TS-friendly type name @@ -229,19 +259,20 @@ public static T Type(this T conf, string typeName) where T : IExportConfigura } /// - /// Overrides member type on export with strong type. - /// Feel free to use delegates here. It is very comfortable instead of regular TS functions syntax. + /// Overrides member type on export with strong type. + /// Feel free to use delegates here. It is very comfortable instead of regular TS functions syntax. /// /// Configurator - public static IExportConfiguration Type(this IExportConfiguration conf) + public static IExportConfiguration Type( + this IExportConfiguration conf) { - conf.AttributePrototype.StrongType = typeof(T); + conf.AttributePrototype.StrongType = typeof (T); return conf; } /// - /// Overrides member type on export with strong type. - /// Feel free to use delegates here. It is very comfortable instead of regular TS functions syntax. + /// Overrides member type on export with strong type. + /// Feel free to use delegates here. It is very comfortable instead of regular TS functions syntax. /// /// Configurator /// Type to override with @@ -253,11 +284,12 @@ public static T Type(this T conf, Type type) where T : IExportConfiguration - /// Overrides member type name on export with textual string. - /// Beware of using this setting because specified type may not present in your TypeScript code and - /// this will lead to TypeScript compilation errors. - /// Actually this method does the same as .Type call. Just for your convinence + /// Overrides member type name on export with textual string. + /// Beware of using this setting because specified type may not present in your TypeScript code and + /// this will lead to TypeScript compilation errors. + /// Actually this method does the same as .Type call. Just for your convinence /// /// Configurator /// TS-friendly type name @@ -269,21 +301,22 @@ public static T Returns(this T conf, string typeName) where T : IExportConfig } /// - /// Overrides member type on export with strong type. - /// Feel free to use delegates here. It is very comfortable instead of regular TS functions syntax. - /// Actually this method does the same as .Type call. Just for your convinence + /// Overrides member type on export with strong type. + /// Feel free to use delegates here. It is very comfortable instead of regular TS functions syntax. + /// Actually this method does the same as .Type call. Just for your convinence /// /// Configurator - public static IExportConfiguration Returns(this IExportConfiguration conf) + public static IExportConfiguration Returns( + this IExportConfiguration conf) { - conf.AttributePrototype.StrongType = typeof(T); + conf.AttributePrototype.StrongType = typeof (T); return conf; } /// - /// Overrides member type on export with strong type. - /// Feel free to use delegates here. It is very comfortable instead of regular TS functions syntax. - /// Actually this method does the same as .Type call. Just for your convinence + /// Overrides member type on export with strong type. + /// Feel free to use delegates here. It is very comfortable instead of regular TS functions syntax. + /// Actually this method does the same as .Type call. Just for your convinence /// /// Configurator /// Type to override with @@ -293,29 +326,29 @@ public static T Returns(this T conf, Type type) where T : IExportConfiguratio conf.AttributePrototype.StrongType = type; return conf; } - #endregion - - + #endregion #endregion #region Various and specific + /// - /// Forces property to be a nullable. - /// When set to true then property will be generated as [property]? : [type] with - /// forcibly added question mark denoting nullable field. + /// Forces property to be a nullable. + /// When set to true then property will be generated as [property]? : [type] with + /// forcibly added question mark denoting nullable field. /// /// Configuration /// Force nullable or not - public static T ForceNullable(this T conf, bool force = false) where T : IExportConfiguration + public static T ForceNullable(this T conf, bool force = false) + where T : IExportConfiguration { conf.AttributePrototype.ForceNullable = force; return conf; } /// - /// Sets parameter default value. + /// Sets parameter default value. /// /// Configuration /// Default value for parameter @@ -326,7 +359,7 @@ public static T DefaultValue(this T conf, object value) where T : IExportConf } /// - /// Forces exporter to add I letter as interface prefix. + /// Forces exporter to add I letter as interface prefix. /// /// Configuration /// Add I automatically or not @@ -337,7 +370,7 @@ public static T AutoI(this T conf, bool auto = true) where T : IExportConfigu } /// - /// Adds global reference to another typescript library + /// Adds global reference to another typescript library /// /// Table configurator /// Full path to .d.ts or .ts file @@ -349,16 +382,19 @@ public static ConfigurationBuilder AddReference(this ConfigurationBuilder conf, } /// - /// Tries to find documentation .xml file for specified assembly and take it in account when generating documentaion + /// Tries to find documentation .xml file for specified assembly and take it in account when generating documentaion /// /// Table configurator /// Assembly which documentation should be included /// Override XMLDOC file name if differs (please include .xml extension) /// Fluent - public static ConfigurationBuilder TryLookupDocumentationForAssembly(this ConfigurationBuilder conf, Assembly assmbly,string documentationFileName = null) + public static ConfigurationBuilder TryLookupDocumentationForAssembly(this ConfigurationBuilder conf, + Assembly assmbly, string documentationFileName = null) { var assemblyDir = Path.GetDirectoryName(assmbly.Location); - var file = String.IsNullOrEmpty(documentationFileName) ? Path.GetFileNameWithoutExtension(assmbly.Location) + ".xml" : documentationFileName; + var file = string.IsNullOrEmpty(documentationFileName) + ? Path.GetFileNameWithoutExtension(assmbly.Location) + ".xml" + : documentationFileName; var filePath = Path.Combine(assemblyDir, file); if (File.Exists(filePath)) { @@ -369,4 +405,4 @@ public static ConfigurationBuilder TryLookupDocumentationForAssembly(this Config #endregion } -} +} \ No newline at end of file diff --git a/Reinforced.Typings/Generators/ClassCodeGenerator.cs b/Reinforced.Typings/Generators/ClassCodeGenerator.cs index de329906..6ada2d98 100644 --- a/Reinforced.Typings/Generators/ClassCodeGenerator.cs +++ b/Reinforced.Typings/Generators/ClassCodeGenerator.cs @@ -2,18 +2,18 @@ using System.Collections.Generic; using System.Linq; using System.Reflection; -using System.Runtime.CompilerServices; using Reinforced.Typings.Attributes; namespace Reinforced.Typings.Generators { /// - /// Default code generator for CLR type (class) + /// Default code generator for CLR type (class) /// public class ClassCodeGenerator : ITsCodeGenerator { /// - /// Main code generator method. This method should write corresponding TypeScript code for element (1st argument) to WriterWrapper (3rd argument) using TypeResolver if necessary + /// Main code generator method. This method should write corresponding TypeScript code for element (1st argument) to + /// WriterWrapper (3rd argument) using TypeResolver if necessary /// /// Element code to be generated to output /// Type resolver @@ -26,21 +26,25 @@ public virtual void Generate(Type element, TypeResolver resolver, WriterWrapper } /// - /// Export settings + /// Export settings /// public ExportSettings Settings { get; set; } /// - /// Exports entire class to specified writer + /// Exports entire class to specified writer /// - /// Declaration type. Used in "export $gt;class< ... " line. This parameter allows switch it to "interface" + /// + /// Declaration type. Used in "export $gt;class< ... " line. This parameter allows switch it to + /// "interface" + /// /// Exporting class type /// Type resolver /// Output writer /// Pass here type attribute inherited from IAutoexportSwitchAttribute - protected virtual void Export(string declType, Type type, TypeResolver resolver, WriterWrapper sw, IAutoexportSwitchAttribute swtch) + protected virtual void Export(string declType, Type type, TypeResolver resolver, WriterWrapper sw, + IAutoexportSwitchAttribute swtch) { - string name = type.GetName(); + var name = type.GetName(); Settings.Documentation.WriteDocumentation(type, sw); sw.Indent(); @@ -51,8 +55,8 @@ protected virtual void Export(string declType, Type type, TypeResolver resolver, var ifaces = type.GetInterfaces(); var bs = type.BaseType; - bool baseClassIsExportedAsInterface = false; - if (bs != null && bs != typeof(object)) + var baseClassIsExportedAsInterface = false; + if (bs != null && bs != typeof (object)) { if (ConfigurationRepository.Instance.ForType(bs) != null) { @@ -63,15 +67,16 @@ protected virtual void Export(string declType, Type type, TypeResolver resolver, } } } - var ifacesStrings = ifaces.Where(c => ConfigurationRepository.Instance.ForType(c) != null) - .Select(resolver.ResolveTypeName).ToList(); + var ifacesStrings = + ifaces.Where(c => ConfigurationRepository.Instance.ForType(c) != null) + .Select(resolver.ResolveTypeName).ToList(); if (baseClassIsExportedAsInterface) { ifacesStrings.Add(resolver.ResolveTypeName(bs)); } if (ifacesStrings.Any()) { - string implemets = String.Join(", ", ifacesStrings); + var implemets = string.Join(", ", ifacesStrings); if (type.IsExportingAsInterface()) sw.Write(" extends {0}", implemets); else sw.Write(" implements {0}", implemets); } @@ -83,7 +88,7 @@ protected virtual void Export(string declType, Type type, TypeResolver resolver, } /// - /// Exports all type members sequentially + /// Exports all type members sequentially /// /// Type itself /// Type resolver @@ -100,13 +105,14 @@ protected virtual void ExportMembers(Type element, TypeResolver resolver, Writer } /// - /// Here you can customize what to export when base class is class but exporting as interface + /// Here you can customize what to export when base class is class but exporting as interface /// /// Type itself /// Type resolver /// Output writer /// Pass here type attribute inherited from IAutoexportSwitchAttribute - protected virtual void HandleBaseClassExportingAsInterface(Type element, TypeResolver resolver, WriterWrapper sw, IAutoexportSwitchAttribute swtch) + protected virtual void HandleBaseClassExportingAsInterface(Type element, TypeResolver resolver, WriterWrapper sw, + IAutoexportSwitchAttribute swtch) { if (element.BaseType != null) { @@ -118,7 +124,8 @@ protected virtual void HandleBaseClassExportingAsInterface(Type element, TypeRes // we do not export methods - just properties and fields // but still. It is better thatn nothing - Settings.Documentation.WriteComment(sw, String.Format("Automatically implemented from {0}", resolver.ResolveTypeName(element.BaseType))); + Settings.Documentation.WriteComment(sw, + string.Format("Automatically implemented from {0}", resolver.ResolveTypeName(element.BaseType))); var basExSwtch = ConfigurationRepository.Instance.ForType(element.BaseType); Settings.SpecialCase = true; ExportFields(element.BaseType, resolver, sw, basExSwtch); @@ -129,61 +136,46 @@ protected virtual void HandleBaseClassExportingAsInterface(Type element, TypeRes } /// - /// Exports type fields + /// Exports type fields /// /// Type itself /// Type resolver /// Output writer /// Pass here type attribute inherited from IAutoexportSwitchAttribute - protected virtual void ExportFields(Type element, TypeResolver resolver, WriterWrapper sw, IAutoexportSwitchAttribute swtch) + protected virtual void ExportFields(Type element, TypeResolver resolver, WriterWrapper sw, + IAutoexportSwitchAttribute swtch) { - var fields = - element.GetFields(TypeExtensions.MembersFlags) - .Where(TypeExtensions.TypeScriptMemberSearchPredicate) - .OfType(); - if (!swtch.AutoExportFields) - { - fields = fields.Where(c => ConfigurationRepository.Instance.ForMember(c) != null); - } - GenerateMembers(element, resolver, sw, fields); + GenerateMembers(element, resolver, sw, element.GetExportedFields()); } /// - /// Exports type properties + /// Exports type properties /// /// Type itself /// Type resolver /// Output writer /// Pass here type attribute inherited from IAutoexportSwitchAttribute - protected virtual void ExportProperties(Type element, TypeResolver resolver, WriterWrapper sw, IAutoexportSwitchAttribute swtch) + protected virtual void ExportProperties(Type element, TypeResolver resolver, WriterWrapper sw, + IAutoexportSwitchAttribute swtch) { - var properties = element.GetProperties(TypeExtensions.MembersFlags).Where(TypeExtensions.TypeScriptMemberSearchPredicate).OfType(); - if (!swtch.AutoExportProperties) - { - properties = properties.Where(c => ConfigurationRepository.Instance.ForMember(c) != null); - } - GenerateMembers(element, resolver, sw, properties); + GenerateMembers(element, resolver, sw, element.GetExportedProperties()); } /// - /// Exports type methods + /// Exports type methods /// /// Type itself /// Type resolver /// Output writer /// Pass here type attribute inherited from IAutoexportSwitchAttribute - protected virtual void ExportMethods(Type element, TypeResolver resolver, WriterWrapper sw, IAutoexportSwitchAttribute swtch) + protected virtual void ExportMethods(Type element, TypeResolver resolver, WriterWrapper sw, + IAutoexportSwitchAttribute swtch) { - var methods = element.GetMethods(TypeExtensions.MembersFlags).Where(c => TypeExtensions.TypeScriptMemberSearchPredicate(c) && !c.IsSpecialName); - if (!swtch.AutoExportMethods) - { - methods = methods.Where(c => ConfigurationRepository.Instance.ForMember(c) != null); - } - GenerateMembers(element, resolver, sw, methods); + GenerateMembers(element, resolver, sw, element.GetExportedMethods()); } /// - /// Exports type constructors + /// Exports type constructors /// /// Type itself /// Type resolver @@ -204,18 +196,17 @@ protected virtual void ExportConstructors(Type element, TypeResolver resolver, W } } - /// - /// Exports list of type members + /// Exports list of type members /// /// Type member type /// Exporting class /// Type resolver /// Output writer /// Type members to export - protected virtual void GenerateMembers(Type element, TypeResolver resolver, WriterWrapper sw, IEnumerable members) where T : MemberInfo + protected virtual void GenerateMembers(Type element, TypeResolver resolver, WriterWrapper sw, + IEnumerable members) where T : MemberInfo { - foreach (var m in members) { var generator = resolver.GeneratorFor(m, Settings); @@ -223,4 +214,4 @@ protected virtual void GenerateMembers(Type element, TypeResolver resolver, W } } } -} +} \ No newline at end of file diff --git a/Reinforced.Typings/Generators/ConstructorCodeGenerator.cs b/Reinforced.Typings/Generators/ConstructorCodeGenerator.cs index 3a5956ff..3b248f70 100644 --- a/Reinforced.Typings/Generators/ConstructorCodeGenerator.cs +++ b/Reinforced.Typings/Generators/ConstructorCodeGenerator.cs @@ -1,20 +1,17 @@ -using System; -using System.Collections.Generic; -using System.Linq; +using System.Linq; using System.Reflection; -using System.Text; -using System.Threading.Tasks; using Reinforced.Typings.Attributes; namespace Reinforced.Typings.Generators { /// - /// Default code generator for constructor + /// Default code generator for constructor /// public class ConstructorCodeGenerator : MethodCodeGenerator, ITsCodeGenerator { /// - /// Main code generator method. This method should write corresponding TypeScript code for element (1st argument) to WriterWrapper (3rd argument) using TypeResolver if necessary + /// Main code generator method. This method should write corresponding TypeScript code for element (1st argument) to + /// WriterWrapper (3rd argument) using TypeResolver if necessary /// /// Element code to be generated to output /// Type resolver @@ -23,13 +20,13 @@ public virtual void Generate(ConstructorInfo element, TypeResolver resolver, Wri { if (element.IsIgnored()) return; var isInterfaceMethod = element.DeclaringType.IsExportingAsInterface(); - if (element.GetParameters().Length==0) return; + if (element.GetParameters().Length == 0) return; sw.Tab(); Settings.Documentation.WriteDocumentation(element, sw); sw.Indent(); WriteFunctionName(false, element.GetModifier(), "constructor", sw, isInterfaceMethod); WriteMethodParameters(element, resolver, sw); - WriteRestOfDeclaration(String.Empty, sw); + WriteRestOfDeclaration(string.Empty, sw); WriteConstructorBody(element, resolver, sw); sw.UnTab(); } @@ -38,7 +35,7 @@ private void WriteConstructorBody(ConstructorInfo element, TypeResolver resolver { // 1. Check presence of base type var bt = element.DeclaringType != null ? element.DeclaringType.BaseType : null; - if (bt == typeof(object) || bt.IsExportingAsInterface()) bt = null; + if (bt == typeof (object) || bt.IsExportingAsInterface()) bt = null; if (bt == null) { @@ -53,24 +50,30 @@ private void WriteConstructorBody(ConstructorInfo element, TypeResolver resolver { // 2. If present then generate super() call with supplied parameters var ctorParams = string.Join(", ", attr.Values.Take(parameters.Length)); - GenerateBody("somethingnonvoid", resolver, sw, String.Format("super({0});", ctorParams)); + GenerateBody("somethingnonvoid", resolver, sw, string.Format("super({0});", ctorParams)); return; } - var baseConstructors = bt.GetConstructors(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static | - BindingFlags.DeclaredOnly); + var baseConstructors = + bt.GetConstructors(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | + BindingFlags.Static | + BindingFlags.DeclaredOnly); // 3. Trying to lookup constructor with same parameters - bool found = false; + var found = false; var paramTypes = parameters.Select(c => c.ParameterType).ToArray(); - var corresponding = TypeExtensions.GetMethodWithSameParameters(baseConstructors.Cast().ToArray(), paramTypes); + var corresponding = TypeExtensions.GetMethodWithSameParameters( + baseConstructors.Cast().ToArray(), paramTypes); found = corresponding != null; if (found) { // 3.If constructor with same parameters found - just use it var ctorParams = string.Join(", ", parameters.Select(c => c.GetName())); - GenerateBody("somethingnonvoid", resolver, sw, String.Format("super({0}); // Please use [TsBaseParam] attribute here to generate more sensible super() call", ctorParams)); + GenerateBody("somethingnonvoid", resolver, sw, + string.Format( + "super({0}); // Please use [TsBaseParam] attribute here to generate more sensible super() call", + ctorParams)); return; } @@ -78,14 +81,18 @@ private void WriteConstructorBody(ConstructorInfo element, TypeResolver resolver if (baseConstructors.Any(c => c.GetParameters().Length == 0)) { // 4. If not present then generate empty super() call - GenerateBody("somethingnonvoid", resolver, sw, "super(); // Please use [TsBaseParam] attribute here to generate more sensible super() call"); + GenerateBody("somethingnonvoid", resolver, sw, + "super(); // Please use [TsBaseParam] attribute here to generate more sensible super() call"); return; } // 5. If nothing found - well... we simply leave here super with all nulls supplied var maxParams = baseConstructors.Max(c => c.GetParameters().Length); var mockedCtorParams = string.Join(", ", Enumerable.Repeat("null", maxParams)); - GenerateBody("somethingnonvoid", resolver, sw, String.Format("super({0}); // Please use [TsBaseParam] attribute here to generate more sensible super() call", mockedCtorParams)); + GenerateBody("somethingnonvoid", resolver, sw, + string.Format( + "super({0}); // Please use [TsBaseParam] attribute here to generate more sensible super() call", + mockedCtorParams)); } } -} +} \ No newline at end of file diff --git a/Reinforced.Typings/Generators/EnumGenerator.cs b/Reinforced.Typings/Generators/EnumGenerator.cs index e0e429ac..91842b04 100644 --- a/Reinforced.Typings/Generators/EnumGenerator.cs +++ b/Reinforced.Typings/Generators/EnumGenerator.cs @@ -1,17 +1,16 @@ using System; using System.Linq; -using System.Reflection; -using Reinforced.Typings.Attributes; namespace Reinforced.Typings.Generators { /// - /// Default code generator for enums + /// Default code generator for enums /// public class EnumGenerator : ITsCodeGenerator { /// - /// Main code generator method. This method should write corresponding TypeScript code for element (1st argument) to WriterWrapper (3rd argument) using TypeResolver if necessary + /// Main code generator method. This method should write corresponding TypeScript code for element (1st argument) to + /// WriterWrapper (3rd argument) using TypeResolver if necessary /// /// Element code to be generated to output /// Type resolver @@ -23,13 +22,13 @@ public virtual void Generate(Type element, TypeResolver resolver, WriterWrapper var fmt = Settings.GetDeclarationFormat(element); var fields = element.GetFields().Where(c => !c.IsSpecialName).ToDictionary(c => c.Name, c => c); - + Settings.Documentation.WriteDocumentation(element, sw); sw.Indent(); - sw.Write(String.Format(fmt, "enum {0} {{ "), name); + sw.Write(string.Format(fmt, "enum {0} {{ "), name); sw.Br(); sw.Tab(); - for (int index = 0; index < values.Length; index++) + for (var index = 0; index < values.Length; index++) { var v = values.GetValue(index); var n = Enum.GetName(element, v); @@ -37,7 +36,7 @@ public virtual void Generate(Type element, TypeResolver resolver, WriterWrapper { var fieldItself = fields[n]; Settings.Documentation.WriteDocumentation(fieldItself, sw); - + var attr = ConfigurationRepository.Instance.ForEnumValue(fieldItself); if (attr != null) n = attr.Name; @@ -52,8 +51,8 @@ public virtual void Generate(Type element, TypeResolver resolver, WriterWrapper } /// - /// Export settings + /// Export settings /// public ExportSettings Settings { get; set; } } -} +} \ No newline at end of file diff --git a/Reinforced.Typings/Generators/FieldCodeGenerator.cs b/Reinforced.Typings/Generators/FieldCodeGenerator.cs index 211d1873..2bcc377d 100644 --- a/Reinforced.Typings/Generators/FieldCodeGenerator.cs +++ b/Reinforced.Typings/Generators/FieldCodeGenerator.cs @@ -4,19 +4,19 @@ namespace Reinforced.Typings.Generators { /// - /// Default code generator for fields + /// Default code generator for fields /// public class FieldCodeGenerator : PropertyCodeGenerator { /// - /// That's it - overriden GetType for property since properties and fields are exported to TypeScript almost same way. + /// That's it - overriden GetType for property since properties and fields are exported to TypeScript almost same way. /// /// Member info (Fields behind) /// Field type protected override Type GetType(MemberInfo mi) { - FieldInfo pi = (FieldInfo)mi; + var pi = (FieldInfo) mi; return pi.FieldType; } } -} +} \ No newline at end of file diff --git a/Reinforced.Typings/Generators/ITsCodeGenerator.cs b/Reinforced.Typings/Generators/ITsCodeGenerator.cs index 185aa577..8ec38336 100644 --- a/Reinforced.Typings/Generators/ITsCodeGenerator.cs +++ b/Reinforced.Typings/Generators/ITsCodeGenerator.cs @@ -1,22 +1,23 @@ namespace Reinforced.Typings.Generators { /// - /// TypeScript code generator interface + /// TypeScript code generator interface /// /// public interface ITsCodeGenerator { /// - /// Main code generator method. This method should write corresponding TypeScript code for element (1st argument) to WriterWrapper (3rd argument) using TypeResolver if necessary + /// Export settings + /// + ExportSettings Settings { get; set; } + + /// + /// Main code generator method. This method should write corresponding TypeScript code for element (1st argument) to + /// WriterWrapper (3rd argument) using TypeResolver if necessary /// /// Element code to be generated to output /// Type resolver /// Output writer void Generate(TElement element, TypeResolver resolver, WriterWrapper sw); - - /// - /// Export settings - /// - ExportSettings Settings { get; set; } } -} +} \ No newline at end of file diff --git a/Reinforced.Typings/Generators/InterfaceCodeGenerator.cs b/Reinforced.Typings/Generators/InterfaceCodeGenerator.cs index 1c99d253..7adc3c90 100644 --- a/Reinforced.Typings/Generators/InterfaceCodeGenerator.cs +++ b/Reinforced.Typings/Generators/InterfaceCodeGenerator.cs @@ -1,16 +1,17 @@ using System; -using System.Reflection; using Reinforced.Typings.Attributes; namespace Reinforced.Typings.Generators { /// - /// Default code generator for interfaces. Derived from class generator since interfaces are very similar to classes in TypeScript + /// Default code generator for interfaces. Derived from class generator since interfaces are very similar to classes in + /// TypeScript /// public class InterfaceCodeGenerator : ClassCodeGenerator { /// - /// Main code generator method. This method should write corresponding TypeScript code for element (1st argument) to WriterWrapper (3rd argument) using TypeResolver if necessary + /// Main code generator method. This method should write corresponding TypeScript code for element (1st argument) to + /// WriterWrapper (3rd argument) using TypeResolver if necessary /// /// Element code to be generated to output /// Type resolver @@ -22,4 +23,4 @@ public override void Generate(Type element, TypeResolver resolver, WriterWrapper Export("interface", element, resolver, sw, tc); } } -} +} \ No newline at end of file diff --git a/Reinforced.Typings/Generators/MethodCodeGenerator.cs b/Reinforced.Typings/Generators/MethodCodeGenerator.cs index 7c3efeff..a916a50b 100644 --- a/Reinforced.Typings/Generators/MethodCodeGenerator.cs +++ b/Reinforced.Typings/Generators/MethodCodeGenerator.cs @@ -1,23 +1,63 @@ -using System; -using System.Linq; +using System.Linq; using System.Reflection; -using Reinforced.Typings.Attributes; namespace Reinforced.Typings.Generators { /// - /// Default typescript code generator for method + /// Default typescript code generator for method /// public class MethodCodeGenerator : ITsCodeGenerator { /// - /// Retrieves function name corresponding to method and return type. Fell free to override it. + /// Main code generator method. This method should write corresponding TypeScript code for element (1st argument) to + /// WriterWrapper (3rd argument) using TypeResolver if necessary + /// + /// Element code to be generated to output + /// Type resolver + /// Output writer + public virtual void Generate(MethodInfo element, TypeResolver resolver, WriterWrapper sw) + { + if (element.IsIgnored()) return; + + var isInterfaceMethod = element.DeclaringType.IsExportingAsInterface() && !Settings.SpecialCase; + string name, type; + + GetFunctionNameAndReturnType(element, resolver, out name, out type); + + sw.Tab(); + Settings.Documentation.WriteDocumentation(element, sw); + sw.Indent(); + var modifier = element.GetModifier(); + + if (Settings.SpecialCase) modifier = AccessModifier.Public; + + WriteFunctionName(element.IsStatic, modifier, name, sw, isInterfaceMethod); + WriteMethodParameters(element, resolver, sw); + WriteRestOfDeclaration(type, sw); + + if (isInterfaceMethod) + { + sw.Write(";"); + sw.Br(); + } + else GenerateBody(type, resolver, sw); + sw.UnTab(); + } + + /// + /// Export settings + /// + public ExportSettings Settings { get; set; } + + /// + /// Retrieves function name corresponding to method and return type. Fell free to override it. /// /// Method info /// Type resolver /// Resulting method name /// Resulting return type name - protected virtual void GetFunctionNameAndReturnType(MethodInfo element, TypeResolver resolver, out string name, out string type) + protected virtual void GetFunctionNameAndReturnType(MethodInfo element, TypeResolver resolver, out string name, + out string type) { name = element.Name; var fa = ConfigurationRepository.Instance.ForMember(element); @@ -42,22 +82,21 @@ protected virtual void GetFunctionNameAndReturnType(MethodInfo element, TypeReso { var args = element.GetGenericArguments(); var names = args.Select(c => resolver.ResolveTypeName(c)); - name = String.Concat(name, "<", String.Join(",", names), ">"); + name = string.Concat(name, "<", string.Join(",", names), ">"); } } } - /// - /// Writes all method's parameters to output writer. + /// Writes all method's parameters to output writer. /// /// Method info /// Type resolver /// Output writer protected virtual void WriteMethodParameters(MethodBase element, TypeResolver resolver, WriterWrapper sw) { - ParameterInfo[] p = element.GetParameters(); - for (int index = 0; index < p.Length; index++) + var p = element.GetParameters(); + for (var index = 0; index < p.Length; index++) { var param = p[index]; if (param.IsIgnored()) continue; @@ -71,13 +110,14 @@ protected virtual void WriteMethodParameters(MethodBase element, TypeResolver re } /// - /// Writes method body to output writer + /// Writes method body to output writer /// /// Method return type /// Type resolver /// Output writer /// Content for non-void body - protected virtual void GenerateBody(string returnType, TypeResolver resolver, WriterWrapper sw, string content = "return null;") + protected virtual void GenerateBody(string returnType, TypeResolver resolver, WriterWrapper sw, + string content = "return null;") { if (Settings.ExportPureTypings) //Ambient class declarations cannot have a body { @@ -102,16 +142,19 @@ protected virtual void WriteMethodParameters(MethodBase element, TypeResolver re } /// - /// Writes method name, accessor and opening brace to output writer + /// Writes method name, accessor and opening brace to output writer /// /// Is method static or not /// Access modifier for method /// Method name /// Output writer - /// Is this method interface declaration or not (access modifiers prohibited on interface declaration methods) - protected void WriteFunctionName(bool isStatic, AccessModifier accessModifier, string name, WriterWrapper sw, bool isInterfaceDecl = false) + /// + /// Is this method interface declaration or not (access modifiers prohibited on interface + /// declaration methods) + /// + protected void WriteFunctionName(bool isStatic, AccessModifier accessModifier, string name, WriterWrapper sw, + bool isInterfaceDecl = false) { - if (!isInterfaceDecl) { sw.Write("{0} ", accessModifier.ToModifierText()); @@ -122,7 +165,7 @@ protected void WriteFunctionName(bool isStatic, AccessModifier accessModifier, s } /// - /// Writes rest of method declaration to output writer (after formal parameters list) + /// Writes rest of method declaration to output writer (after formal parameters list) /// /// Returning type name /// Output writer @@ -137,40 +180,5 @@ protected void WriteRestOfDeclaration(string type, WriterWrapper sw) sw.Write("): {0}", type); } } - /// - /// Main code generator method. This method should write corresponding TypeScript code for element (1st argument) to WriterWrapper (3rd argument) using TypeResolver if necessary - /// - /// Element code to be generated to output - /// Type resolver - /// Output writer - public virtual void Generate(MethodInfo element, TypeResolver resolver, WriterWrapper sw) - { - if (element.IsIgnored()) return; - - var isInterfaceMethod = element.DeclaringType.IsExportingAsInterface() && !Settings.SpecialCase; - string name, type; - - GetFunctionNameAndReturnType(element, resolver, out name, out type); - - sw.Tab(); - Settings.Documentation.WriteDocumentation(element, sw); - sw.Indent(); - var modifier = element.GetModifier(); - - if (Settings.SpecialCase) modifier = AccessModifier.Public; - - WriteFunctionName(element.IsStatic, modifier, name, sw, isInterfaceMethod); - WriteMethodParameters(element, resolver, sw); - WriteRestOfDeclaration(type, sw); - - if (isInterfaceMethod) { sw.Write(";"); sw.Br(); } - else GenerateBody(type, resolver, sw); - sw.UnTab(); - } - - /// - /// Export settings - /// - public ExportSettings Settings { get; set; } } -} +} \ No newline at end of file diff --git a/Reinforced.Typings/Generators/NamespaceCodeGenerator.cs b/Reinforced.Typings/Generators/NamespaceCodeGenerator.cs index a003a5fe..e7edf594 100644 --- a/Reinforced.Typings/Generators/NamespaceCodeGenerator.cs +++ b/Reinforced.Typings/Generators/NamespaceCodeGenerator.cs @@ -4,37 +4,43 @@ namespace Reinforced.Typings.Generators { /// - /// Default code generator for namespace + /// Default code generator for namespace /// public class NamespaceCodeGenerator { /// - /// Generates namespace source code + /// Export settings + /// + public ExportSettings Settings { get; set; } + + /// + /// Generates namespace source code /// /// Types list /// Namespace name /// Type resolver /// Output writer - public virtual void Generate(IEnumerable types, string namespaceName, TypeResolver resolver, WriterWrapper sw) + public virtual void Generate(IEnumerable types, string namespaceName, TypeResolver resolver, + WriterWrapper sw) { - WriteNamespaceBegin(namespaceName,sw); + WriteNamespaceBegin(namespaceName, sw); Settings.CurrentNamespace = namespaceName; foreach (var type in types) { - var converter = resolver.GeneratorFor(type,Settings); + var converter = resolver.GeneratorFor(type, Settings); converter.Generate(type, resolver, sw); Console.WriteLine("Exported {0}", type); } - - WriteNamespaceEnd(namespaceName,sw); + + WriteNamespaceEnd(namespaceName, sw); } /// - /// Writes to output file opening namespace declaration + /// Writes to output file opening namespace declaration /// /// Namespace name /// Output writer - public virtual void WriteNamespaceBegin(string namespaceName,WriterWrapper sw) + public virtual void WriteNamespaceBegin(string namespaceName, WriterWrapper sw) { if (string.IsNullOrEmpty(namespaceName)) return; if (Settings.ExportPureTypings) @@ -49,7 +55,7 @@ public virtual void WriteNamespaceBegin(string namespaceName,WriterWrapper sw) } /// - /// Writes to ouput file namespace closing + /// Writes to ouput file namespace closing /// /// Namespace name /// Output writer @@ -61,10 +67,5 @@ public virtual void WriteNamespaceEnd(string namespaceName, WriterWrapper sw) sw.WriteLine("}"); sw.Br(); } - - /// - /// Export settings - /// - public ExportSettings Settings { get; set; } } -} +} \ No newline at end of file diff --git a/Reinforced.Typings/Generators/ParameterCodeGenerator.cs b/Reinforced.Typings/Generators/ParameterCodeGenerator.cs index 076fab73..68d03f0e 100644 --- a/Reinforced.Typings/Generators/ParameterCodeGenerator.cs +++ b/Reinforced.Typings/Generators/ParameterCodeGenerator.cs @@ -5,45 +5,13 @@ namespace Reinforced.Typings.Generators { /// - /// Default code generator for method parameter + /// Default code generator for method parameter /// public class ParameterCodeGenerator : ITsCodeGenerator { /// - /// Returns default value for specified parameter info - /// - /// Parameter info - /// Parameter attribute - /// Serialized to string default value of type that is exposed by mentioned parameter - protected virtual string GetDefaultValue(ParameterInfo element, TsParameterAttribute attr) - { - object defVal = null; - if (attr != null) - { - defVal = attr.DefaultValue; - } - if (defVal == null) - { - defVal = element.DefaultValue; - } - - if (defVal == null) return null; - - if (defVal is string) - { - return String.Format("\"{0}\"", defVal); - } - if (defVal is bool) - { - return ((bool)defVal) ? "true" : "false"; - } - var ts = defVal.ToString(); - if (string.IsNullOrEmpty(ts)) return null; - return ts; - - } - /// - /// Main code generator method. This method should write corresponding TypeScript code for element (1st argument) to WriterWrapper (3rd argument) using TypeResolver if necessary + /// Main code generator method. This method should write corresponding TypeScript code for element (1st argument) to + /// WriterWrapper (3rd argument) using TypeResolver if necessary /// /// Element code to be generated to output /// Type resolver @@ -51,9 +19,9 @@ protected virtual string GetDefaultValue(ParameterInfo element, TsParameterAttri public virtual void Generate(ParameterInfo element, TypeResolver resolver, WriterWrapper sw) { if (element.IsIgnored()) return; - string name = element.Name; + var name = element.Name; string type; - bool isNullable = false; + var isNullable = false; var fa = ConfigurationRepository.Instance.ForMember(element); var defaultValue = GetDefaultValue(element, fa); @@ -92,14 +60,47 @@ public virtual void Generate(ParameterInfo element, TypeResolver resolver, Write else { //there are slightly different rules for .d.ts - if (isNullable||defaultValue!=null) sw.Write("?"); + if (isNullable || defaultValue != null) sw.Write("?"); sw.Write(": {0}", type); } } /// - /// Export settings + /// Export settings /// public ExportSettings Settings { get; set; } + + /// + /// Returns default value for specified parameter info + /// + /// Parameter info + /// Parameter attribute + /// Serialized to string default value of type that is exposed by mentioned parameter + protected virtual string GetDefaultValue(ParameterInfo element, TsParameterAttribute attr) + { + object defVal = null; + if (attr != null) + { + defVal = attr.DefaultValue; + } + if (defVal == null) + { + defVal = element.DefaultValue; + } + + if (defVal == null) return null; + + if (defVal is string) + { + return string.Format("\"{0}\"", defVal); + } + if (defVal is bool) + { + return ((bool) defVal) ? "true" : "false"; + } + var ts = defVal.ToString(); + if (string.IsNullOrEmpty(ts)) return null; + return ts; + } } -} +} \ No newline at end of file diff --git a/Reinforced.Typings/Generators/PropertyCodeGenerator.cs b/Reinforced.Typings/Generators/PropertyCodeGenerator.cs index e02954aa..e2ae2479 100644 --- a/Reinforced.Typings/Generators/PropertyCodeGenerator.cs +++ b/Reinforced.Typings/Generators/PropertyCodeGenerator.cs @@ -5,12 +5,13 @@ namespace Reinforced.Typings.Generators { /// - /// Default code generator for properties + /// Default code generator for properties /// public class PropertyCodeGenerator : ITsCodeGenerator { /// - /// Main code generator method. This method should write corresponding TypeScript code for element (1st argument) to WriterWrapper (3rd argument) using TypeResolver if necessary + /// Main code generator method. This method should write corresponding TypeScript code for element (1st argument) to + /// WriterWrapper (3rd argument) using TypeResolver if necessary /// /// Element code to be generated to output /// Type resolver @@ -21,7 +22,7 @@ public virtual void Generate(MemberInfo element, TypeResolver resolver, WriterWr var t = GetType(element); string typeName = null; - string propName = element.Name; + var propName = element.Name; var tp = ConfigurationRepository.Instance.ForMember(element); if (tp != null) { @@ -35,10 +36,12 @@ public virtual void Generate(MemberInfo element, TypeResolver resolver, WriterWr } if (!string.IsNullOrEmpty(tp.Name)) propName = tp.Name; - if (tp.ForceNullable && element.DeclaringType.IsExportingAsInterface() && !Settings.SpecialCase) propName = propName + "?"; + if (tp.ForceNullable && element.DeclaringType.IsExportingAsInterface() && !Settings.SpecialCase) + propName = propName + "?"; } if (string.IsNullOrEmpty(typeName)) typeName = resolver.ResolveTypeName(t); - if (!propName.EndsWith("?") && t.IsNullable() && element.DeclaringType.IsExportingAsInterface() && !Settings.SpecialCase) + if (!propName.EndsWith("?") && t.IsNullable() && element.DeclaringType.IsExportingAsInterface() && + !Settings.SpecialCase) { propName = propName + "?"; } @@ -54,8 +57,8 @@ public virtual void Generate(MemberInfo element, TypeResolver resolver, WriterWr sw.Indent(); if (!element.DeclaringType.IsExportingAsInterface() || Settings.SpecialCase) { - var modifier = Settings.SpecialCase? AccessModifier.Public: element.GetModifier(); - sw.Write("{0} ",modifier.ToModifierText()); + var modifier = Settings.SpecialCase ? AccessModifier.Public : element.GetModifier(); + sw.Write("{0} ", modifier.ToModifierText()); } sw.Write("{0}: {1};", propName, typeName); sw.Br(); @@ -63,19 +66,19 @@ public virtual void Generate(MemberInfo element, TypeResolver resolver, WriterWr } /// - /// Export settings + /// Export settings /// public ExportSettings Settings { get; set; } /// - /// Returns type of specified property. It is useful for overloads sometimes + /// Returns type of specified property. It is useful for overloads sometimes /// /// Method Info /// Property info type protected virtual Type GetType(MemberInfo mi) { - PropertyInfo pi = (PropertyInfo)mi; + var pi = (PropertyInfo) mi; return pi.PropertyType; } } -} +} \ No newline at end of file diff --git a/Reinforced.Typings/Generators/SettingsExtensions.cs b/Reinforced.Typings/Generators/SettingsExtensions.cs index a6092719..97c08c37 100644 --- a/Reinforced.Typings/Generators/SettingsExtensions.cs +++ b/Reinforced.Typings/Generators/SettingsExtensions.cs @@ -6,20 +6,20 @@ namespace Reinforced.Typings.Generators { /// - /// Various extensions for settings + /// Various extensions for settings /// public static class SettingsExtensions { /// - /// Returns declaration format for supplied Type (export/declare/nothing) + /// Returns declaration format for supplied Type (export/declare/nothing) /// /// Export settings /// Type /// Declaration format - just supply your compilation unit type and name - public static string GetDeclarationFormat(this ExportSettings settings,Type element) + public static string GetDeclarationFormat(this ExportSettings settings, Type element) { var ns = element.GetNamespace(); - bool needsExports = !string.IsNullOrEmpty(ns); + var needsExports = !string.IsNullOrEmpty(ns); if (settings.ExportPureTypings) { if (element.IsExportingAsInterface()) return "{0} "; // no declare or export for interfaces @@ -32,7 +32,7 @@ public static string GetDeclarationFormat(this ExportSettings settings,Type elem } /// - /// Conditionally (based on settings) turns method name to camelCase + /// Conditionally (based on settings) turns method name to camelCase /// /// Settings object /// Regular method name @@ -44,19 +44,20 @@ public static string ConditionallyConvertMethodNameToCamelCase(this ExportSettin } /// - /// Conditionally (based on settings) turns property name to camelCase + /// Conditionally (based on settings) turns property name to camelCase /// /// Settings object /// Regular property name /// Property name in camelCase if camelCasing enabled, initial string otherwise - public static string ConditionallyConvertPropertyNameToCamelCase(this ExportSettings settings, string regularName) + public static string ConditionallyConvertPropertyNameToCamelCase(this ExportSettings settings, + string regularName) { if (!settings.CamelCaseForProperties) return regularName; return ConvertToCamelCase(regularName); } /// - /// Conditionally (based on attribute setting) turns member name to camelCase + /// Conditionally (based on attribute setting) turns member name to camelCase /// /// Member /// Regular property name @@ -80,14 +81,16 @@ private static string ConvertToCamelCase(string s) } /// - /// Retrieves type from source assemblies by name + /// Retrieves type from source assemblies by name /// /// Settings /// Type name /// Type (or null) public static Type GetSourceAssemblyType(this ExportSettings settings, string typeName) { - return settings.SourceAssemblies.Select(sourceAssembly => sourceAssembly.GetType(typeName, false)).FirstOrDefault(t => t != null); + return + settings.SourceAssemblies.Select(sourceAssembly => sourceAssembly.GetType(typeName, false)) + .FirstOrDefault(t => t != null); } } -} +} \ No newline at end of file diff --git a/Reinforced.Typings/Properties/AssemblyInfo.cs b/Reinforced.Typings/Properties/AssemblyInfo.cs index 2f94fd0f..a982ee05 100644 --- a/Reinforced.Typings/Properties/AssemblyInfo.cs +++ b/Reinforced.Typings/Properties/AssemblyInfo.cs @@ -4,6 +4,7 @@ // General Information about an assembly is controlled through the following // set of attributes. Change these attribute values to modify the information // associated with an assembly. + [assembly: AssemblyTitle("DynamicMvcTypings")] [assembly: AssemblyDescription("")] [assembly: AssemblyConfiguration("")] @@ -16,9 +17,11 @@ // Setting ComVisible to false makes the types in this assembly not visible // to COM components. If you need to access a type in this assembly from // COM, set the ComVisible attribute to true on that type. + [assembly: ComVisible(false)] // The following GUID is for the ID of the typelib if this project is exposed to COM + [assembly: Guid("f05e4940-fa83-446c-97ff-b0d7fb56daee")] // Version information for an assembly consists of the following four values: @@ -31,5 +34,6 @@ // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] + [assembly: AssemblyVersion("1.0.0.0")] -[assembly: AssemblyFileVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] \ No newline at end of file diff --git a/Reinforced.Typings/ReferenceInspector.cs b/Reinforced.Typings/ReferenceInspector.cs index 949dbcff..32c94070 100644 --- a/Reinforced.Typings/ReferenceInspector.cs +++ b/Reinforced.Typings/ReferenceInspector.cs @@ -1,72 +1,88 @@ using System; using System.Collections.Generic; -using System.Linq; using System.Reflection; using System.Text; -using System.Threading.Tasks; -using Reinforced.Typings.Attributes; namespace Reinforced.Typings { internal static class ReferenceInspector { internal static string GenerateInspectedReferences(this FilesOperations fileOps, Type element, - HashSet alltypes, string currentNamespace) + HashSet alltypes) { var inspectedTypes = InspectReferences(element, alltypes); - StringBuilder sb = new StringBuilder(); + + var references = new HashSet(); + var types = ConfigurationRepository.Instance.ReferencesForType(element); if (types != null) { foreach (var attr in types) { - var path = attr.Type != null ? fileOps.GetRelativePathForType(attr.Type, currentNamespace) : attr.RawPath; - sb.AppendLine(String.Format("/// ", path)); + var path = attr.Type != null ? fileOps.GetRelativePathForType(attr.Type, element) : attr.RawPath; + references.AddIfNotExists(path); } } foreach (var inspectedType in inspectedTypes) { - sb.AppendLine(String.Format("/// ", fileOps.GetRelativePathForType(inspectedType, currentNamespace))); + var path = fileOps.GetRelativePathForType(inspectedType, element); + references.AddIfNotExists(path); + } + var sb = new StringBuilder(); + foreach (var reference in references) + { + if (!string.IsNullOrEmpty(reference)) + sb.AppendLine(string.Format("/// ", reference)); } - return sb.ToString(); + return sb.ToString().Trim(); } - internal static HashSet InspectReferences(Type element, HashSet alltypes) + private static Type GetOverridenType(MemberInfo info) { - HashSet references = new HashSet(); - IAutoexportSwitchAttribute swtch = ConfigurationRepository.Instance.ForType(element) ?? - (IAutoexportSwitchAttribute)ConfigurationRepository.Instance.ForType(element); - - var flags = BindingFlags.Public | BindingFlags.Instance | BindingFlags.Static | BindingFlags.DeclaredOnly; - - Func predicate = c => ConfigurationRepository.Instance.IsIgnored(c); - - var fields = element.GetFields(flags).Where(predicate).OfType(); - - if (!swtch.AutoExportFields) fields = fields.Where(c => ConfigurationRepository.Instance.ForMember(c) != null); - - foreach (var fi in fields) InspectArgumentReferences(fi.FieldType, alltypes, references); - - var properties = element.GetProperties(flags).Where(predicate).OfType(); - if (!swtch.AutoExportProperties) properties = properties.Where(c => ConfigurationRepository.Instance.ForMember(c) != null); + var attr = ConfigurationRepository.Instance.ForMember(info); + if (attr != null && attr.StrongType != null) return attr.StrongType; + if (info is PropertyInfo) return ((PropertyInfo) info).PropertyType; + if (info is FieldInfo) return ((FieldInfo) info).FieldType; + if (info is MethodInfo) return ((MethodInfo) info).ReturnType; + return null; + } - foreach (var pi in properties) InspectArgumentReferences(pi.PropertyType, alltypes, references); + internal static HashSet InspectReferences(Type element, HashSet alltypes) + { + var references = new HashSet(); + if (element.IsEnum) return references; + + foreach (var fi in element.GetExportedFields()) + InspectTypeReferences(GetOverridenType(fi), alltypes, references); + foreach (var pi in element.GetExportedProperties()) + InspectTypeReferences(GetOverridenType(pi), alltypes, references); + foreach (var mi in element.GetExportedMethods()) + { + InspectTypeReferences(GetOverridenType(mi), alltypes, references); - var methods = element.GetMethods(flags).Where(c => predicate(c) && !c.IsSpecialName); - if (!swtch.AutoExportMethods) methods = methods.Where(c => ConfigurationRepository.Instance.ForMember(c) != null); + foreach (var parameterInfo in mi.GetParameters()) + { + if (parameterInfo.IsIgnored()) continue; - foreach (var mi in methods) + var paramAttr = ConfigurationRepository.Instance.ForMember(parameterInfo); + if (paramAttr != null && paramAttr.StrongType != null) + InspectTypeReferences(paramAttr.StrongType, alltypes, references); + else InspectTypeReferences(parameterInfo.ParameterType, alltypes, references); + } + } + if (element.BaseType != null) InspectTypeReferences(element.BaseType, alltypes, references); + var interfaces = element.GetInterfaces(); + foreach (var iface in interfaces) { - InspectArgumentReferences(mi.ReturnType, alltypes, references); - foreach (var parameterInfo in mi.GetParameters()) - InspectArgumentReferences(parameterInfo.ParameterType, alltypes, references); + InspectTypeReferences(iface, alltypes, references); } return references; } - private static void InspectArgumentReferences(Type argument, HashSet alltypes, HashSet referenceContainer) + private static void InspectTypeReferences(Type argument, HashSet alltypes, + HashSet referenceContainer) { if (alltypes.Contains(argument)) referenceContainer.AddIfNotExists(argument); if (argument.IsGenericType) @@ -74,7 +90,7 @@ private static void InspectArgumentReferences(Type argument, HashSet allty var args = argument.GetGenericArguments(); foreach (var type in args) { - if (alltypes.Contains(type)) referenceContainer.AddIfNotExists(type); + InspectTypeReferences(type, alltypes, referenceContainer); } } } @@ -84,6 +100,5 @@ private static void AddIfNotExists(this HashSet hashSet, T val) if (hashSet.Contains(val)) return; hashSet.Add(val); } - } -} +} \ No newline at end of file diff --git a/Reinforced.Typings/Reinforced.Typings.csproj b/Reinforced.Typings/Reinforced.Typings.csproj index 26654286..7ed7d799 100644 --- a/Reinforced.Typings/Reinforced.Typings.csproj +++ b/Reinforced.Typings/Reinforced.Typings.csproj @@ -57,6 +57,7 @@ + diff --git a/Reinforced.Typings/TsExporter.cs b/Reinforced.Typings/TsExporter.cs index 89314146..3ef32e72 100644 --- a/Reinforced.Typings/TsExporter.cs +++ b/Reinforced.Typings/TsExporter.cs @@ -11,30 +11,30 @@ namespace Reinforced.Typings { /// - /// Facade for final TypeScript export. This class supplies assemblies names or assemblies itself as parameter and exports resulting TypeScript file to file or to string + /// Facade for final TypeScript export. This class supplies assemblies names or assemblies itself as parameter and + /// exports resulting TypeScript file to file or to string /// public class TsExporter : MarshalByRefObject { - private readonly ExportSettings _settings; - private bool _isAnalyzed; + private readonly FilesOperations _fileOps; private readonly StringBuilder _referenceBuilder = new StringBuilder(); - private Dictionary> _namespace = new Dictionary>(); + private readonly ExportSettings _settings; private List _allTypes; private HashSet _allTypesHash; - private readonly FilesOperations _fileOps; private ConfigurationRepository _configurationRepository; + private bool _isAnalyzed; + private Dictionary> _namespace = new Dictionary>(); #region Constructors /// - /// Constructs new instance of TypeScript exporter + /// Constructs new instance of TypeScript exporter /// /// public TsExporter(ExportSettings settings) { _settings = settings; _fileOps = new FilesOperations(settings); - } #endregion @@ -42,10 +42,12 @@ public TsExporter(ExportSettings settings) private void ExtractReferences() { if (_isAnalyzed) return; - _settings.Documentation = new DocumentationManager(_settings.GenerateDocumentation ? _settings.DocumentationFilePath : null); - if (_settings.ConfigurationMethod != null) + _settings.Documentation = + new DocumentationManager(_settings.GenerateDocumentation ? _settings.DocumentationFilePath : null); + var fluentConfigurationPresents = _settings.ConfigurationMethod != null; + if (fluentConfigurationPresents) { - ConfigurationBuilder configurationBuilder = new ConfigurationBuilder(); + var configurationBuilder = new ConfigurationBuilder(); _settings.ConfigurationMethod(configurationBuilder); _configurationRepository = configurationBuilder.Build(); ConfigurationRepository.Instance = _configurationRepository; @@ -54,7 +56,6 @@ private void ExtractReferences() { _settings.Documentation.CacheDocumentation(additionalDocumentationPath); } - } _allTypes = _settings.SourceAssemblies @@ -64,75 +65,75 @@ private void ExtractReferences() _allTypesHash = new HashSet(_allTypes); + if (_settings.Hierarchical) + { + foreach (var type in _allTypesHash) + { + ConfigurationRepository.Instance.AddFileSeparationSettings(type); + } + } + var grp = _allTypes.GroupBy(c => c.GetNamespace(true)); _namespace = grp.Where(g => !string.IsNullOrEmpty(g.Key)) // avoid anonymous types .ToDictionary(k => k.Key, v => v.ToList()); _settings.SourceAssemblies.Where(c => c.GetCustomAttributes().Any()) - .SelectMany(c => c.GetCustomAttributes()) - .Select(c => string.Format("/// ", c.Path)) - .Union(ConfigurationRepository.Instance.References.Select(c => string.Format("/// ", c))) - .ToList() - .ForEach(a => _referenceBuilder.AppendLine(a)); + .SelectMany(c => c.GetCustomAttributes()) + .Select(c => string.Format("/// ", c.Path)) + .Union( + ConfigurationRepository.Instance.References.Select( + c => string.Format("/// ", c))) + .ToList() + .ForEach(a => _referenceBuilder.AppendLine(a)); _settings.References = _referenceBuilder.ToString(); - _isAnalyzed = true; } /// - /// Exports TypeScript source to specified TextWriter according to settings + /// Exports TypeScript source to specified TextWriter according to settings /// /// TextWriter - public void ExportAll(TextWriter sw) + /// TypeResolver object + /// Types to export + public void ExportTypes(TextWriter sw, TypeResolver tr, IEnumerable types = null) { - _settings.Lock(); - - ExtractReferences(); - - sw.WriteLine(_referenceBuilder.ToString()); - TypeResolver tr = new TypeResolver(_settings); - WriterWrapper ww = new WriterWrapper(sw); - - var gen = tr.GeneratorForNamespace(_settings); + ExportReferences(sw, types); + if (types == null) types = _allTypes; + ExportNamespaces(types, tr, sw); + } - foreach (var n in _namespace) + private void ExportReferences(TextWriter tw, IEnumerable types = null) + { + WriteWarning(tw); + if (types != null) { - var ns = n.Key; - if (ns == "-") ns = String.Empty; - gen.Generate(n.Value, ns, tr, ww); + var atLeast = false; + foreach (var type in types) + { + var inspected = _fileOps.GenerateInspectedReferences(type, _allTypesHash); + if (!string.IsNullOrEmpty(inspected) && !string.IsNullOrWhiteSpace(inspected)) + { + tw.WriteLine(inspected); + atLeast = true; + } + } + if (atLeast) tw.WriteLine(); } - - sw.Flush(); - _settings.Unlock(); - tr.PrintCacheInfo(); } - private void ExportType(Type type, TextWriter tw, TypeResolver resolver) - { - tw.WriteLine(_referenceBuilder.ToString()); - var n = type.GetNamespace(); - tw.WriteLine(_fileOps.GenerateInspectedReferences(type, _allTypesHash, n)); - - WriterWrapper sw = new WriterWrapper(tw); - var gen = resolver.GeneratorForNamespace(_settings); - - gen.WriteNamespaceBegin(n, sw); - var converter = resolver.GeneratorFor(type, _settings); - converter.Generate(type, resolver, sw); - Console.WriteLine("Exported {0}", type); - gen.WriteNamespaceEnd(n, sw); - tw.Flush(); - } /// - /// Exports TypeScript source according to settings + /// Exports TypeScript source according to settings /// public void Export() { _fileOps.ClearTempRegistry(); ExtractReferences(); + var tr = new TypeResolver(_settings); + _settings.Lock(); + if (!_settings.Hierarchical) { var file = _fileOps.GetTmpFile(_settings.TargetFile); @@ -140,32 +141,51 @@ public void Export() { using (var tw = new StreamWriter(fs)) { - WriteWarning(tw); - ExportAll(tw); + ExportTypes(tw, tr); } } } else { - TypeResolver tr = new TypeResolver(_settings); - foreach (var t in _allTypes) + var typeFilesMap = _allTypes + .GroupBy(c => _fileOps.GetPathForType(c)) + .ToDictionary(c => c.Key, c => c.AsEnumerable()); + + foreach (var kv in typeFilesMap) { - var path = _fileOps.GetPathForType(t); + var path = kv.Key; var tmpFile = _fileOps.GetTmpFile(path); using (var fs = File.OpenWrite(tmpFile)) { using (var tw = new StreamWriter(fs)) { - WriteWarning(tw); - ExportType(t, tw, tr); + ExportTypes(tw, tr, kv.Value); } } } - tr.PrintCacheInfo(); } + + _settings.Unlock(); _fileOps.DeployTempFiles(); + tr.PrintCacheInfo(); } + private void ExportNamespaces(IEnumerable types, TypeResolver tr, TextWriter tw) + { + var gen = tr.GeneratorForNamespace(_settings); + var grp = types.GroupBy(c => c.GetNamespace(true)); + var nsp = grp.Where(g => !string.IsNullOrEmpty(g.Key)) // avoid anonymous types + .ToDictionary(k => k.Key, v => v.ToList()); + + var ww = new WriterWrapper(tw); + foreach (var n in nsp) + { + var ns = n.Key; + if (ns == "-") ns = string.Empty; + gen.Generate(n.Value, ns, tr, ww); + } + tw.Flush(); + } private void WriteWarning(TextWriter tw) { @@ -174,11 +194,12 @@ private void WriteWarning(TextWriter tw) tw.WriteLine("// This code was generated by a Reinforced.Typings tool. "); tw.WriteLine("// Changes to this file may cause incorrect behavior and will be lost if"); tw.WriteLine("// the code is regenerated."); + tw.WriteLine(); } } /// - /// Exports TypeScript source to string + /// Exports TypeScript source to string /// /// String containig generated TypeScript source for specified assemblies public string ExportAll() @@ -186,14 +207,14 @@ public string ExportAll() _settings.Lock(); ExtractReferences(); - StringBuilder sb = new StringBuilder(); + var sb = new StringBuilder(); + var tr = new TypeResolver(_settings); using (var sw = new StringWriter(sb)) { - ExportAll(sw); + ExportTypes(sw, tr); } _settings.Unlock(); return sb.ToString(); - } } -} +} \ No newline at end of file diff --git a/Reinforced.Typings/TypeExtensions.cs b/Reinforced.Typings/TypeExtensions.cs index c7ebf155..e47e7d1e 100644 --- a/Reinforced.Typings/TypeExtensions.cs +++ b/Reinforced.Typings/TypeExtensions.cs @@ -9,22 +9,67 @@ namespace Reinforced.Typings { /// - /// Useful extensions for reflection + /// Useful extensions for reflection /// public static class TypeExtensions { /// - /// Determines is type derived from Nullable or not + /// Binding flags for searching all members + /// + public const BindingFlags MembersFlags = + BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static | + BindingFlags.DeclaredOnly; + + /// + /// Search predicate to exclude ignored and compiler-generated items + /// + public static readonly Func TypeScriptMemberSearchPredicate = + c => + (!ConfigurationRepository.Instance.IsIgnored(c)) && + (c.GetCustomAttribute() == null); + + /// + /// Returns all properties that should be exported to TypeScript for specified type + /// + /// Type + /// Properties array + public static PropertyInfo[] GetExportedProperties(this Type t) + { + return ConfigurationRepository.Instance.GetExportedProperties(t); + } + + /// + /// Returns all fields that should be exported to TypeScript for specified type + /// + /// Type + /// Fields array + public static FieldInfo[] GetExportedFields(this Type t) + { + return ConfigurationRepository.Instance.GetExportedFields(t); + } + + /// + /// Returns all methods that should be exported to TypeScript for specified type + /// + /// Type + /// Methods array + public static MethodInfo[] GetExportedMethods(this Type t) + { + return ConfigurationRepository.Instance.GetExportedMethods(t); + } + + /// + /// Determines is type derived from Nullable or not /// /// Type /// True if type is nullable value type. False otherwise public static bool IsNullable(this Type t) { - return (t.IsGenericType && (t.GetGenericTypeDefinition() == typeof(Nullable<>))); + return (t.IsGenericType && (t.GetGenericTypeDefinition() == typeof (Nullable<>))); } /// - /// Retrieves first type argument of type + /// Retrieves first type argument of type /// /// Type /// First type argument @@ -34,7 +79,7 @@ public static Type GetArg(this Type t) } /// - /// Determines if type is Dictionary-like + /// Determines if type is Dictionary-like /// /// Type /// True if type is derived from dictionary type @@ -44,67 +89,63 @@ public static bool IsDictionary(this Type t) { var tg = t.GetGenericTypeDefinition(); - if (typeof(IDictionary<,>).IsAssignableFrom(tg)) return true; - if (typeof(IReadOnlyDictionary<,>).IsAssignableFrom(tg)) return true; - if (typeof(Dictionary<,>).IsAssignableFrom(tg)) return true; - if (typeof(IDictionary).IsAssignableFrom(t)) return true; + if (typeof (IDictionary<,>).IsAssignableFrom(tg)) return true; + if (typeof (IReadOnlyDictionary<,>).IsAssignableFrom(tg)) return true; + if (typeof (Dictionary<,>).IsAssignableFrom(tg)) return true; + if (typeof (IDictionary).IsAssignableFrom(t)) return true; } else { - if (typeof(IDictionary).IsAssignableFrom(t)) return true; + if (typeof (IDictionary).IsAssignableFrom(t)) return true; } return false; } /// - /// Determines if type is enumerable regardless of generic spec + /// Determines if type is enumerable regardless of generic spec /// /// Type /// True if type is enumerable (incl. array type). False otherwise. public static bool IsEnumerable(this Type t) { if (t.IsArray) return true; + if (typeof (IEnumerable).IsAssignableFrom(t)) return true; if (t.IsGenericType) { var tg = t.GetGenericTypeDefinition(); - if (typeof(IEnumerable<>).IsAssignableFrom(tg)) return true; - if (typeof(IEnumerable).IsAssignableFrom(t)) return true; - - } - else - { - if (typeof(IEnumerable).IsAssignableFrom(t)) return true; + if (typeof (IEnumerable<>).IsAssignableFrom(tg)) return true; } return false; } /// - /// Determines if supplied type is non-generic enumerable + /// Determines if supplied type is non-generic enumerable /// /// Type /// True if supplied type is nongeneric enumerable. False otherwise public static bool IsNongenericEnumerable(this Type t) { + if (t.IsGenericType && t.GetGenericTypeDefinition() == typeof (IEnumerable<>)) return false; var interfaces = t.GetInterfaces(); - bool containsEnumerable = interfaces.Contains(typeof (IEnumerable)); - bool containsGenericEnumerable = + var containsEnumerable = interfaces.Contains(typeof (IEnumerable)); + var containsGenericEnumerable = interfaces.Any(c => c.IsGenericType && c.GetGenericTypeDefinition() == typeof (IEnumerable<>)); return containsEnumerable && !containsGenericEnumerable; } /// - /// Determines should type be exported as interface or not + /// Determines should type be exported as interface or not /// /// Type /// True, if supplied type should be exported as interface. False otherwise public static bool IsExportingAsInterface(this Type t) { - return ConfigurationRepository.Instance.ForType(t) != null; + return ConfigurationRepository.Instance.ForType(t) != null; } /// - /// Determines if type member should be ignored for translation using corresponding Typings attribute + /// Determines if type member should be ignored for translation using corresponding Typings attribute /// /// Type member info /// True if type member should be ignored, false otherwise @@ -114,7 +155,7 @@ public static bool IsIgnored(this MemberInfo t) } /// - /// Determines if parameter should be ignored for translation using corresponding Typings attribute + /// Determines if parameter should be ignored for translation using corresponding Typings attribute /// /// Parameter info /// True if parameter should be ignored, false otherwise @@ -124,7 +165,7 @@ public static bool IsIgnored(this ParameterInfo t) } /// - /// Removes generics postfix (all text after '`') from typename + /// Removes generics postfix (all text after '`') from typename /// /// Type /// Clean, genericless name @@ -132,7 +173,7 @@ private static string CleanGenericName(this Type t) { if (t.IsGenericType) { - string name = t.Name; + var name = t.Name; var qidx = name.IndexOf('`'); return name.Substring(0, qidx); } @@ -140,42 +181,43 @@ private static string CleanGenericName(this Type t) } /// - /// Retrieves parameter name from corresponding attribute. If attribute not present then takes parameter name via reflection + /// Retrieves parameter name from corresponding attribute. If attribute not present then takes parameter name via + /// reflection /// /// Parameter info /// Parameter name public static string GetName(this ParameterInfo element) { var fa = ConfigurationRepository.Instance.ForMember(element); - if (fa != null && !String.IsNullOrEmpty(fa.Name)) return fa.Name; + if (fa != null && !string.IsNullOrEmpty(fa.Name)) return fa.Name; return element.Name; } /// - /// Determines if supplied type is delegate type + /// Determines if supplied type is delegate type /// /// Type /// True, if supplied type is delegate, false otherwise public static bool IsDelegate(this Type t) { if (t.BaseType == null) return false; - return typeof(MulticastDelegate).IsAssignableFrom(t.BaseType); + return typeof (MulticastDelegate).IsAssignableFrom(t.BaseType); } private static string SerializeGenericArguments(this Type t) { - if (!t.IsGenericTypeDefinition) return String.Empty; + if (!t.IsGenericTypeDefinition) return string.Empty; if (t.IsGenericTypeDefinition) { var args = t.GetGenericArguments(); - string argsStr = String.Format("<{0}>", String.Join(", ", args.Select(c => c.Name))); + var argsStr = string.Format("<{0}>", string.Join(", ", args.Select(c => c.Name))); return argsStr; } - return String.Empty; + return string.Empty; } /// - /// Retrieves type name from type itself or from corresponding Reinforced.Typings attribute + /// Retrieves type name from type itself or from corresponding Reinforced.Typings attribute /// /// Type /// Type name @@ -184,8 +226,8 @@ public static string GetName(this Type t) if (t.IsEnum) { var te = ConfigurationRepository.Instance.ForType(t); - string ns = t.Name; - if (te != null && !String.IsNullOrEmpty(te.Name)) + var ns = t.Name; + if (te != null && !string.IsNullOrEmpty(te.Name)) { ns = te.Name; } @@ -194,8 +236,9 @@ public static string GetName(this Type t) var tc = ConfigurationRepository.Instance.ForType(t); var ti = ConfigurationRepository.Instance.ForType(t); - string nameFromAttr = tc != null ? tc.Name : ti.Name; - var name = (!String.IsNullOrEmpty(nameFromAttr) ? nameFromAttr : t.CleanGenericName()) + t.SerializeGenericArguments(); + var nameFromAttr = tc != null ? tc.Name : ti.Name; + var name = (!string.IsNullOrEmpty(nameFromAttr) ? nameFromAttr : t.CleanGenericName()) + + t.SerializeGenericArguments(); if (ti != null) { if (ti.AutoI && !name.StartsWith("I")) name = "I" + name; @@ -204,18 +247,21 @@ public static string GetName(this Type t) } /// - /// Retrieves type namespace from type itself or from corresponding Typings attribute + /// Retrieves type namespace from type itself or from corresponding Typings attribute /// /// Type - /// Forces GetNamespace to return "-" for interfaces with IncludeInterface = false and null for anonymous types + /// + /// Forces GetNamespace to return "-" for interfaces with IncludeInterface = false and + /// null for anonymous types + /// /// Full-qualified namespace name public static string GetNamespace(this Type t, bool distinguishAutoTypes = false) { if (t.IsEnum) { var te = ConfigurationRepository.Instance.ForType(t); - string ns = t.Namespace; - if (te != null && te.IncludeNamespace && !String.IsNullOrEmpty(te.Namespace)) + var ns = t.Namespace; + if (te != null && te.IncludeNamespace && !string.IsNullOrEmpty(te.Namespace)) { ns = te.Namespace; } @@ -224,15 +270,15 @@ public static string GetNamespace(this Type t, bool distinguishAutoTypes = false var tc = ConfigurationRepository.Instance.ForType(t); var ti = ConfigurationRepository.Instance.ForType(t); if (tc == null && ti == null) return t.Namespace; - string nameFromAttr = tc != null ? tc.Namespace : ti.Namespace; - bool includeNamespace = tc != null ? tc.IncludeNamespace : ti.IncludeNamespace; - if (!includeNamespace) return distinguishAutoTypes ? "-" : String.Empty; - if (!String.IsNullOrEmpty(nameFromAttr)) return nameFromAttr; + var nameFromAttr = tc != null ? tc.Namespace : ti.Namespace; + var includeNamespace = tc != null ? tc.IncludeNamespace : ti.IncludeNamespace; + if (!includeNamespace) return distinguishAutoTypes ? "-" : string.Empty; + if (!string.IsNullOrEmpty(nameFromAttr)) return nameFromAttr; return t.Namespace; } /// - /// Returns access modifier for specified field + /// Returns access modifier for specified field /// /// Field /// Access modifier string @@ -244,7 +290,7 @@ public static AccessModifier GetModifier(this FieldInfo fieldInfo) } /// - /// Returns access modifier for specified method + /// Returns access modifier for specified method /// /// Method /// Access modifier string @@ -256,7 +302,7 @@ public static AccessModifier GetModifier(this MethodInfo methodInfo) } /// - /// Returns access modifier for specified constructor + /// Returns access modifier for specified constructor /// /// Constructor /// Access modifier string @@ -268,7 +314,7 @@ public static AccessModifier GetModifier(this ConstructorInfo constructorInfo) } /// - /// Returns access modifier for specified constructor + /// Returns access modifier for specified constructor /// /// Property /// Access modifier string @@ -281,21 +327,21 @@ public static AccessModifier GetModifier(this PropertyInfo propertyInfo) } /// - /// Returns access modifier for specified type member + /// Returns access modifier for specified type member /// /// Type member /// Access modifier string public static AccessModifier GetModifier(this MemberInfo member) { - if (member is PropertyInfo) return GetModifier((PropertyInfo)member); - if (member is MethodInfo) return GetModifier((MethodInfo)member); - if (member is FieldInfo) return GetModifier((FieldInfo)member); + if (member is PropertyInfo) return GetModifier((PropertyInfo) member); + if (member is MethodInfo) return GetModifier((MethodInfo) member); + if (member is FieldInfo) return GetModifier((FieldInfo) member); return AccessModifier.Public; } /// - /// Determines if propercy is "bounced". - /// It means property with different accesor's access level + /// Determines if propercy is "bounced". + /// It means property with different accesor's access level /// /// Property /// True if property has different access levels for accessor @@ -308,7 +354,6 @@ public static bool IsBounceProperty(this PropertyInfo propertyInfo) g.IsPublic != s.IsPublic || g.IsFamily != s.IsFamily || g.IsPrivate != s.IsPrivate; - } internal static MethodBase GetMethodWithSameParameters(MethodBase[] methodsSet, Type[] parameters) @@ -319,8 +364,8 @@ internal static MethodBase GetMethodWithSameParameters(MethodBase[] methodsSet, var methodParams = method.GetParameters(); if (methodParams.Length != parameters.Length) continue; - bool parametersMatch = true; - for (int i = 0; i < parameters.Length; i++) + var parametersMatch = true; + for (var i = 0; i < parameters.Length; i++) { if (parameters[i] != methodParams[i].ParameterType) { @@ -338,7 +383,7 @@ internal static MethodBase GetMethodWithSameParameters(MethodBase[] methodsSet, } /// - /// Converts AccessModifier to corresponding TypeScript source text + /// Converts AccessModifier to corresponding TypeScript source text /// /// Access modifier /// Access modifier text @@ -355,7 +400,7 @@ public static string ToModifierText(this AccessModifier modifier) } /// - /// Converts AccessModifier to corresponding TypeScript source text + /// Converts AccessModifier to corresponding TypeScript source text /// /// Access modifier /// Access modifier text @@ -368,20 +413,7 @@ public static string ToModifierOmitPublic(this AccessModifier modifier) case AccessModifier.Protected: return "protected"; } - return String.Empty; + return string.Empty; } - - /// - /// Binding flags for searching all members - /// - public const BindingFlags MembersFlags = - BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static | - BindingFlags.DeclaredOnly; - - /// - /// Search predicate to exclude ignored and compiler-generated items - /// - public static readonly Func TypeScriptMemberSearchPredicate = - c => !ConfigurationRepository.Instance.IsIgnored(c) && c.GetCustomAttribute() == null; } } \ No newline at end of file diff --git a/Reinforced.Typings/TypeResolver.cs b/Reinforced.Typings/TypeResolver.cs index d2509fcf..f341a6e2 100644 --- a/Reinforced.Typings/TypeResolver.cs +++ b/Reinforced.Typings/TypeResolver.cs @@ -9,40 +9,60 @@ namespace Reinforced.Typings { /// - /// Type resolver. It is helper class to convert source types, members and parameter names to typescript ones + /// Type resolver. It is helper class to convert source types, members and parameter names to typescript ones /// public class TypeResolver { - private readonly Dictionary _defaultGenerators = new Dictionary(); - private readonly ITsCodeGenerator _defaultParameterGenerator; - private readonly ITsCodeGenerator _defaultInterfaceGenerator; private readonly ITsCodeGenerator _defaultClassGenerator; private readonly ITsCodeGenerator _defaultEnumGenerator; + private readonly Dictionary _defaultGenerators = new Dictionary(); + private readonly ITsCodeGenerator _defaultInterfaceGenerator; private readonly NamespaceCodeGenerator _defaultNsgenerator; + private readonly ITsCodeGenerator _defaultParameterGenerator; + private readonly Dictionary _generatorsCache = new Dictionary(); + + private readonly Dictionary _resolveCache = new Dictionary + { + {typeof (object), "any"}, + {typeof (void), "void"}, + {typeof (string), "string"}, + {typeof (char), "string"}, + {typeof (bool), "boolean"}, + {typeof (byte), "number"}, + {typeof (sbyte), "number"}, + {typeof (short), "number"}, + {typeof (ushort), "number"}, + {typeof (int), "number"}, + {typeof (uint), "number"}, + {typeof (long), "number"}, + {typeof (ulong), "number"}, + {typeof (float), "number"}, + {typeof (double), "number"}, + {typeof (decimal), "number"} + }; private readonly ExportSettings _settings; - private readonly Dictionary _generatorsCache = new Dictionary(); /// - /// Constructs new type resolver + /// Constructs new type resolver /// public TypeResolver(ExportSettings settings) { - _defaultGenerators[MemberTypes.Property] = new PropertyCodeGenerator { Settings = settings }; - _defaultGenerators[MemberTypes.Field] = new FieldCodeGenerator { Settings = settings }; - _defaultGenerators[MemberTypes.Method] = new MethodCodeGenerator { Settings = settings }; - _defaultGenerators[MemberTypes.Constructor] = new ConstructorCodeGenerator { Settings = settings }; - _defaultParameterGenerator = new ParameterCodeGenerator { Settings = settings }; - _defaultClassGenerator = new ClassCodeGenerator { Settings = settings }; - _defaultInterfaceGenerator = new InterfaceCodeGenerator { Settings = settings }; - _defaultEnumGenerator = new EnumGenerator { Settings = settings }; - _defaultNsgenerator = new NamespaceCodeGenerator { Settings = settings }; + _defaultGenerators[MemberTypes.Property] = new PropertyCodeGenerator {Settings = settings}; + _defaultGenerators[MemberTypes.Field] = new FieldCodeGenerator {Settings = settings}; + _defaultGenerators[MemberTypes.Method] = new MethodCodeGenerator {Settings = settings}; + _defaultGenerators[MemberTypes.Constructor] = new ConstructorCodeGenerator {Settings = settings}; + _defaultParameterGenerator = new ParameterCodeGenerator {Settings = settings}; + _defaultClassGenerator = new ClassCodeGenerator {Settings = settings}; + _defaultInterfaceGenerator = new InterfaceCodeGenerator {Settings = settings}; + _defaultEnumGenerator = new EnumGenerator {Settings = settings}; + _defaultNsgenerator = new NamespaceCodeGenerator {Settings = settings}; _settings = settings; } /// - /// Reteieves code generator instance for specified type member. - /// Also this method considers Typings attribute and instantiates generator specified there if necessary + /// Reteieves code generator instance for specified type member. + /// Also this method considers Typings attribute and instantiates generator specified there if necessary /// /// Type member info type /// Type member info @@ -62,29 +82,29 @@ public ITsCodeGenerator GeneratorFor(T member, ExportSettings settings) wh return LazilyInstantiateGenerator(classAttr.DefaultMethodCodeGenerator, settings); } } - var gen = (ITsCodeGenerator)_defaultGenerators[member.MemberType]; + var gen = (ITsCodeGenerator) _defaultGenerators[member.MemberType]; gen.Settings = settings; return gen; } /// - /// Retrieves code generator for ParameterInfo (since ParameterInfo does not derive from MemberInfo). - /// Also this method considers Typings attribute and instantiates generator specified there if necessary + /// Retrieves code generator for ParameterInfo (since ParameterInfo does not derive from MemberInfo). + /// Also this method considers Typings attribute and instantiates generator specified there if necessary /// /// Parameter info /// Export settings /// Code generator for parameter info public ITsCodeGenerator GeneratorFor(ParameterInfo member, ExportSettings settings) { - var attr =ConfigurationRepository.Instance.ForMember(member); + var attr = ConfigurationRepository.Instance.ForMember(member); var fromAttr = GetFromAttribute(attr, settings); if (fromAttr != null) return fromAttr; return _defaultParameterGenerator; } /// - /// Retrieves code generator for specified type - /// Also this method considers Typings attribute and instantiates generator specified there if necessary + /// Retrieves code generator for specified type + /// Also this method considers Typings attribute and instantiates generator specified there if necessary /// /// Type info /// Export settings @@ -95,9 +115,9 @@ public ITsCodeGenerator GeneratorFor(Type member, ExportSettings settings) var fromAttr = GetFromAttribute(attr, settings); if (fromAttr != null) return fromAttr; - bool isClass = attr is TsClassAttribute; - bool isInterface = attr is TsInterfaceAttribute; - bool isEnum = attr is TsEnumAttribute; + var isClass = attr is TsClassAttribute; + var isInterface = attr is TsInterfaceAttribute; + var isEnum = attr is TsEnumAttribute; if (isClass) return _defaultClassGenerator; if (isInterface) return _defaultInterfaceGenerator; @@ -106,7 +126,7 @@ public ITsCodeGenerator GeneratorFor(Type member, ExportSettings settings) } /// - /// Retrieves code generator for namespaces + /// Retrieves code generator for namespaces /// /// public NamespaceCodeGenerator GeneratorForNamespace(ExportSettings settings) @@ -132,36 +152,20 @@ private ITsCodeGenerator LazilyInstantiateGenerator(Type generatorType, Ex if (!_generatorsCache.ContainsKey(generatorType)) { _generatorsCache[generatorType] = Activator.CreateInstance(generatorType); - var gen = (ITsCodeGenerator)_generatorsCache[generatorType]; + var gen = (ITsCodeGenerator) _generatorsCache[generatorType]; gen.Settings = settings; } - return (ITsCodeGenerator)_generatorsCache[generatorType]; + return (ITsCodeGenerator) _generatorsCache[generatorType]; } } private string GetConcreteGenericArguments(Type t) { - if (!t.IsGenericType) return String.Empty; + if (!t.IsGenericType) return string.Empty; var args = t.GetGenericArguments(); - return String.Format("<{0}>", string.Join(", ", args.Select(ResolveTypeName))); + return string.Format("<{0}>", string.Join(", ", args.Select(ResolveTypeName))); } - private readonly Dictionary _resolveCache = new Dictionary() - { - {typeof(object),"any"}, - {typeof(void),"void"}, - {typeof(string),"string"}, - {typeof(char),"string"}, - {typeof(bool),"boolean"}, - {typeof(byte),"number"},{typeof(sbyte),"number"},{ - typeof(short),"number"},{typeof(ushort),"number"},{ - typeof(int),"number"},{typeof(uint),"number"},{ - typeof(long),"number"},{typeof(ulong),"number"},{ - typeof(float),"number"},{typeof(double),"number"},{ - typeof(decimal),"number"} - - }; - private string Cache(Type t, string name) { _resolveCache[t] = name; @@ -171,14 +175,15 @@ private string Cache(Type t, string name) private string TruncateNamespace(string typeName) { if (string.IsNullOrEmpty(_settings.CurrentNamespace)) return typeName; - return typeName.Replace(_settings.CurrentNamespace, String.Empty).Trim('.'); + return typeName.Replace(_settings.CurrentNamespace, string.Empty).Trim('.'); } /// - /// Returns typescript-friendly type name for specified type. - /// This method successfully handles dictionaries, IEnumerables, arrays, another TsExport-ed types, void, delegates, most of CLR built-in types, parametrized types etc. - /// It also considers Ts*-attributes while resolving type names - /// If it cannot handle anything then it will return "any" + /// Returns typescript-friendly type name for specified type. + /// This method successfully handles dictionaries, IEnumerables, arrays, another TsExport-ed types, void, delegates, + /// most of CLR built-in types, parametrized types etc. + /// It also considers Ts*-attributes while resolving type names + /// If it cannot handle anything then it will return "any" /// /// Specified type /// Typescript-friendly type name @@ -189,12 +194,15 @@ public string ResolveTypeName(Type t) var td = ConfigurationRepository.Instance.ForType(t); if (td != null) { - string ns = t.Namespace; - if (!td.IncludeNamespace) ns = String.Empty; + var ns = t.Namespace; + if (!td.IncludeNamespace) ns = string.Empty; if (!string.IsNullOrEmpty(td.Namespace)) ns = td.Namespace; - string name = t.GetName() + GetConcreteGenericArguments(t); - if (string.IsNullOrEmpty(ns)) { return Cache(t, name); } + var name = t.GetName() + GetConcreteGenericArguments(t); + if (string.IsNullOrEmpty(ns)) + { + return Cache(t, name); + } return Cache(t, string.Format("{0}.{1}", ns, name)); } @@ -204,11 +212,14 @@ public string ResolveTypeName(Type t) } if (t.IsDictionary()) { - if (!t.IsGenericType) { return Cache(t, "{ [key: any]: any }"); } + if (!t.IsGenericType) + { + return Cache(t, "{ [key: any]: any }"); + } var gargs = t.GetGenericArguments(); var key = ResolveTypeName(gargs[0]); var value = ResolveTypeName(gargs[1]); - var name = String.Format("{{ [key: {0}]: {1} }}", key, value); + var name = string.Format("{{ [key: {0}]: {1} }}", key, value); return Cache(t, name); } if (t.IsNongenericEnumerable()) @@ -221,17 +232,15 @@ public string ResolveTypeName(Type t) { return Cache(t, ResolveTypeName(t.GetElementType()) + "[]"); } - else + var enumerable = + t.GetInterfaces() + .FirstOrDefault(c => c.IsGenericType && c.GetGenericTypeDefinition() == typeof (IEnumerable<>)); + if (enumerable == null) { - var enumerable = t.GetInterfaces().FirstOrDefault(c => c.IsGenericType && c.GetGenericTypeDefinition() == typeof (IEnumerable<>)); - if (enumerable == null) - { - if (t.IsGenericType && t.GetGenericTypeDefinition() == typeof (IEnumerable<>)) enumerable = t; - } - if (enumerable == null) return Cache(t, "any[]"); - return Cache(t, ResolveTypeName(enumerable.GetArg()) + "[]"); + if (t.IsGenericType && t.GetGenericTypeDefinition() == typeof (IEnumerable<>)) enumerable = t; } - + if (enumerable == null) return Cache(t, "any[]"); + return Cache(t, ResolveTypeName(enumerable.GetArg()) + "[]"); } if (t.IsGenericParameter) @@ -244,7 +253,7 @@ public string ResolveTypeName(Type t) } return Cache(t, t.Name); } - if (typeof(MulticastDelegate).IsAssignableFrom(t.BaseType)) + if (typeof (MulticastDelegate).IsAssignableFrom(t.BaseType)) { var methodInfo = t.GetMethod("Invoke"); return Cache(t, ConstructFunctionType(methodInfo)); @@ -261,13 +270,13 @@ internal void PrintCacheInfo() private string ConstructFunctionType(MethodInfo methodInfo) { var retType = ResolveTypeName(methodInfo.ReturnType); - StringBuilder sb = new StringBuilder(); + var sb = new StringBuilder(); sb.Append("("); - int argAggreagtor = 0; - bool first = true; + var argAggreagtor = 0; + var first = true; foreach (var parameterInfo in methodInfo.GetParameters()) { - string argName = argAggreagtor > 0 ? "arg" + argAggreagtor : "arg"; + var argName = argAggreagtor > 0 ? "arg" + argAggreagtor : "arg"; var typeName = ResolveTypeName(parameterInfo.ParameterType); if (!first) { @@ -284,4 +293,4 @@ private string ConstructFunctionType(MethodInfo methodInfo) return sb.ToString(); } } -} +} \ No newline at end of file diff --git a/Reinforced.Typings/WriterWrapper.cs b/Reinforced.Typings/WriterWrapper.cs index 7e2775a2..c287ecd0 100644 --- a/Reinforced.Typings/WriterWrapper.cs +++ b/Reinforced.Typings/WriterWrapper.cs @@ -1,5 +1,4 @@ -using System; -using System.IO; +using System.IO; #pragma warning disable 1591 @@ -14,7 +13,7 @@ public class WriterWrapper public WriterWrapper(TextWriter writer) { _writer = writer; - _tabsLine = String.Empty; + _tabsLine = string.Empty; } private void AppendTabs() @@ -33,9 +32,10 @@ public void UnTab() if (_tabsCount > 0) _tabsCount--; _tabsLine = new string('\t', _tabsCount); } + public void WriteIndented(string str) { - string[] result = str.Split('\n'); + var result = str.Split('\n'); foreach (var s in result) { AppendTabs(); @@ -44,10 +44,11 @@ public void WriteIndented(string str) } _writer.WriteLine(); } + public void WriteIndented(string format, params object[] args) { var formatted = string.Format(format, args); - string[] result = formatted.Split('\n'); + var result = formatted.Split('\n'); foreach (var s in result) { AppendTabs(); @@ -56,10 +57,12 @@ public void WriteIndented(string format, params object[] args) } _writer.WriteLine(); } + public void Indent() { AppendTabs(); } + public void Write(bool value) { _writer.Write(value); @@ -129,6 +132,7 @@ public void Br() { _writer.WriteLine(); } + public void WriteLine() { AppendTabs(); diff --git a/Reinforced.Typings/Xmldoc/DocumentationManager.cs b/Reinforced.Typings/Xmldoc/DocumentationManager.cs index 0ffbd664..607fb3e1 100644 --- a/Reinforced.Typings/Xmldoc/DocumentationManager.cs +++ b/Reinforced.Typings/Xmldoc/DocumentationManager.cs @@ -6,17 +6,21 @@ using System.Text; using System.Xml.Serialization; using Reinforced.Typings.Xmldoc.Model; + // ReSharper disable PossibleNullReferenceException namespace Reinforced.Typings.Xmldoc { /// - /// XMLDOC documentation manager + /// XMLDOC documentation manager /// public class DocumentationManager { + private readonly Dictionary _documentationCache = + new Dictionary(); + private bool _isDocumentationExists; - private readonly Dictionary _documentationCache = new Dictionary(); + internal DocumentationManager(string docFilePath) { CacheDocumentation(docFilePath); @@ -36,11 +40,11 @@ internal void CacheDocumentation(string docFilePath) if (!File.Exists(docFilePath)) return; try { - XmlSerializer ser = new XmlSerializer(typeof(Documentation)); + var ser = new XmlSerializer(typeof (Documentation)); Documentation documentation; using (var fs = File.OpenRead(docFilePath)) { - documentation = (Documentation)ser.Deserialize(fs); + documentation = (Documentation) ser.Deserialize(fs); } foreach (var documentationMember in documentation.Members) { @@ -53,7 +57,7 @@ internal void CacheDocumentation(string docFilePath) _isDocumentationExists = false; } } - + private static string GetDocFriendlyParameterName(Type parameterType, Dictionary typeGenericsDict, Dictionary methodGenericArgsDict) @@ -75,17 +79,16 @@ private static string GetDocFriendlyParameterName(Type parameterType, name = name.Substring(0, quote); var genericParams = parameterType.GetGenericArguments() .Select(c => GetDocFriendlyParameterName(c, typeGenericsDict, methodGenericArgsDict)).ToArray(); - name = String.Format("{0}{{{1}}}", name, string.Join(",", genericParams)); + name = string.Format("{0}{{{1}}}", name, string.Join(",", genericParams)); return name; - } return parameterType.FullName.Trim('&'); } - private string GetIdentifierForMethod(MethodBase method,string name) + private string GetIdentifierForMethod(MethodBase method, string name) { var isCtor = name == "#ctor"; - StringBuilder sb = new StringBuilder(String.Format("M:{0}.{1}", method.DeclaringType.FullName, name)); + var sb = new StringBuilder(string.Format("M:{0}.{1}", method.DeclaringType.FullName, name)); if (!isCtor) { var cnt = method.GetGenericArguments().Length; @@ -96,17 +99,18 @@ private string GetIdentifierForMethod(MethodBase method,string name) { sb.Append('('); - var typeGenericsDict = + var typeGenericsDict = method.DeclaringType.GetGenericArguments() - .Select((a, i) => new { a, i }) - .ToDictionary(c => c.a, c => c.i); // type -> `0, type -> `1 + .Select((a, i) => new {a, i}) + .ToDictionary(c => c.a, c => c.i); // type -> `0, type -> `1 + - - var methodGenericArgsDict = isCtor? new Dictionary() : - method.GetGenericArguments() - .Select((a, i) => new { a, i }) - .ToDictionary(c => c.a, c => c.i); //type -> ``0, type -> ``1 - List names = new List(); + var methodGenericArgsDict = isCtor + ? new Dictionary() + : method.GetGenericArguments() + .Select((a, i) => new {a, i}) + .ToDictionary(c => c.a, c => c.i); //type -> ``0, type -> ``1 + var names = new List(); foreach (var param in prs) { var friendlyName = GetDocFriendlyParameterName(param.ParameterType, typeGenericsDict, @@ -114,7 +118,7 @@ private string GetIdentifierForMethod(MethodBase method,string name) if (param.IsOut || param.ParameterType.IsByRef) friendlyName = friendlyName + "@"; names.Add(friendlyName); } - sb.Append(String.Join(",", names)); + sb.Append(string.Join(",", names)); sb.Append(')'); } return sb.ToString(); @@ -124,31 +128,38 @@ private string GetPrefix(MemberTypes mt) { switch (mt) { - - case MemberTypes.Property:return "P"; - case MemberTypes.Field:return "F"; - case MemberTypes.Method:return "M"; - case MemberTypes.Event:return "E"; + case MemberTypes.Property: + return "P"; + case MemberTypes.Field: + return "F"; + case MemberTypes.Method: + return "M"; + case MemberTypes.Event: + return "E"; } - return String.Empty; + return string.Empty; } + private string GetIdentifierForMember(MemberInfo member) { - if (member is MethodInfo) return GetIdentifierForMethod((MethodBase) member,member.Name); - string id = String.Format("{0}:{1}.{2}",GetPrefix(member.MemberType),member.DeclaringType.FullName,member.Name); + if (member is MethodInfo) return GetIdentifierForMethod((MethodBase) member, member.Name); + var id = string.Format("{0}:{1}.{2}", GetPrefix(member.MemberType), member.DeclaringType.FullName, + member.Name); return id; } + private string GetIdentifierForType(Type type) { - return String.Format("T:{0}",type.FullName); + return string.Format("T:{0}", type.FullName); } + private string GetIdentifierForConstructor(ConstructorInfo constructor) { return GetIdentifierForMethod(constructor, "#ctor"); } /// - /// Outputs documentation for class member + /// Outputs documentation for class member /// /// Class member /// Text writer @@ -172,7 +183,7 @@ public void WriteDocumentation(MemberInfo member, WriterWrapper sw) } /// - /// Outputs documentation for method + /// Outputs documentation for method /// /// Method /// Text writer @@ -199,11 +210,10 @@ public void WriteDocumentation(MethodInfo method, WriterWrapper sw) Line(sw, string.Format("@returns {0}", doc.Returns.Text)); } End(sw); - } /// - /// Outputs documentation for constructor + /// Outputs documentation for constructor /// /// Constructor /// Text writer @@ -225,15 +235,13 @@ public void WriteDocumentation(ConstructorInfo constructor, WriterWrapper sw) Line(sw, "@constructor"); if (doc.HasParameters()) { - WriteParametersDoc(constructor.GetParameters(), doc, sw); } End(sw); - } /// - /// Outputs documentation for type + /// Outputs documentation for type /// /// Type /// Text writer @@ -258,7 +266,7 @@ private void WriteParametersDoc(ParameterInfo[] parameters, DocumentationMember var doc = docMember.Parameters.SingleOrDefault(c => c.Name == parameterInfo.Name); if (doc == null) continue; var name = parameterInfo.GetName(); - Line(sw, String.Format("@param {0} {1}", name, doc.Description)); + Line(sw, string.Format("@param {0} {1}", name, doc.Description)); } } @@ -270,7 +278,7 @@ private void Begin(WriterWrapper sw) private void Summary(WriterWrapper sw, string summary) { if (string.IsNullOrEmpty(summary)) return; - var summaryLines = summary.Split(new[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries); + var summaryLines = summary.Split(new[] {'\r', '\n'}, StringSplitOptions.RemoveEmptyEntries); foreach (var summaryLine in summaryLines) { Line(sw, summaryLine); @@ -284,7 +292,7 @@ private void Line(WriterWrapper sw, string line = null) } /// - /// Writes output comment with automatic multiline division + /// Writes output comment with automatic multiline division /// /// Output writer /// Comment (multiline allowed) @@ -292,7 +300,7 @@ public void WriteComment(WriterWrapper sw, string comment) { sw.Br(); sw.Indent(); - var lines = comment.Split(new[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries); + var lines = comment.Split(new[] {'\r', '\n'}, StringSplitOptions.RemoveEmptyEntries); if (lines.Length == 1) { sw.WriteLine("// {0} ", lines[0]); @@ -302,19 +310,16 @@ public void WriteComment(WriterWrapper sw, string comment) Begin(sw); foreach (var line in lines) { - Line(sw,line); + Line(sw, line); } End(sw); sw.Br(); } - } - + private void End(WriterWrapper sw) { sw.WriteLine("*/"); } - - } -} +} \ No newline at end of file diff --git a/Reinforced.Typings/Xmldoc/Model/DocumentationMemberExtensions.cs b/Reinforced.Typings/Xmldoc/Model/DocumentationMemberExtensions.cs index 154137e8..e2f48a41 100644 --- a/Reinforced.Typings/Xmldoc/Model/DocumentationMemberExtensions.cs +++ b/Reinforced.Typings/Xmldoc/Model/DocumentationMemberExtensions.cs @@ -12,7 +12,7 @@ public static DocumentationMemberType MeberType(this string name) if (name.StartsWith("E:")) return DocumentationMemberType.Event; if (name.StartsWith("N:")) return DocumentationMemberType.Namespace; if (name.StartsWith("F:")) return DocumentationMemberType.Field; - + return DocumentationMemberType.Unknown; } @@ -30,6 +30,5 @@ public static bool HasReturns(this DocumentationMember dm) { return dm.Returns != null && !string.IsNullOrEmpty(dm.Returns.Text); } - } } \ No newline at end of file diff --git a/Reinforced.Typings/Xmldoc/Model/DocumentationMemberType.cs b/Reinforced.Typings/Xmldoc/Model/DocumentationMemberType.cs index 6a2eef09..6f4b56d0 100644 --- a/Reinforced.Typings/Xmldoc/Model/DocumentationMemberType.cs +++ b/Reinforced.Typings/Xmldoc/Model/DocumentationMemberType.cs @@ -1,4 +1,6 @@ + #pragma warning disable 1591 + namespace Reinforced.Typings.Xmldoc.Model { public enum DocumentationMemberType diff --git a/Reinforced.Typings/Xmldoc/Model/Model.cs b/Reinforced.Typings/Xmldoc/Model/Model.cs index bf2ebfa8..edbeb286 100644 --- a/Reinforced.Typings/Xmldoc/Model/Model.cs +++ b/Reinforced.Typings/Xmldoc/Model/Model.cs @@ -1,14 +1,14 @@ -using System; -using System.Xml; +using System.Xml; using System.Xml.Serialization; + #pragma warning disable 1591 namespace Reinforced.Typings.Xmldoc.Model { [XmlRoot("doc")] [XmlType("doc")] - [XmlInclude(typeof(DocumentationMember))] - [XmlInclude(typeof(DocumentationParameter))] + [XmlInclude(typeof (DocumentationMember))] + [XmlInclude(typeof (DocumentationParameter))] public class Documentation { [XmlArray("members")] @@ -40,20 +40,19 @@ public string Name [XmlElement(ElementName = "param")] public DocumentationParameter[] Parameters { get; set; } + [XmlElement(ElementName = "returns")] + public DocumentationReturns Returns { get; set; } + public override string ToString() { - return String.Format("({0}) {1}", MemberType, Name); + return string.Format("({0}) {1}", MemberType, Name); } - - [XmlElement(ElementName = "returns")] - public DocumentationReturns Returns { get; set; } } public class DocumentationParameter : XmlIgnoreInner { public string Name { get; set; } - public string Description { get; set; } public override void ReadXml(XmlReader reader) @@ -62,7 +61,6 @@ public override void ReadXml(XmlReader reader) Description = reader.ReadInnerXml().Trim(); if (Description.Contains("this method interface declaration")) { - } } @@ -104,4 +102,4 @@ public override string ToString() return Text; } } -} +} \ No newline at end of file diff --git a/Reinforced.Typings/Xmldoc/Model/XmlIgnoreInner.cs b/Reinforced.Typings/Xmldoc/Model/XmlIgnoreInner.cs index 4e2befae..e47852cf 100644 --- a/Reinforced.Typings/Xmldoc/Model/XmlIgnoreInner.cs +++ b/Reinforced.Typings/Xmldoc/Model/XmlIgnoreInner.cs @@ -2,6 +2,7 @@ using System.Xml; using System.Xml.Schema; using System.Xml.Serialization; + #pragma warning disable 1591 namespace Reinforced.Typings.Xmldoc.Model diff --git a/package/Reinforced.Typings.nuspec b/package/Reinforced.Typings.nuspec index 51c79728..073b9646 100644 --- a/package/Reinforced.Typings.nuspec +++ b/package/Reinforced.Typings.nuspec @@ -2,7 +2,7 @@ Reinforced.Typings - 1.0.5 + 1.0.6 Reinforced.Typings Pavel B. Novikov Pavel B. Novikov @@ -16,6 +16,9 @@ mvc, web, typescript https://github.com/reinforced/Reinforced.Typings/blob/master/LICENSE.md + * 1.0.6 + * * Improved multiple files export + * * Fixed automatic references bugs * 1.0.5 * * Fluent configuration. * * Added more XMLDOC documentation.