public FieldValueReference( EvaluationContext ctx, FieldInfo field, object obj, Type declaringType, string vname, ObjectValueFlags vflags, FieldReferenceBatch batch = null) : base(ctx) { this.field = field; this.obj = obj; this.declaringType = declaringType; this.vname = vname; this.batch = batch; if (field.IsStatic) { this.obj = null; } flags = GetFlags(field); // if `vflags` already has an origin specified, we need to unset the `Field` flag which is always returned by GetFlags(). if ((vflags & ObjectValueFlags.OriginMask) != 0) { flags &= ~ObjectValueFlags.Field; } flags |= vflags; if (obj?.GetType()?.IsPrimitive == true) { flags |= ObjectValueFlags.ReadOnly; } }
public FieldValueReference(EvaluationContext ctx, FieldInfoMirror field, object obj, TypeMirror declaringType, string vname, ObjectValueFlags vflags, FieldReferenceBatch batch = null) : base(ctx) { this.field = field; this.obj = obj; this.declaringType = declaringType; this.vname = vname; this.batch = batch; flags = vflags; if (field.IsStatic) { this.obj = null; } var objectMirror = obj as ObjectMirror; if (objectMirror != null) { EnsureContextHasDomain(objectMirror.Domain); } flags |= GetFlags(field); if (obj is PrimitiveValue) { flags |= ObjectValueFlags.ReadOnly; } }
public FieldValueReference( EvaluationContext ctx, FieldInfo field, object obj, Type declaringType, FieldReferenceBatch batch = null) : this(ctx, field, obj, declaringType, null, ObjectValueFlags.Field, batch) { }
public FieldValueReference (EvaluationContext ctx, FieldInfoMirror field, object obj, TypeMirror declaringType, string vname, ObjectValueFlags vflags, FieldReferenceBatch batch = null): base (ctx) { this.field = field; this.obj = obj; this.declaringType = declaringType; this.vname = vname; this.batch = batch; flags = vflags; if (field.IsStatic) this.obj = null; var objectMirror = obj as ObjectMirror; if (objectMirror != null) EnsureContextHasDomain (objectMirror.Domain); flags |= GetFlags (field); if (obj is PrimitiveValue) flags |= ObjectValueFlags.ReadOnly; }
public IEnumerable <ValueReference> GetMembers( EvaluationContext ctx, IObjectSource objectSource, object t, object value, BindingFlags bindingFlags) { var subProps = new Dictionary <string, PropertyInfo> (); var type = t as Type; Type realType = null; if (value != null && (bindingFlags & BindingFlags.Instance) != 0) { realType = GetValueType(value) as Type; } // First of all, get a list of properties overridden in sub-types while (realType != null && realType != type) { foreach (PropertyInfo property in realType.GetProperties(bindingFlags | BindingFlags.DeclaredOnly)) { MethodInfo method = property.GetGetMethod(true); if (method == null || method.GetParameters().Length != 0 || method.IsAbstract || !method.IsVirtual || method.IsStatic) { continue; } if (method.IsPublic && ((bindingFlags & BindingFlags.Public) == 0)) { continue; } if (!method.IsPublic && ((bindingFlags & BindingFlags.NonPublic) == 0)) { continue; } subProps[property.Name] = property; } realType = realType.BaseType; } var tupleNames = GetTupleElementNames(objectSource, ctx); bool hasExplicitInterface = false; while (type != null) { var fieldsBatch = new FieldReferenceBatch(value); foreach (var field in type.GetFields(bindingFlags)) { if (field.IsStatic) { yield return(new FieldValueReference(ctx, field, value, type)); } else { fieldsBatch.Add(field); string vname = MapTupleName(field.Name, tupleNames); yield return(new FieldValueReference(ctx, field, value, type, vname, ObjectValueFlags.Field, fieldsBatch)); } } foreach (var prop in type.GetProperties(bindingFlags)) { var getter = prop.GetGetMethod(true); if (getter == null || getter.GetParameters().Length != 0 || getter.IsAbstract) { continue; } if (getter.IsStatic && ((bindingFlags & BindingFlags.Static) == 0)) { continue; } if (!getter.IsStatic && ((bindingFlags & BindingFlags.Instance) == 0)) { continue; } if (getter.IsPublic && ((bindingFlags & BindingFlags.Public) == 0)) { continue; } //This is only possible in case of explicitly implemented interface property, which we handle later if (getter.IsVirtual && getter.IsPrivate) { hasExplicitInterface = true; continue; } if (!getter.IsPublic && ((bindingFlags & BindingFlags.NonPublic) == 0)) { continue; } // If a property is overriden, return the override instead of the base property PropertyInfo overridden; if (getter.IsVirtual && subProps.TryGetValue(prop.Name, out overridden)) { getter = overridden.GetGetMethod(true); if (getter == null) { continue; } yield return(new PropertyValueReference(ctx, overridden, value, overridden.DeclaringType, getter, null)); } else { yield return(new PropertyValueReference(ctx, prop, value, type, getter, null)); } } if ((bindingFlags & BindingFlags.DeclaredOnly) != 0) { break; } type = type.BaseType; } type = t as Type; if (type == null || !hasExplicitInterface || (bindingFlags & BindingFlags.Instance) == 0 || (bindingFlags & BindingFlags.Public) == 0) { yield break; } var interfaces = type.GetInterfaces(); foreach (Type intr in interfaces) { var map = type.GetInterfaceMap(intr); foreach (PropertyInfo prop in intr.GetProperties(bindingFlags)) { var getter = prop.GetGetMethod(true); if (getter == null || getter.GetParameters().Length != 0) { continue; } var implementationGetter = map.TargetMethods[Array.IndexOf(map.InterfaceMethods, getter)]; //We are only intersted into private(explicit) implementations because public ones are already handled before if (implementationGetter.IsPublic) { continue; } yield return(new PropertyValueReference(ctx, prop, value, type, getter, null)); } } }
public FieldValueReference(EvaluationContext ctx, FieldInfoMirror field, object obj, TypeMirror declaringType, FieldReferenceBatch batch = null) : this(ctx, field, obj, declaringType, null, ObjectValueFlags.Field, batch) { }