public MemberRelationship this[MemberRelationship source] { get { if (source.Owner == null) { throw new ArgumentNullException("Owner"); } if (source.Member == null) { throw new ArgumentNullException("Member"); } return(GetRelationship(source)); } set { if (source.Owner == null) { throw new ArgumentNullException("Owner"); } if (source.Member == null) { throw new ArgumentNullException("Member"); } SetRelationship(source, value); } }
public MemberRelationship this[MemberRelationship source] { get { if (source.Owner == null) { throw new ArgumentNullException("Owner"); } if (source.Member == null) { throw new ArgumentNullException("Member"); } return this.GetRelationship(source); } set { if (source.Owner == null) { throw new ArgumentNullException("Owner"); } if (source.Member == null) { throw new ArgumentNullException("Member"); } this.SetRelationship(source, value); } }
private static void ThrowRelationshipNotSupported(MemberRelationship source, MemberRelationship relationship) { string?sourceName = TypeDescriptor.GetComponentName(source.Owner !) ?? source.Owner !.ToString(); string?relName = TypeDescriptor.GetComponentName(relationship.Owner !) ?? relationship.Owner !.ToString(); throw new ArgumentException(SR.Format(SR.MemberRelationshipService_RelationshipNotSupported, sourceName, source.Member.Name, relName, relationship.Member.Name)); }
protected override MemberRelationship GetRelationship(MemberRelationship source) { LoggingService.Debug("MemberRelationshipService: GetRelationship called, source=" + ToString(source)); var mrs = base.GetRelationship(source); LoggingService.Debug("MemberRelationshipService: -> returning " + ToString(mrs)); return mrs; }
/// <summary> /// Returns the current relationship associated with the source, or MemberRelationship.Empty if /// there is no relationship. Also sets a relationship between two objects. Empty /// can also be passed as the property value, in which case the relationship will /// be cleared. /// </summary> public MemberRelationship this[MemberRelationship source] { get { // The Owner and Member properties can be null if the MemberRelationship is constructed // using the default constructor. However there is no situation in which one is null // and not the other as the main constructor performs argument validation. if (source.Owner == null) { throw new ArgumentException(SR.Format(SR.InvalidNullArgument, "source.Owner"), nameof(source)); } Debug.Assert(source.Member != null); return(GetRelationship(source)); } set { // The Owner and Member properties can be null if the MemberRelationship is constructed // using the default constructor. However there is no situation in which one is null // and not the other as the main constructor performs argument validation. if (source.Owner == null) { throw new ArgumentException(SR.Format(SR.InvalidNullArgument, "source.Owner"), nameof(source)); } Debug.Assert(source.Member != null); SetRelationship(source, value); } }
public override bool SupportsRelationship(MemberRelationship source, MemberRelationship relationship) { #if WFDESIGN_LOG_MEMBERRELATIONSHIPSERVICE LoggingService.Debug("MemberRelationshipService: SupportsRelationship called, source=" + ToString(source) + ", relationship=" + ToString(relationship)); #endif return true; }
/// <summary> /// This is the implementation API for returning relationships. The default implementation stores the /// relationship in a table. Relationships are stored weakly, so they do not keep an object alive. Empty can be /// passed in for relationship to remove the relationship. /// </summary> protected virtual void SetRelationship(MemberRelationship source, MemberRelationship relationship) { if (!relationship.IsEmpty && !SupportsRelationship(source, relationship)) { ThrowRelationshipNotSupported(source, relationship); } _relationships[new RelationshipEntry(source)] = new RelationshipEntry(relationship); }
/// <summary> /// This is the implementation API for returning relationships. The default implementation stores the /// relationship in a table. Relationships are stored weakly, so they do not keep an object alive. /// </summary> protected virtual MemberRelationship GetRelationship(MemberRelationship source) { if (_relationships.TryGetValue(new RelationshipEntry(source), out RelationshipEntry retVal) && retVal._owner.IsAlive) { return(new MemberRelationship(retVal._owner.Target !, retVal._member)); } return(MemberRelationship.Empty); }
/// <summary> /// This method returns true if the given member descriptor should be serialized, /// or false if there is no need to serialize the member. /// </summary> public override bool ShouldSerialize(IDesignerSerializationManager manager, object value, MemberDescriptor descriptor) { ArgumentNullException.ThrowIfNull(manager); ArgumentNullException.ThrowIfNull(value); if (!(descriptor is PropertyDescriptor propertyToSerialize)) { throw new ArgumentNullException(nameof(descriptor)); } bool shouldSerializeProperty = propertyToSerialize.ShouldSerializeValue(value); if (!shouldSerializeProperty) { SerializeAbsoluteContext absolute = (SerializeAbsoluteContext)manager.Context[typeof(SerializeAbsoluteContext)]; if (absolute is not null && absolute.ShouldSerialize(propertyToSerialize)) { // For ReadOnly properties, we only want to override the value returned from // ShouldSerializeValue() if the property is marked with DesignerSerializationVisibilityAttribute(Content). // Consider the case of a property with just a getter - we only want to serialize those // if they're marked in this way (see ReflectPropertyDescriptor::ShouldSerializeValue()) if (!propertyToSerialize.Attributes.Contains(DesignerSerializationVisibilityAttribute.Content)) { shouldSerializeProperty = false; // it's already false at this point, but this is clearer. } else { shouldSerializeProperty = true; // Always serialize difference properties } } } if (shouldSerializeProperty) { bool isDesignTime = propertyToSerialize.Attributes.Contains(DesignOnlyAttribute.Yes); if (!isDesignTime) { return(true); } } // If we don't have to serialize, we need to make sure there isn't a member // relationship with this property. If there is, we still need to serialize. if (manager.GetService(typeof(MemberRelationshipService)) is MemberRelationshipService relationships) { MemberRelationship relationship = relationships[value, descriptor]; if (relationship != MemberRelationship.Empty) { return(true); } } return(false); }
/// <devdoc> /// This is the implementation API for returning relationships. The default implementation stores the /// relationship in a table. Relationships are stored weakly, so they do not keep an object alive. /// </devdoc> protected virtual MemberRelationship GetRelationship(MemberRelationship source) { RelationshipEntry retVal; if (_relationships != null && _relationships.TryGetValue(new RelationshipEntry(source), out retVal) && retVal.Owner.IsAlive) { return new MemberRelationship(retVal.Owner.Target, retVal.Member); } return MemberRelationship.Empty; }
protected virtual MemberRelationship GetRelationship(MemberRelationship source) { RelationshipEntry entry; if (((this._relationships != null) && this._relationships.TryGetValue(new RelationshipEntry(source), out entry)) && entry.Owner.IsAlive) { return new MemberRelationship(entry.Owner.Target, entry.Member); } return MemberRelationship.Empty; }
protected virtual MemberRelationship GetRelationship(MemberRelationship source) { RelationshipEntry entry; if (((this._relationships != null) && this._relationships.TryGetValue(new RelationshipEntry(source), out entry)) && entry.Owner.IsAlive) { return(new MemberRelationship(entry.Owner.Target, entry.Member)); } return(MemberRelationship.Empty); }
public MemberRelationship this [MemberRelationship source] { get { return(default(MemberRelationship)); } set { } }
public MemberRelationship this [MemberRelationship source] { get { return default(MemberRelationship); } set { } }
public override bool Equals(object obj) { if (!(obj is MemberRelationship)) { return(false); } MemberRelationship relationship = (MemberRelationship)obj; return((relationship.Owner == this.Owner) && (relationship.Member == this.Member)); }
private void SerializeNormalProperty(IDesignerSerializationManager manager, object value, PropertyDescriptor property, CodeStatementCollection statements) { using (CodeDomSerializerBase.TraceScope("CodeDomSerializer::SerializeProperty")) { CodeExpression targetObject = base.SerializeToExpression(manager, value); if (targetObject != null) { CodeExpression expression = new CodePropertyReferenceExpression(targetObject, property.Name); CodeExpression right = null; MemberRelationshipService service = manager.GetService(typeof(MemberRelationshipService)) as MemberRelationshipService; if (service != null) { MemberRelationship relationship = service[value, property]; if (relationship != MemberRelationship.Empty) { CodeExpression expression4 = base.SerializeToExpression(manager, relationship.Owner); if (expression4 != null) { right = new CodePropertyReferenceExpression(expression4, relationship.Member.Name); } } } if (right == null) { bool flag; object obj2 = this.GetPropertyValue(manager, property, value, out flag); if (flag) { ExpressionContext context = null; if (obj2 != value) { context = new ExpressionContext(expression, property.PropertyType, value); manager.Context.Push(context); } try { right = base.SerializeToExpression(manager, obj2); } finally { if (context != null) { manager.Context.Pop(); } } } } if (right != null) { CodeAssignStatement statement = new CodeAssignStatement(expression, right); statements.Add(statement); } } } }
private void SerializeNormalProperty(IDesignerSerializationManager manager, object instance, PropertyDescriptor descriptor, CodeStatementCollection statements) { CodeAssignStatement assignment = new CodeAssignStatement(); CodeExpression leftSide = null; CodePropertyReferenceExpression propRef = null; ExpressionContext expression = manager.Context[typeof(ExpressionContext)] as ExpressionContext; RootContext root = manager.Context[typeof(RootContext)] as RootContext; if (expression != null && expression.PresetValue == instance && expression.Expression != null) { leftSide = new CodePropertyReferenceExpression(expression.Expression, descriptor.Name); } else if (root != null && root.Value == instance) { leftSide = new CodePropertyReferenceExpression(root.Expression, descriptor.Name); } else { propRef = new CodePropertyReferenceExpression(); propRef.PropertyName = descriptor.Name; propRef.TargetObject = base.SerializeToExpression(manager, instance); leftSide = propRef; } CodeExpression rightSide = null; MemberRelationship relationship = GetRelationship(manager, instance, descriptor); if (!relationship.IsEmpty) { propRef = new CodePropertyReferenceExpression(); propRef.PropertyName = relationship.Member.Name; propRef.TargetObject = base.SerializeToExpression(manager, relationship.Owner); rightSide = propRef; } else { rightSide = base.SerializeToExpression(manager, descriptor.GetValue(instance)); } if (rightSide == null || leftSide == null) { base.ReportError(manager, "Cannot serialize " + ((IComponent)instance).Site.Name + "." + descriptor.Name, "Property Name: " + descriptor.Name + System.Environment.NewLine + "Property Type: " + descriptor.PropertyType.Name + System.Environment.NewLine); } else { assignment.Left = leftSide; assignment.Right = rightSide; statements.Add(assignment); } }
/// <summary> /// This is the implementation API for returning relationships. The default implementation stores the /// relationship in a table. Relationships are stored weakly, so they do not keep an object alive. /// </summary> protected virtual MemberRelationship GetRelationship(MemberRelationship source) { RelationshipEntry retVal; if (_relationships != null && _relationships.TryGetValue(new RelationshipEntry(source), out retVal) && retVal.Owner.IsAlive) { return(new MemberRelationship(retVal.Owner.Target, retVal.Member)); } return(MemberRelationship.Empty); }
/// <summary> /// Infrastructure support to make this a first class struct /// </summary> public override bool Equals(object obj) { if (!(obj is MemberRelationship)) { return(false); } MemberRelationship rel = (MemberRelationship)obj; return(rel.Owner == Owner && rel.Member == Member); }
protected virtual void SetRelationship(MemberRelationship source, MemberRelationship relationship) { if (source.IsEmpty) { throw new ArgumentNullException("source"); } if (!relationship.IsEmpty && !this.SupportsRelationship(source, relationship)) { throw new ArgumentException("Relationship not supported."); } _relations[new MemberRelationshipWeakEntry(source)] = new MemberRelationshipWeakEntry(relationship); }
public override bool ShouldSerialize(IDesignerSerializationManager manager, object value, MemberDescriptor descriptor) { PropertyDescriptor member = descriptor as PropertyDescriptor; if (manager == null) { throw new ArgumentNullException("manager"); } if (value == null) { throw new ArgumentNullException("value"); } if (member == null) { throw new ArgumentNullException("descriptor"); } bool flag = member.ShouldSerializeValue(value); if (!flag) { SerializeAbsoluteContext context = (SerializeAbsoluteContext)manager.Context[typeof(SerializeAbsoluteContext)]; if ((context != null) && context.ShouldSerialize(member)) { if (!member.Attributes.Contains(DesignerSerializationVisibilityAttribute.Content)) { flag = false; } else { flag = true; } } } if (flag && !member.Attributes.Contains(DesignOnlyAttribute.Yes)) { return(true); } MemberRelationshipService service = manager.GetService(typeof(MemberRelationshipService)) as MemberRelationshipService; if (service != null) { MemberRelationship relationship = service[value, descriptor]; if (relationship != MemberRelationship.Empty) { return(true); } } return(false); }
protected virtual MemberRelationship GetRelationship(MemberRelationship source) { if (source.IsEmpty) { throw new ArgumentNullException("source"); } MemberRelationshipWeakEntry entry = _relations[new MemberRelationshipWeakEntry(source)] as MemberRelationshipWeakEntry; if (entry != null) { return(new MemberRelationship(entry.Owner, entry.Member)); } return(MemberRelationship.Empty); }
/// <summary> /// This is the implementation API for returning relationships. The default implementation stores the /// relationship in a table. Relationships are stored weakly, so they do not keep an object alive. Empty can be /// passed in for relationship to remove the relationship. /// </summary> protected virtual void SetRelationship(MemberRelationship source, MemberRelationship relationship) { if (!relationship.IsEmpty && !SupportsRelationship(source, relationship)) { string sourceName = TypeDescriptor.GetComponentName(source.Owner); string relName = TypeDescriptor.GetComponentName(relationship.Owner); if (sourceName == null) { sourceName = source.Owner.ToString(); } if (relName == null) { relName = relationship.Owner.ToString(); } throw new ArgumentException(SR.Format(SR.MemberRelationshipService_RelationshipNotSupported, sourceName, source.Member.Name, relName, relationship.Member.Name)); } _relationships[new RelationshipEntry(source)] = new RelationshipEntry(relationship); }
protected virtual void SetRelationship(MemberRelationship source, MemberRelationship relationship) { if (!relationship.IsEmpty && !this.SupportsRelationship(source, relationship)) { string componentName = TypeDescriptor.GetComponentName(source.Owner); string str2 = TypeDescriptor.GetComponentName(relationship.Owner); if (componentName == null) { componentName = source.Owner.ToString(); } if (str2 == null) { str2 = relationship.Owner.ToString(); } throw new ArgumentException(SR.GetString("MemberRelationshipService_RelationshipNotSupported", new object[] { componentName, source.Member.Name, str2, relationship.Member.Name })); } if (this._relationships == null) { this._relationships = new Dictionary<RelationshipEntry, RelationshipEntry>(); } this._relationships[new RelationshipEntry(source)] = new RelationshipEntry(relationship); }
protected virtual void SetRelationship(MemberRelationship source, MemberRelationship relationship) { if (!relationship.IsEmpty && !this.SupportsRelationship(source, relationship)) { string componentName = TypeDescriptor.GetComponentName(source.Owner); string str2 = TypeDescriptor.GetComponentName(relationship.Owner); if (componentName == null) { componentName = source.Owner.ToString(); } if (str2 == null) { str2 = relationship.Owner.ToString(); } throw new ArgumentException(SR.GetString("MemberRelationshipService_RelationshipNotSupported", new object[] { componentName, source.Member.Name, str2, relationship.Member.Name })); } if (this._relationships == null) { this._relationships = new Dictionary <RelationshipEntry, RelationshipEntry>(); } this._relationships[new RelationshipEntry(source)] = new RelationshipEntry(relationship); }
public MemberRelationshipWeakEntry (MemberRelationship relation) { _ownerWeakRef = new WeakReference (relation.Owner); _member = relation.Member; }
/// <summary> /// This serializes the given property on this object. /// </summary> private void SerializeNormalProperty(IDesignerSerializationManager manager, object value, PropertyDescriptor property, CodeStatementCollection statements) { using (CodeDomSerializer.TraceScope("CodeDomSerializer::" + nameof(SerializeProperty))) { CodeExpression target = SerializeToExpression(manager, value); CodeDomSerializer.TraceWarningIf(target is null, "Unable to serialize target for property {0}", property.Name); if (target != null) { CodeExpression propertyRef = new CodePropertyReferenceExpression(target, property.Name); CodeExpression serializedPropertyValue = null; // First check for a member relationship service to see if this property // is related to another member. If it is, then we will use that // relationship to construct the property assign statement. if // it isn't, then we're serialize ourselves. if (manager.GetService(typeof(MemberRelationshipService)) is MemberRelationshipService relationships) { MemberRelationship relationship = relationships[value, property]; if (relationship != MemberRelationship.Empty) { CodeExpression rhsTarget = SerializeToExpression(manager, relationship.Owner); if (rhsTarget != null) { serializedPropertyValue = new CodePropertyReferenceExpression(rhsTarget, relationship.Member.Name); } } } if (serializedPropertyValue is null) { // Serialize the value of this property into a code expression. If we can't get one, // then we won't serialize the property. // object propValue = GetPropertyValue(manager, property, value, out bool validValue); if (validValue) { ExpressionContext tree = null; if (propValue != value) { // make sure the value isn't the object or we'll end up printing // this property instead of the value. tree = new ExpressionContext(propertyRef, property.PropertyType, value); manager.Context.Push(tree); } try { serializedPropertyValue = SerializeToExpression(manager, propValue); } finally { if (tree != null) { Debug.Assert(manager.Context.Current == tree, "Context stack corrupted."); manager.Context.Pop(); } } } } if (serializedPropertyValue != null) { CodeAssignStatement assign = new CodeAssignStatement(propertyRef, serializedPropertyValue); statements.Add(assign); } } } }
public MemberRelationship this[MemberRelationship source] { get { throw new NotImplementedException(); } set { throw new NotImplementedException(); } }
static MemberRelationship() { Empty = new MemberRelationship(); }
internal RelationshipEntry(MemberRelationship rel) { Owner = new WeakReference(rel.Owner); Member = rel.Member; hashCode = rel.Owner == null ? 0 : rel.Owner.GetHashCode(); }
/// <devdoc> /// This is the implementation API for returning relationships. The default implementation stores the /// relationship in a table. Relationships are stored weakly, so they do not keep an object alive. Empty can be /// passed in for relationship to remove the relationship. /// </devdoc> protected virtual void SetRelationship(MemberRelationship source, MemberRelationship relationship) { if (!relationship.IsEmpty && !SupportsRelationship(source, relationship)) { string sourceName = TypeDescriptor.GetComponentName(source.Owner); string relName = TypeDescriptor.GetComponentName(relationship.Owner); if (sourceName == null) { sourceName = source.Owner.ToString(); } if (relName == null) { relName = relationship.Owner.ToString(); } throw new ArgumentException(SR.GetString(SR.MemberRelationshipService_RelationshipNotSupported, sourceName, source.Member.Name, relName, relationship.Member.Name)); } if (_relationships == null) { _relationships = new Dictionary<RelationshipEntry,RelationshipEntry>(); } _relationships[new RelationshipEntry(source)] = new RelationshipEntry(relationship); }
public MemberRelationship this [MemberRelationship source] { get { return(GetRelationship(source)); } set { SetRelationship(source, value); } }
protected virtual new void SetRelationship(MemberRelationship source, MemberRelationship relationship) { }
private bool DeserializePropertyAssignStatement(IDesignerSerializationManager manager, CodeAssignStatement statement, CodePropertyReferenceExpression propertyReferenceEx, bool reportError) { object instance = this.DeserializeExpression(manager, null, propertyReferenceEx.TargetObject); if ((instance != null) && !(instance is CodeExpression)) { PropertyDescriptor member = GetPropertiesHelper(manager, instance, runTimeProperties)[propertyReferenceEx.PropertyName]; if (member != null) { object underlyingSystemType = this.DeserializeExpression(manager, null, statement.Right); if (underlyingSystemType is CodeExpression) { return false; } IConvertible convertible = underlyingSystemType as IConvertible; if ((convertible != null) && (member.PropertyType != underlyingSystemType.GetType())) { try { underlyingSystemType = convertible.ToType(member.PropertyType, null); } catch { } } Type type = underlyingSystemType as Type; if ((type != null) && (type.UnderlyingSystemType != null)) { underlyingSystemType = type.UnderlyingSystemType; } MemberRelationship empty = MemberRelationship.Empty; MemberRelationshipService service = null; if (statement.Right is CodePropertyReferenceExpression) { service = manager.GetService(typeof(MemberRelationshipService)) as MemberRelationshipService; if (service != null) { CodePropertyReferenceExpression right = (CodePropertyReferenceExpression) statement.Right; object obj4 = this.DeserializeExpression(manager, null, right.TargetObject); PropertyDescriptor descriptor2 = GetPropertiesHelper(manager, obj4, null)[right.PropertyName]; if (descriptor2 != null) { MemberRelationship source = new MemberRelationship(instance, member); MemberRelationship relationship = new MemberRelationship(obj4, descriptor2); empty = service[source]; if (service.SupportsRelationship(source, relationship)) { service[source] = relationship; } } } } else { service = manager.GetService(typeof(MemberRelationshipService)) as MemberRelationshipService; if (service != null) { empty = service[instance, member]; service[instance, member] = MemberRelationship.Empty; } } try { member.SetValue(instance, underlyingSystemType); } catch { if (service != null) { service[instance, member] = empty; } throw; } return true; } if (reportError) { Error(manager, System.Design.SR.GetString("SerializerNoSuchProperty", new object[] { instance.GetType().FullName, propertyReferenceEx.PropertyName }), "SerializerNoSuchProperty"); } } return false; }
protected virtual new MemberRelationship GetRelationship(MemberRelationship source) { return default(MemberRelationship); }
public abstract bool SupportsRelationship(MemberRelationship source, MemberRelationship relationship);
protected virtual void SetRelationship(MemberRelationship source, MemberRelationship relationship) { throw new NotImplementedException(); }
internal RelationshipEntry(MemberRelationship rel) { this.Owner = new WeakReference(rel.Owner); this.Member = rel.Member; this.hashCode = (rel.Owner == null) ? 0 : rel.Owner.GetHashCode(); }
public override bool SupportsRelationship(MemberRelationship source, MemberRelationship relationship) { return true; }
static string ToString(MemberRelationship mrs) { return "[MR: IsEmpty=" + mrs.IsEmpty + ", Owner=[" + (mrs.Owner == null ? "<null>" : mrs.Owner.ToString()) + "], Member=[" + (mrs.Member == null ? "<null>" : mrs.Member.Name) + "]]"; }
protected virtual MemberRelationship GetRelationship (MemberRelationship source) { if (source.IsEmpty) throw new ArgumentNullException ("source"); MemberRelationshipWeakEntry entry = _relations[new MemberRelationshipWeakEntry (source)] as MemberRelationshipWeakEntry; if (entry != null) return new MemberRelationship (entry.Owner, entry.Member); return MemberRelationship.Empty; }
protected virtual new MemberRelationship GetRelationship(MemberRelationship source) { return(default(MemberRelationship)); }
protected virtual void SetRelationship (MemberRelationship source, MemberRelationship relationship) { if (source.IsEmpty) throw new ArgumentNullException ("source"); if (!relationship.IsEmpty && !this.SupportsRelationship (source, relationship)) throw new ArgumentException ("Relationship not supported."); _relations[new MemberRelationshipWeakEntry (source)] = new MemberRelationshipWeakEntry (relationship); }
public MemberRelationship this [MemberRelationship source] { get { return GetRelationship (source); } set { SetRelationship (source, value); } }
public MemberRelationshipWeakEntry(MemberRelationship relation) { _ownerWeakRef = new WeakReference(relation.Owner); _member = relation.Member; }
internal RelationshipEntry(MemberRelationship rel) { Owner = new WeakReference(rel.Owner); Member = rel.Member; _hashCode = rel.Owner == null ? 0 : rel.Owner.GetHashCode(); }
protected virtual MemberRelationship GetRelationship(MemberRelationship source) { throw new NotImplementedException(); }
protected override MemberRelationship GetRelationship(MemberRelationship source) { return base.GetRelationship(source); }