public static clsFragmentPart[] ArrayFromString(string strFragment) { List <clsFragmentPart> aryRet = new List <clsFragmentPart>(); foreach (Match mch in Regex.Matches(strFragment, @"((?<part>([\w\d_]+))(\((?<params>.*?)\))?(\[(?<indexer>.*?)\])?\.?)+")) { clsFragmentPart objPart = new clsFragmentPart(); Group groupParse = mch.Groups["part"]; if (groupParse.Success) { objPart.Name = groupParse.Value; } groupParse = mch.Groups["params"]; if (groupParse.Success) { objPart.Parameters = groupParse.Value; } groupParse = mch.Groups["indexer"]; if (groupParse.Success) { objPart.Indexer = groupParse.Value; } aryRet.Add(objPart); } return(aryRet.ToArray()); }
public static void GetProperty(clsFragmentPart part, object context, Type obj, out PropertyInfo propRet, out object objRet) { propRet = null; objRet = null; object[] aryParams = clsFragmentPart.GetParamObjectArray(context, part.IndexList); foreach (PropertyInfo t in obj.GetProperties()) { if (!IsPropertyBrowsable(t)) { continue; } if (t.IsSpecialName) { continue; } if (t.Name != part.Name) { continue; } ParameterInfo[] paramsItm = t.GetIndexParameters(); if (paramsItm.Length != aryParams.Length) { continue; } bool bolSignatureValid = true; for (int itr = 0; itr < paramsItm.Length; itr++) { if (aryParams[itr] == null) { bolSignatureValid = false; break; } if (aryParams[itr].GetType() != paramsItm[itr].ParameterType) { bolSignatureValid = false; break; } } if (!bolSignatureValid) { continue; } propRet = t; objRet = t.GetValue(context, aryParams); break; } }
public static void GetMethod(clsFragmentPart part, object context, Type obj, out MethodInfo methodRet, out object objRet) { methodRet = null; objRet = null; object[] aryParams = clsFragmentPart.GetParamObjectArray(context, part.ParamList); foreach (MethodInfo t in obj.GetMethods()) { if (!IsMemberBrowsable(t)) { continue; } if (t.IsSpecialName) { continue; } if (t.Name != part.Name) { continue; } ParameterInfo[] paramsItm = t.GetParameters(); if (paramsItm.Length != aryParams.Length) { continue; } bool bolSignatureValid = true; for (int itr = 0; itr < paramsItm.Length; itr++) { if (aryParams[itr] == null) { bolSignatureValid = false; break; } if (aryParams[itr].GetType() != paramsItm[itr].ParameterType) { bolSignatureValid = false; break; } } if (!bolSignatureValid) { continue; } methodRet = t; objRet = t.Invoke(context, aryParams); break; } }