private static WebGenParam CalculateReturnType(string sourceModelNamespace, TypeReference returnType) { return(returnType == null || returnType.FullName == "System.Void" || returnType.FullName == "System.Threading.Tasks.Task" ? null : returnType.Namespace == "System" //|| returnType.Namespace.StartsWith("System.") ? new WebGenParam { Name = returnType.Name, RelativeNamespace = null, DataType = returnType } : returnType.Name == "Task`1" && returnType is GenericInstanceType ? CalculateReturnType(sourceModelNamespace, (returnType as GenericInstanceType).GenericArguments.First()) : (returnType.Name == "List`1" || returnType.Name == "IEnumerable`1") && returnType is GenericInstanceType ? new WebGenParam { Name = (returnType as GenericInstanceType).GenericArguments.First().Name, RelativeNamespace = DtGenUtil.CalculateRelativeNamespace((returnType as GenericInstanceType).GenericArguments.First().Namespace, sourceModelNamespace) .ToList(), DataType = returnType } : new WebGenParam { Name = returnType.Name, RelativeNamespace = DtGenUtil.CalculateRelativeNamespace(returnType.Namespace, sourceModelNamespace) .ToList(), DataType = returnType }); }
private static IEnumerable <GenClass> ReadClasses(string assemblyPath, string sourceNamespace) { var assemb = Assembly.LoadFile(assemblyPath); // var test = (from t in assemb.GetTypes() // where (t.Namespace ?? "").StartsWith(sourceNamespace) // && t.Name.StartsWith("<") // select t) // .ToList(); return(from t in assemb.GetTypes() where (t.Namespace ?? "").StartsWith(sourceNamespace) && !t.IsNested && t.IsClass && t.GetProperties().Any() select new GenClass { Name = t.Name, Properties = t.GetProperties() .Select(p => new GenProperty { Name = p.Name, PropType = p.PropertyType, CanRead = p.CanRead, CanWrite = p.CanWrite }) .ToList(), RelativeDotNetNamespace = DtGenUtil.CalculateRelativeNamespace(t.Namespace, sourceNamespace) .ToList() }); }
private static IEnumerable <GenWebClass> ReadClasses(string assemblyPath, string sourceNamespace, string sourceModelNamespace) { //var types = GetTypes(assemblyPath); // var test = (from t in assemb.GetTypes() // where (t.Namespace ?? "").StartsWith(sourceNamespace) // && t.Name.StartsWith("<") // select t) // .ToList(); return(from t in GetTypes(assemblyPath) where (t.Namespace ?? "").StartsWith(sourceNamespace) && !t.IsNested && t.IsClass && t.GetMethods().Any(m => m.CustomAttributes.Any(a => a.AttributeType.FullName == "System.Web.Http.HttpPostAttribute") && m.Parameters.Count <= 1) && t.BaseType.FullName == "System.Web.Http.ApiController" select new GenWebClass { Name = t.Name, Methods = t.GetMethods().Where(m => m.CustomAttributes.Any(a => a.AttributeType.FullName == "System.Web.Http.HttpPostAttribute") && m.Parameters.Count <= 1) .Select(m => new GenWebMethod { Name = m.Name, Parameter = m.Parameters .Select(c => c.ParameterType is GenericInstanceType ? new WebGenParam { Name = (c.ParameterType as GenericInstanceType).GenericArguments.First().Name, RelativeNamespace = DtGenUtil.CalculateRelativeNamespace((c.ParameterType as GenericInstanceType).GenericArguments.First().Namespace, sourceModelNamespace) .ToList(), DataType = c.ParameterType } : new WebGenParam { Name = c.ParameterType.Name, RelativeNamespace = DtGenUtil.CalculateRelativeNamespace(c.ParameterType.Namespace, sourceModelNamespace) .ToList(), DataType = c.ParameterType }) .SingleOrDefault(), Return = CalculateReturnType(sourceModelNamespace, m.MethodReturnType == null ? null : m.MethodReturnType.ReturnType) }) .ToList(), RelativeNamespace = DtGenUtil.CalculateRelativeNamespace(t.Namespace, sourceNamespace) .ToList() }); }
private static IEnumerable <GenEnum> ReadEnums(string assemblyPath, string sourceNamespace) { var assemb = Assembly.LoadFile(assemblyPath); // var test = (from t in assemb.GetTypes() // where (t.Namespace ?? "").StartsWith(sourceNamespace) // && t.Name.StartsWith("<") // select t) // .ToList(); return(from t in assemb.GetTypes() where (t.Namespace ?? "").StartsWith(sourceNamespace) && !t.IsNested && t.IsEnum && Enum.GetValues(t).Length > 0 select new GenEnum { Name = t.Name, Values = ConvertToGenEnum(Enum.GetValues(t), t) .ToList(), RelativeNamespace = DtGenUtil.CalculateRelativeNamespace(t.Namespace, sourceNamespace) .ToList() }); }