public PropertyInfo SearchProperty(string name) { var propertyArray = MType.GetProperties(/*BindingFlags.DeclaredOnly*/); foreach (var property in propertyArray) { if (ReflectionUtil.IsDeclare(MType, property)) { MappingCodeAttribute propertyAttr = Attribute.GetCustomAttribute(property, typeof(MappingCodeAttribute)) as MappingCodeAttribute; if (propertyAttr == null) { if (property.Name == name) { //return property; return(ForType.GetProperty(property.Name)); } } else { if (propertyAttr.Code == name) { return(ForType.GetProperty(property.Name)); } } } } return(null); }
/// <summary> /// Reads the properties and constructor arguments from type metadata declared on this type /// </summary> protected virtual IList <IPropertyData> ReadDeclaredProperties() { IList <IPropertyData> properties = new List <IPropertyData>(); MemberInfo[] members = ForType.GetMembers(BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly); foreach (MemberInfo member in members) { IPropertyData property = null; if (member is PropertyInfo) { property = CreatePropertyHandler((PropertyInfo)member); } else if (member is FieldInfo) { property = CreateFieldHandler((FieldInfo)member); } if (property != null) { properties.Add(property); property.Alias = OwningRepository.PropertyNamingStrategy.GetName(property.Name); OwningRepository.ProcessAttributes(property, member); } } return(properties); }
public Pizza(string name, ForType usage, SizeType size) : base(name) { this.Size = size; this.For = usage; this.Additions = new List <IAdditive>(); }
public FieldInfo SearchField(string name) { var fieldArray = MType.GetFields( ); foreach (FieldInfo field in fieldArray) { if (ReflectionUtil.IsDeclare(MType, field)) { MappingCodeAttribute propertyAttr = Attribute.GetCustomAttribute(field, typeof(MappingCodeAttribute)) as MappingCodeAttribute; if (propertyAttr == null) { if (field.Name == name) { return(ForType.GetField(field.Name)); } } else { if (propertyAttr.Code == name) { return(ForType.GetField(field.Name)); } } } } return(null); }
public string GetSheet(string mapping) { var attr = ForType.GetCustomAttributes(typeof(SheetMappingAttribute), true) .FirstOrDefault(a => ((SheetMappingAttribute)a).Type == mapping) as SheetMappingAttribute; return(attr == null ? null : attr.Sheet); }
public ExFieldInfo SearchExField(string name) { if (this.ForType.IsEnum) { var fieldArray = this.ForType.GetFields(BindingFlags.Static | BindingFlags.Public); foreach (FieldInfo field in fieldArray) { ZCodeAttribute propertyAttr = Attribute.GetCustomAttribute(field, typeof(ZCodeAttribute)) as ZCodeAttribute; if (propertyAttr == null) { if (field.Name == name) { return(GclUtil.CreatExFieldInfo(ForType.GetField(field.Name), ForType)); //return ForType.GetField(field.Name); } } else { if (propertyAttr.Code == name) { return(GclUtil.CreatExFieldInfo(ForType.GetField(field.Name), ForType)); //return ForType.GetField(field.Name); } } } return(null); } else { var fieldArray = MType.GetFields(); foreach (FieldInfo field in fieldArray) { if (ReflectionUtil.IsDeclare(MType, field)) { ZCodeAttribute propertyAttr = Attribute.GetCustomAttribute(field, typeof(ZCodeAttribute)) as ZCodeAttribute; if (propertyAttr == null) { if (field.Name == name) { return(GclUtil.CreatExFieldInfo(ForType.GetField(field.Name), ForType)); //return ForType.GetField(field.Name); } } else { if (propertyAttr.Code == name) { return(GclUtil.CreatExFieldInfo(ForType.GetField(field.Name), ForType)); //return ForType.GetField(field.Name); } } } } return(null); } }
private MethodInfo searchMethodByMethod(MethodInfo method) { ParameterInfo[] paramArray = method.GetParameters(); Type[] types = new Type[paramArray.Length]; for (int i = 0; i < paramArray.Length; i++) { types[i] = paramArray[i].ParameterType; } MethodInfo rmethod = ForType.GetMethod(method.Name, types); return(rmethod); }
public ExPropertyInfo SearchExProperty(string name) { var propertyArray = MType.GetProperties(/*BindingFlags.DeclaredOnly*/); foreach (PropertyInfo property in propertyArray) { if (ReflectionUtil.IsDeclare(MType, property)) { if (isExFieldInfoByAttr(name, property)) { return(GclUtil.CreatExPropertyInfo(ForType.GetProperty(property.Name), ForType)); } /*ExFieldInfo exFieldInfo = searchExFieldInfoByAttr(name, property); * if (exFieldInfo != null) * { * return exFieldInfo; * }*/ /*ZCodeAttribute propertyAttr = Attribute.GetCustomAttribute(property, typeof(ZCodeAttribute)) as ZCodeAttribute; * if (propertyAttr == null) * { * if (property.Name == name) * { * //return ForType.GetExProperty(property.Name); * return GclUtil.CreatExPropertyInfo(ForType.GetProperty(property.Name), ForType); * } * } * else * { * if (propertyAttr.Code == name) * { * //return ForType.GetExProperty(property.Name); * return GclUtil.CreatExPropertyInfo(ForType.GetProperty(property.Name), ForType); * } * }*/ } } if (isRootMapping()) { return(null); } else { ExPropertyInfo property = ParentMapping.SearchExProperty(name); return(property); } }
/// <summary> /// Returns true if any member chosen to be serialized is /// A) A property /// B) Has only a getter or only a setter /// </summary> /// <returns></returns> private bool AnyNonUniformMembers() { foreach (var mem in Members) { var prop = ForType.GetProperty(mem.Key, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); if (prop == null) { continue; } if ((prop.CanRead && !prop.CanWrite) || (prop.CanWrite && !prop.CanRead)) { return(true); } } return(false); }
/// <summary> /// Reads the properties and constructor arguments from type metadata declared on this type /// </summary> /// <param name="Properties">properties collection</param> /// <param name="ConstructorArguments">constructor arguments</param> protected virtual IList <IPropertyData> ReadDeclaredProperties() { IList <IPropertyData> properties = new List <IPropertyData>(); MemberInfo[] members = ForType.GetMembers(BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly); foreach (MemberInfo member in members) { IPropertyData property = null; if (member is PropertyInfo) { property = CreatePropertyHandler((PropertyInfo)member); } else if (member is FieldInfo) { property = CreateFieldHandler((FieldInfo)member); } if (property != null) { properties.Add(property); } } return(properties); }
public ExPropertyInfo SearchExProperty(string name) { var propertyArray = MType.GetProperties(/*BindingFlags.DeclaredOnly*/); foreach (var property in propertyArray) { if (ReflectionUtil.IsDeclare(MType, property)) { ZCodeAttribute propertyAttr = Attribute.GetCustomAttribute(property, typeof(ZCodeAttribute)) as ZCodeAttribute; if (propertyAttr == null) { if (property.Name == name) { //return ForType.GetExProperty(property.Name); return(GclUtil.CreatExPropertyInfo(ForType.GetProperty(property.Name), ForType)); } } else { if (propertyAttr.Code == name) { //return ForType.GetExProperty(property.Name); return(GclUtil.CreatExPropertyInfo(ForType.GetProperty(property.Name), ForType)); } } } } if (isRootMapping()) { return(null); } else { ExPropertyInfo property = ParentMapping.SearchExProperty(name); return(property); } }
private For(ForType type) { _forType = type; }
public ExFieldInfo SearchExField(string name) { if (this.ForType.IsEnum) { var fieldArray = this.ForType.GetFields(BindingFlags.Static | BindingFlags.Public); foreach (FieldInfo field in fieldArray) { if (isExFieldInfoByAttr(name, field)) { return(GclUtil.CreatExFieldInfo(ForType.GetField(field.Name), ForType)); } /*ExFieldInfo exFieldInfo = searchExFieldInfoByAttr(name, field); * if (exFieldInfo != null) * { * return exFieldInfo; * }*/ /*Attribute[] attrs = Attribute.GetCustomAttributes(field, typeof(ZCodeAttribute)); * if (propertyAttr == null) * { * if (field.Name == name) * { * return GclUtil.CreatExFieldInfo(ForType.GetField(field.Name), ForType); * //return ForType.GetField(field.Name); * } * } * else * { * if (propertyAttr.Code == name) * { * return GclUtil.CreatExFieldInfo(ForType.GetField(field.Name), ForType); * //return ForType.GetField(field.Name); * } * }*/ } return(null); } else { var fieldArray = MType.GetFields(); foreach (FieldInfo field in fieldArray) { if (ReflectionUtil.IsDeclare(MType, field)) { if (isExFieldInfoByAttr(name, field)) { return(GclUtil.CreatExFieldInfo(ForType.GetField(field.Name), ForType)); } /*ExFieldInfo exFieldInfo = searchExFieldInfoByAttr(name, field); * if (exFieldInfo != null) * { * return exFieldInfo; * }*/ /* * ZCodeAttribute propertyAttr = Attribute.GetCustomAttribute(field, typeof(ZCodeAttribute)) as ZCodeAttribute; * if (propertyAttr == null) * { * if (field.Name == name) * { * return GclUtil.CreatExFieldInfo(ForType.GetField(field.Name), ForType); * } * } * else * { * if (propertyAttr.Code == name) * { * return GclUtil.CreatExFieldInfo(ForType.GetField(field.Name), ForType); * } * }*/ } } return(null); } }
private IList <IPropertyData> SortConstructorParameters(IList <IPropertyData> parameters, bool exactMatch) { StringComparison comparison = exactMatch ? StringComparison.Ordinal : StringComparison.OrdinalIgnoreCase; foreach (ConstructorInfo constructor in ForType.GetConstructors()) { ParameterInfo[] ctorParms = constructor.GetParameters(); if (ctorParms.Length != parameters.Count) { continue; } IPropertyData[] result = new IPropertyData[parameters.Count]; int matchCount = 0; foreach (IPropertyData property in parameters) { if (property.Position >= 0) { if (exactMatch && ctorParms[property.Position].ParameterType != property.PropertyType) { break; } //if (!exactMatch && !ctorParms[property.Position].ParameterType.IsAssignableFrom(property.PropertyType)) // break; if (result[property.Position] == null) { result[property.Position] = property; matchCount++; } else { // something else occupies this spot already, so there's a conflict with this constructor so try another // most likely none of them will work in this situation, but we'll let the outer method determine that break; } } else { // named argument, search the list int i; for (i = 0; i < ctorParms.Length; i++) { string parmName = ctorParms[i].Name; if (ctorParms[i].IsDefined(typeof(ConstructorParameterAttribute), false)) { parmName = ReflectionUtils.GetAttribute <ConstructorParameterAttribute>(ctorParms[i], false).Name; } if (parmName.Equals(property.ConstructorParameterName, comparison) && ((exactMatch && ctorParms[i].ParameterType == property.PropertyType) || (!exactMatch /* && ctorParms[i].ParameterType.IsAssignableFrom(property.PropertyType)*/))) { break; } } if (i < ctorParms.Length && result[i] == null) { result[i] = property; matchCount++; } else { break; } } } if (matchCount == result.Length) { // found a match, return it if (exactMatch) { return(result); } if (IsLooseMatch(constructor, result)) { return(result); } } } return(null); }
public IPizza Create(string name, ForType usage, SizeType size) { var pizza = new Pizza(name, usage, size); if (usage == ForType.Delivery) { this.Render.PrintMenu(pizza); var client = this.Render.GetClientDetails(); this.Deliver(client); } this.Render.PrintMenu(pizza); int additionCategory = this.Render.InputFromEnum <ProductTypes>("Choose category: "); while (additionCategory != 0) { int addition = 0; this.Render.PrintMenu(pizza); switch (additionCategory) { case 1: addition = this.Render.InputFromEnum <CheeseType>("Choose additions to add: ", ConsoleColor.Blue); var cheeseDecorator = CheeseDecorator.Instance; cheeseDecorator.Decorate(pizza, (CheeseType)addition, 1); break; case 2: addition = this.Render.InputFromEnum <FruitType>("Choose additions to add: ", ConsoleColor.Cyan); var fruitDecorator = FruitDecorator.Instance; fruitDecorator.Decorate(pizza, (FruitType)addition, 1); break; case 3: addition = this.Render.InputFromEnum <MeatType>("Choose additions to add: ", ConsoleColor.Yellow); var meatDecorator = MeatDecorator.Instance; meatDecorator.Decorate(pizza, (MeatType)addition, 1); break; case 4: addition = this.Render.InputFromEnum <SauceType>("Choose additions to add: ", ConsoleColor.DarkGreen); var sauceDecorator = SauceDecorator.Instance; sauceDecorator.Decorate(pizza, (SauceType)addition, 1); break; case 5: addition = this.Render.InputFromEnum <SpiceType>("Choose additions to add: ", ConsoleColor.DarkMagenta); var spiceDecorator = SpiceDecorator.Instance; spiceDecorator.Decorate(pizza, (SpiceType)addition, 1); break; case 6: addition = this.Render.InputFromEnum <VegetablesType>("Choose additions to add: ", ConsoleColor.DarkYellow); var vegetableDecorator = VegetableDecorator.Instance; vegetableDecorator.Decorate(pizza, (VegetablesType)addition, 1); break; default: throw new ArgumentException("No such category!"); } this.Render.PrintMenu(pizza); additionCategory = this.Render.InputFromEnum <ProductTypes>("Choose category: "); } this.PizzaFinished?.Invoke(null, EventArgs.Empty); this.pizzas.Add(pizza); return(pizza); }
private IList <IPropertyData> SortConstructorParameters(IList <IPropertyData> parameters, bool exactMatch) { StringComparison comparison = exactMatch ? StringComparison.Ordinal : StringComparison.OrdinalIgnoreCase; foreach (ConstructorInfo constructor in ForType.GetConstructors()) { ParameterInfo[] ctorParms = constructor.GetParameters(); if (ctorParms.Length != parameters.Count) { continue; } IPropertyData[] result = new IPropertyData[parameters.Count]; int matchCount = 0; foreach (IPropertyData property in parameters) { // named argument, search the list int i; for (i = 0; i < ctorParms.Length; i++) { string parmName = ctorParms[i].Name; if (ctorParms[i].IsDefined(typeof(ConstructorParameterAttribute), false)) { parmName = ReflectionUtils.GetAttribute <ConstructorParameterAttribute>(ctorParms[i], false).Name ?? parmName; } if (string.IsNullOrEmpty(parmName)) { parmName = ctorParms[i].Name; } if (parmName.Equals(property.ConstructorParameterName, comparison) && ((exactMatch && ctorParms[i].ParameterType == property.PropertyType) || (!exactMatch /* && ctorParms[i].ParameterType.IsAssignableFrom(property.PropertyType)*/))) { break; } } if (i < ctorParms.Length && result[i] == null) { result[i] = property; matchCount++; } else { break; } } if (matchCount == result.Length) { // found a match, return it if (exactMatch) { return(result); } if (IsLooseMatch(constructor, result)) { return(result); } } } return(null); }
public static T Retrieve <T>(JET_SESID sesid, JET_TABLEID table, JET_COLUMNID column) { return((T)ForType(typeof(T))(sesid, table, column)); }