/// <summary> /// Adds view field path info. /// </summary> public void AddViewFieldPathInfo(string viewFieldPath, ViewFieldPathInfo viewFieldPathInfo) { if (_viewFieldPathInfo == null) { _viewFieldPathInfo = new Dictionary <string, ViewFieldPathInfo>(); } _viewFieldPathInfo.Add(viewFieldPath, viewFieldPathInfo); }
/// <summary> /// Tries to parse the view field path and get view field path info. Called only if we're the owner of the field. /// </summary> public bool ParseViewFieldPath() { SevereParseError = false; var viewTypeData = SourceView.ViewTypeData; var viewFieldPath = viewTypeData.GetViewFieldPathInfo(ViewFieldPath); if (viewFieldPath != null) { ViewFieldPathInfo = viewFieldPath; return(true); } ViewFieldPathInfo.IsPathParsed = false; ViewFieldPathInfo.MemberInfo.Clear(); ViewFieldPathInfo.Dependencies.Clear(); // if we get here we are the owner of the field and need to parse the path ViewFieldPathInfo.ValueConverter = viewTypeData.GetViewFieldValueConverter(ViewFieldPath); //Type viewFieldType = SourceView.GetType(); var viewFields = ViewFieldPath.Split('.'); object viewFieldObject = SourceView; var viewFieldBaseType = typeof(ViewFieldBase); bool isGenericViewField = viewFields.Length > 0 ? viewTypeData.IsGenericViewField(viewFields[0]) : false; // parse view field path bool parseSuccess = true; string dependencyPath = string.Empty; for (int i = 0; i < viewFields.Length; ++i) { bool isLastField = (i == viewFields.Length - 1); string viewField = viewFields[i]; // add dependency if (!isLastField) { dependencyPath += (i > 0 ? "." : "") + viewField; ViewFieldPathInfo.Dependencies.Add(dependencyPath); } if (!parseSuccess) { continue; } var viewFieldType = viewFieldObject.GetType(); var memberInfo = viewFieldType.GetFieldInfo(viewField); if (memberInfo == null) { SevereParseError = true; Utils.ErrorMessage = String.Format("Unable to parse view field path \"{0}\". Couldn't find member with the name \"{1}\".", ViewFieldPath, viewField); return(false); } ViewFieldPathInfo.MemberInfo.Add(memberInfo); ViewFieldPathInfo.ViewFieldType = memberInfo.GetFieldType(); // handle special ViewFieldBase types if (viewFieldBaseType.IsAssignableFrom(ViewFieldPathInfo.ViewFieldType)) { viewFieldObject = memberInfo.GetFieldValue(viewFieldObject); if (viewFieldObject == null) { Utils.ErrorMessage = String.Format("Unable to parse view field path \"{0}\". Field/property with the name \"{1}\" was null.", ViewFieldPath, viewField); parseSuccess = false; continue; } memberInfo = ViewFieldPathInfo.ViewFieldType.GetProperty("InternalValue"); // set internal dependency view field value ViewFieldPathInfo.MemberInfo.Add(memberInfo); ViewFieldPathInfo.ViewFieldType = memberInfo.GetFieldType(); } if (isLastField) { ViewFieldPathInfo.ViewFieldType = memberInfo.GetFieldType(); ViewFieldPathInfo.ViewFieldTypeName = ViewFieldPathInfo.ViewFieldType.Name; ViewFieldPathInfo.ValueConverter = ValueConverter ?? ViewData.GetValueConverterForType(ViewFieldTypeName); // handle special case if converter is null if (ValueConverter == null) { if (ViewFieldPathInfo.ViewFieldType.IsEnum()) { // if enum use generic enum converter ViewFieldPathInfo.ValueConverter = new EnumValueConverter(ViewFieldPathInfo.ViewFieldType); } else if (ViewFieldPathInfo.ViewFieldType.IsSubclassOf(typeof(Component))) { // if component use generic component converter ViewFieldPathInfo.ValueConverter = new ComponentValueConverter(ViewFieldPathInfo.ViewFieldType); } } } else { viewFieldObject = memberInfo.GetFieldValue(viewFieldObject); } if (viewFieldObject == null) { Utils.ErrorMessage = String.Format("Unable to parse view field path \"{0}\". Field/property with the name \"{1}\" was null.", ViewFieldPath, viewField); parseSuccess = false; continue; } } ViewFieldPathInfo.IsPathParsed = parseSuccess; if (parseSuccess && !isGenericViewField) { viewTypeData.AddViewFieldPathInfo(ViewFieldPath, ViewFieldPathInfo); } return(parseSuccess); }