public override ExPropertyInfo SearchExProperty(string name) { var propertyArray = this.SharpType.GetProperties(); foreach (var property in propertyArray) { if (!ReflectionUtil.IsDeclare(this.SharpType, property)) { continue; } /* 映射类可能有多个同义的属性名称对应同一个实际属性 */ ZCodeAttribute[] arrs = AttributeUtil.GetAttributes <ZCodeAttribute>(property); foreach (var zcode in arrs) { if (zcode.Code == name) { return(new ExPropertyInfo(property, true, name)); } } } if (ParentMapping != null && !isRoot()) { ExPropertyInfo epi = ParentMapping.SearchExProperty(name); if (epi != null) { epi.IsSelf = false; return(epi); } } return(null); }
public override ExPropertyInfo[] GetPropertyInfoes() { List <ExPropertyInfo> exList = new List <ExPropertyInfo>(); var propertyArray = this.SharpType.GetProperties(); foreach (var property in propertyArray) { ZCodeAttribute[] arrs = AttributeUtil.GetAttributes <ZCodeAttribute>(property); foreach (var zcattr in arrs) { ExPropertyInfo exPI = new ExPropertyInfo(property, true, zcattr.Code); exList.Add(exPI); } } if (ParentMapping != null && !isRoot()) { ExPropertyInfo[] pArr = ParentMapping.GetPropertyInfoes(); foreach (ExPropertyInfo pitem in pArr) { pitem.IsSelf = false; } exList.AddRange(pArr); } return(exList.ToArray()); }
public override TKTProcDesc[] GetProces() { List <TKTProcDesc> list = new List <TKTProcDesc>(); var methodArray = this.SharpType.GetMethods(); foreach (var method in methodArray) { if (!ReflectionUtil.IsDeclare(SharpType, method)) { continue; } /* 映射类可能有多个同义的方法对应同一个实际方法 */ ZCodeAttribute[] attrs = AttributeUtil.GetAttributes <ZCodeAttribute>(method); ProcDescCodeParser parser = new ProcDescCodeParser(); parser.InitType(SharpType, method); foreach (ZCodeAttribute attr in attrs) { TKTProcDesc typeProcDesc = parser.Parser(attr.Code); ExMethodInfo exMethod = ZTypeUtil.CreatExMethodInfo(method, this.SharpType); typeProcDesc.ExMethod = exMethod; list.Add(typeProcDesc); } } if (ParentMapping != null && !isRoot()) { TKTProcDesc[] epi = ParentMapping.GetProces(); foreach (var pitem in epi) { pitem.ExMethod.IsSelf = false; } list.AddRange(epi); } return(list.ToArray()); }
public void GetAttributes_Expression() { var atts = AttributeUtil.GetAttributes <DisplayAttribute, ExpressionTestModel, PropertyInfo>(x => x.IntType, false); Assert.AreEqual("IntType", atts.First().Name); var atts2 = AttributeUtil.GetAttributes <RequiredAttribute, ExpressionTestModel, PropertyInfo>(x => x.StringType, false); Assert.IsNotEmpty(atts2); }
public static ZLMethodDesc[] GetProcDescs(ZLMethodInfo zmethod) { var markMethod = zmethod.MarkMethod; var sharpMethod = zmethod.SharpMethod; List <ZLMethodDesc> list = new List <ZLMethodDesc>(); ZCodeAttribute[] attrs = AttributeUtil.GetAttributes <ZCodeAttribute>(markMethod); foreach (ZCodeAttribute attr in attrs) { ZCodeParser parser = new ZCodeParser(sharpMethod.DeclaringType, zmethod); ZLMethodDesc typeProcDesc = parser.Parser(attr.Code); list.Add(typeProcDesc); } return(list.ToArray()); }
protected ZMethodDesc[] GetProcDesc(MethodInfo markMethod, MethodInfo sharpMethod) { List <ZMethodDesc> list = new List <ZMethodDesc>(); ZCodeAttribute[] attrs = AttributeUtil.GetAttributes <ZCodeAttribute>(markMethod); foreach (ZCodeAttribute attr in attrs) { //if (markMethod.Name == "SetTitle") //{ // Console.WriteLine("ZMethodInfo.SetTitle"); //} ZCodeParser parser = new ZCodeParser(sharpMethod.DeclaringType, sharpMethod); ZMethodDesc typeProcDesc = parser.Parser(attr.Code); typeProcDesc.ZMethod = this; //ZMethodInfo exMethod = ZTypeUtil.CreatExMethodInfo(method, this.SharpType); //typeProcDesc.ExMethod = exMethod; list.Add(typeProcDesc); } return(list.ToArray()); }
public override TKTProcDesc SearchProc(TKTProcDesc procDesc) { var methodArray = this.SharpType.GetMethods(); foreach (var method in methodArray) { if (!ReflectionUtil.IsDeclare(SharpType, method)) { continue; } /* 映射类可能有多个同义的方法对应同一个实际方法 */ ZCodeAttribute[] attrs = AttributeUtil.GetAttributes <ZCodeAttribute>(method); /* 编译器生成的类可能没有标注,没有标注的方法必定在ZMappingType上 */ if (attrs.Length == 0) { ExMethodInfo exMethod = ZTypeUtil.CreatExMethodInfo(method, this.SharpType); TKTProcDesc typeProcDesc = ProcDescHelper.CreateProcDesc(exMethod); if (typeProcDesc.Eq(procDesc)) { TKTProcDesc rdesc = ProcDescHelper.CreateProcDesc(exMethod); return(rdesc); } } else if (attrs.Length > 0) { ParameterInfo[] paramArray = method.GetParameters(); parser.InitType(SharpType, method); foreach (ZCodeAttribute attr in attrs) { ZCodeAttribute zCodeAttribute = attr as ZCodeAttribute; TKTProcDesc typeProcDesc = parser.Parser(zCodeAttribute.Code); if (method.IsStatic && !method.IsAbstract && typeProcDesc.HasSubject() && typeProcDesc.GetSubjectArg().ArgType == this.SharpType) { typeProcDesc = typeProcDesc.CreateTail(); } if (typeProcDesc.Eq(procDesc)) { ExMethodInfo exMethod = null;// getExMethod(method); /* 非 Abstract 的方法肯定从被映射的类中搜索 */ if (method.IsAbstract) { var method2 = searchMethodFromSharp(method); exMethod = ZTypeUtil.CreatExMethodInfo(method2, this.SharpType); //return exMethod; } else { exMethod = ZTypeUtil.CreatExMethodInfo(method, this.ZMappingType); //return exMethod; } typeProcDesc.ExMethod = exMethod; return(typeProcDesc); } } } } if (ParentMapping != null && !isRoot()) { var epi = ParentMapping.SearchProc(procDesc); if (epi != null) { //epi.IsSelf = false; return(epi); } } return(null); }
/// <summary> /// Gets the <see cref="FirestorePropertyAttribute.Name"/> of desired property that defines as <paramref name="propertySelector"/>. /// </summary> /// <typeparam name="T">Type of object from which you need to select the property.</typeparam> /// <param name="propertySelector">Property selector.</param> /// <returns> /// If the specified property exists and contains the <see cref="FirestorePropertyAttribute"/>, /// then this method will return the <see cref="FirestorePropertyAttribute.Name"/> value or null. /// </returns> public static string?GetFirestorePropertyName <T>(Expression <Func <T, object?> > propertySelector) { var attr = AttributeUtil.GetAttributes <FirestorePropertyAttribute, T, PropertyInfo>(propertySelector, true); return(attr.FirstOrDefault()?.Name); }