public void T4ModelInfoTest() { //OSharp.UnitTest.Infrastructure const string pattern = "(?<=OSharp.).*(?=.Infrastructure)"; Type type = typeof(TestEntity); T4ModelInfo modelInfo = new T4ModelInfo(type, pattern); Assert.Equal("UnitTest", modelInfo.ModuleName); }
public void T4ModelInfoTest() { //OSharp.UnitTest.Infrastructure const string pattern = "(?<=OSharp.).*(?=.Infrastructure)"; Type type = typeof(TestEntity); T4ModelInfo modelInfo = new T4ModelInfo(type, pattern); Assert.Equal("UnitTest", modelInfo.ModuleName); }
private static void Method09() { Assembly assembly = Assembly.Load("Mes.Demo.Contracts"); Type baseType = typeof(EntityBase<>); IEnumerable<Type> modelTypes = assembly.GetTypes().Where(m => baseType.IsGenericAssignableFrom(m) && !m.IsAbstract); foreach (Type modelType in modelTypes) { T4ModelInfo model = new T4ModelInfo(modelType, true); if (model.ModuleName == "Test") { foreach (var pro in model.Properties) { List<string> igoreList = new List<string> { "CreatedTime", "Timestamp", "IsDeleted" }; if (!igoreList.Contains(pro.Name)) { List<string> igoreString = new List<string> { "Timestamp" }; igoreString.Contains(pro.Name); if (pro.PropertyType.Name == "ICollection`1") Console.WriteLine(pro.PropertyType.GenericTypeArguments.FirstOrDefault().Name); else if (pro.CustomAttributes != null) { foreach (var customAttribute in pro.CustomAttributes) { switch (customAttribute.AttributeType.Name) { case "RequiredAttribute": Console.WriteLine("[Required]"); break; case "StringLengthAttribute": Console.WriteLine("[StringLength({0})]", customAttribute.ConstructorArguments[0]); break; } string constructorArgumentsString = ""; if (customAttribute.ConstructorArguments != null) { Console.Write(String.Join(",", customAttribute.ConstructorArguments.Select(m => m.Value).ToArray())); } Console.Write("[" + customAttribute.AttributeType.Name.Replace("Attribute", "") + "]"); } Console.WriteLine(); Console.WriteLine(pro.PropertyType.Name); } } // pro.CustomAttributes.FirstOrDefault().ToString(); } } //实体映射类 } }
private static void Method09() { Assembly assembly = Assembly.Load("Mes.Demo.Contracts"); Type baseType = typeof(EntityBase<>); IEnumerable<Type> modelTypes = assembly.GetTypes().Where(m => baseType.IsGenericAssignableFrom(m) && !m.IsAbstract); foreach (Type modelType in modelTypes) { T4ModelInfo model = new T4ModelInfo(modelType, true); if (model.ModuleName == "Test") { foreach (var pro in model.Properties) { List<string> igoreList = new List<string> { "CreatedTime", "Timestamp", "IsDeleted" }; if (!igoreList.Contains(pro.Name)) { List<string> igoreString = new List<string> { "Timestamp" }; igoreString.Contains(pro.Name); if (pro.PropertyType.Name == "ICollection`1") Console.WriteLine(pro.PropertyType.GenericTypeArguments.FirstOrDefault().Name); else if (pro.CustomAttributes != null) { foreach (var customAttribute in pro.CustomAttributes) { switch (customAttribute.AttributeType.Name) { case "RequiredAttribute": Console.WriteLine("[Required]"); break; case "StringLengthAttribute": Console.WriteLine("[StringLength({0})]", customAttribute.ConstructorArguments[0]); break; } string constructorArgumentsString = ""; if (customAttribute.ConstructorArguments != null) { Console.Write(String.Join(",", customAttribute.ConstructorArguments.Select(m => m.Value).ToArray())); } Console.Write("[" + customAttribute.AttributeType.Name.Replace("Attribute", "") + "]"); } Console.WriteLine(); Console.WriteLine(pro.PropertyType.Name); } } // pro.CustomAttributes.FirstOrDefault().ToString(); } } //实体映射类 } }