Пример #1
0
 protected bool Equals(PropertyStem other)
 {
     return string.Equals(PropertyName, other.PropertyName)
            && PropertyType == other.PropertyType 
            && Equals(ReadMethod, other.ReadMethod) 
            && Equals(AccessorField, other.AccessorField) 
            && Equals(AccessorProp, other.AccessorProp);
 }
Пример #2
0
        public static PropertyStem Merge(
            PropertyStem baseStem,
            PropertyStem mergeStem)
        {
            if (baseStem == null) {
                return mergeStem;
            }

            if (baseStem.DeclaringType != mergeStem.DeclaringType) {
                throw new ArgumentException("cannot merge property stems from different declaring types");
            }

            // Below are codified rules for how to merge stems when a class defines two
            // different ways to retrieve a property.  For example, the class could define
            // a property and a getter method.  In this case, which should take precedence?
            // 
            // These rules need to be captured somewhere.  Currently, there is no good answer
            // for where these rules are codified.  We will capture them here for now and move
            // them out so that these rules can be in the development space elsewhere.

            var accessorProp = baseStem.AccessorProp;
            var accessorField = baseStem.AccessorField;
            var accessorMethod = baseStem.ReadMethod;
            var stemPropType = baseStem.PropertyType | mergeStem.PropertyType;
            var stemPropName = baseStem.PropertyName;

            if (mergeStem.AccessorProp != null) {
                if (accessorProp != null)
                    throw new ArgumentException($"base stem already defines {nameof(baseStem.AccessorProp)}");
                accessorProp = mergeStem.AccessorProp;
            }

            if (mergeStem.AccessorField != null) {
                if (accessorField != null)
                    throw new ArgumentException($"base stem already defines {nameof(baseStem.AccessorField)}");
                accessorField = mergeStem.AccessorField;
            }


            if (mergeStem.ReadMethod != null) {
                if (accessorMethod != null)
                    throw new ArgumentException($"base stem already defines {nameof(baseStem.ReadMethod)}");
                accessorMethod = mergeStem.ReadMethod;
            }

            return new PropertyStem(stemPropName, accessorMethod, accessorField, accessorProp, stemPropType);
        }