protected static string XToKey(XFieldInfo xfield) { string key = string.Format("{0}.{1}", xfield.XDeclaringType.XFullName, xfield.XName); key = key.Replace('.', '_'); return(key); }
public static string XToString(XFieldInfo xfield, IStringLocalizer xstring) { if (xstring != null) { string key = XToKey(xfield); string value = xstring[key]; if (key != value) { return(value); } } return(XToString(xfield.XName, xstring)); }
public static string XToTitle(X x, XFieldInfo xfield, IStringLocalizer xstring) { string key = XToKey(xfield); key += "_string"; string value = xstring[key]; if (key == value) { XType _string = x.XTypeOf(typeof(_XString)); XObject[] xattrs = xfield.XGetCustomAttributes(_string, true); if (XToTitle(xattrs, out value) == false) { value = ""; } } return(value); }
protected async Task <IViewComponentResult> xfieldInfo(XFieldInfo xfield, char accessKey, int tabIndex, _XThisCache xthis) { _XInModel xmodel = new _XInModel(); xmodel.AccessKey = accessKey; xmodel.Class = _XFieldInfoModel.XToClass(xfield); xmodel.Name = xfield.XName; xmodel.TabIndex = tabIndex; xmodel.Text = _XStringModel.XToString(xfield, xstring); //xmodel.Title = _XStringModel.XToTitle(x, xfield, xstring); xmodel.XString = xstring; xmodel.XType = xfield.XFieldType; bool ximplicit = _XFieldInfoModel.XIsImplicit(xfield, x); string view = null; XBuild(xmodel, out view, xthis, ximplicit); if (view != null) { return(View(view, xmodel)); } return(View(xmodel)); }
public bool Equals(XFieldInfo other) { XFieldInfoInternal otherField = other as XFieldInfoInternal; return(field.Equals(otherField.field)); }
public string XGetValue(XFieldInfo xfield) { XObject value = xfield.XGetValue(null); return(XConverter.XConvertToString(value)); }
public bool Equals(XFieldInfo other) { throw new NotImplementedException(); }
private static List <XFieldInfo <TKind> > InitializeType(Type _type) { var list = new List <XFieldInfo <TKind> >(); m_xValueInfos.Add(_type, list); var fields = new List <FieldInfo>(); var bt = _type; do { fields.AddRange(bt.GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance)); bt = bt.BaseType; } while (bt != null); foreach (var fieldInfo in fields) { if (!fieldInfo.FieldType.IsGenericType) { continue; } var genericArgumentType = fieldInfo.FieldType.GetGenericArguments().First(); var xAttribute = fieldInfo.GetCustomAttributes(typeof(XAttribute), true).Cast <XAttribute>().SingleOrDefault(); if (xAttribute == null) { continue; } var xFieldInfo = new XFieldInfo <TKind>(xAttribute.HashCode, fieldInfo); var xFactoryAttribute = fieldInfo.GetCustomAttributes(typeof(XFactoryAttribute), true).Cast <XFactoryAttribute>().SingleOrDefault(); if (genericArgumentType.IsAbstract) { if (xFactoryAttribute == null) { throw new ApplicationException(string.Format("Not specified XFactoryAttribute for field {1}(ICollection<{2}>) in class {0}", fieldInfo.DeclaringType.Name, xFieldInfo.Field.Name, genericArgumentType.Name)); } xFieldInfo.Factory = (IXObjectFactory <TKind>)Activator.CreateInstance(xFactoryAttribute.FactoryType); } var constructor = fieldInfo.FieldType.GetConstructor(BindingFlags.NonPublic | BindingFlags.Instance, null, Type.EmptyTypes, null); if (typeof(ICollection <>).MakeGenericType(genericArgumentType).IsAssignableFrom(fieldInfo.FieldType)) { if (typeof(ClientXObject <TKind>).IsAssignableFrom(genericArgumentType)) { var tp = typeof(XCollection <,>).MakeGenericType(new[] { genericArgumentType, typeof(TKind) }); if (genericArgumentType.IsAbstract) { constructor = tp.GetConstructor(BindingFlags.NonPublic | BindingFlags.Instance, null, new[] { typeof(IXObjectFactory <TKind>) }, null); } else { constructor = tp.GetConstructor(BindingFlags.NonPublic | BindingFlags.Instance, null, Type.EmptyTypes, null); } } } else if (typeof(IXValue <>).MakeGenericType(genericArgumentType).IsAssignableFrom(fieldInfo.FieldType)) { if (typeof(ClientXObject <TKind>).IsAssignableFrom(genericArgumentType)) { var tp = typeof(XRef <,>).MakeGenericType(new[] { genericArgumentType, typeof(TKind) }); if (genericArgumentType.IsAbstract) { constructor = tp.GetConstructor(BindingFlags.NonPublic | BindingFlags.Instance, null, new[] { typeof(IXObjectFactory <TKind>) }, null); } else { constructor = tp.GetConstructor(BindingFlags.NonPublic | BindingFlags.Instance, null, Type.EmptyTypes, null); } } else { var tp = typeof(XValue <>).MakeGenericType(new[] { genericArgumentType }); constructor = tp.GetConstructor(BindingFlags.NonPublic | BindingFlags.Instance, null, Type.EmptyTypes, null); } } else { continue; } if (constructor == null) { throw new ApplicationException(string.Format("Can't get default constructor or factory {0}", xFactoryAttribute.FactoryType.Name)); } xFieldInfo.Constructor = constructor; list.Add(xFieldInfo); } return(list); }
public _XFieldInfoModel(_XTypeModel xtype, XFieldInfo field, char key, int index) { XAccessKey = key; XTabIndex = index; }
public static string XToClass(XFieldInfo xfield) { return("field-info"); }
public static bool XIsImplicit(XFieldInfo xfield, X x) { return(xfield.XGetCustomAttributes(x.XTypeOf(typeof(_XImplicit)), false).Length > 0); }
public async Task <IViewComponentResult> InvokeAsync(XType xtype, XObject xobject, XFieldInfo field, char key, int index) { if (xtype == null) { xtype = xobject.XGetType(); } return(View(new _XFieldInfoModel(null, field, key, index))); }