Пример #1
0
 private void ProvideSpecificTraits(ProjectionProperty property, ITraitAggregator aggregator)
 {
     PropertyScope scope;
     var scopes = specificPropertyScopes;
     if (scopes != null && scopes.TryGetValue(property.Name, out scope))
         scope.ProvideTraits(aggregator);
 }
 internal PropertyInitializerInvocation(
     ProjectionProperty        property,
     Cell<IProjectionBehavior> behavior)
 {
     this.property = property;
     this.behavior = behavior;
 }
Пример #3
0
        public MemberKey(ProjectionProperty property)
        {
            if (property == null)
                throw new ArgumentNullException("property");

            MemberName    = property.Name;
            DeclaringType = property.DeclaringType.UnderlyingType;
        }
Пример #4
0
 private void ProvideGeneralTraits(ProjectionProperty property, ITraitAggregator aggregator)
 {
     var scopes = generalPropertyScopes;
     if (scopes != null)
         foreach (var scope in scopes)
             if (scope.AppliesTo(property))
                 scope.ProvideTraits(aggregator);
 }
Пример #5
0
 internal PropertySetterInvocation(
     Projection                projection,
     ProjectionProperty        property,
     Cell<IProjectionBehavior> behavior)
 {
     this.projection = projection;
     this.property   = property;
     this.behavior   = behavior;
 }
Пример #6
0
        internal bool AppliesTo(ProjectionProperty property)
        {
            var restrictions = this.restrictions;
            if (restrictions != null)
                foreach (var restriction in restrictions)
                    if (!restriction.AppliesTo(property))
                        return false;

            return true;
        }
Пример #7
0
 internal PropertyGetterInvocation(
     Projection                projection,
     ProjectionProperty        property,
     GetterOptions         options,
     Cell<IProjectionBehavior> behavior)
 {
     this.projection = projection;
     this.property   = property;
     this.options    = options;
     this.behavior   = behavior;
 }
Пример #8
0
        // TODO: 'trait' instead of 'attribute'?
        internal static Exception AttributeConflict(ProjectionProperty property, Type attributeType)
        {
            var message = string.Format
            (
                "Conflicting '{0}' attributes inherited by property {1}.{2}.  " +
                "Override the attribute, or use inheritance directives to resolve the conflict.",
                attributeType.GetPrettyName(false).RemoveSuffix(AttributeSuffix),
                property.DeclaringType.UnderlyingType.GetPrettyName(true),
                property.Name
            );

            return new ProjectionException(message);
        }
Пример #9
0
        public void ProvidePropertyTraits(
            ProjectionProperty projectionProperty,
            PropertyInfo       underlyingProperty,
            ITraitAggregator   aggregator)
        {
            if (projectionProperty == null)
                throw Error.ArgumentNull("projectionProperty");
            if (underlyingProperty == null)
                throw Error.ArgumentNull("underlyingProperty");
            if (aggregator == null)
                throw Error.ArgumentNull("aggregator");

            ProvideAttributes(underlyingProperty, aggregator);

            var scopes = this.scopes;
            if (scopes != null)
                foreach (var scope in scopes)
                    scope.ProvideTraits(projectionProperty, aggregator);
        }
Пример #10
0
 public bool AppliesTo(ProjectionProperty property)
 {
     return property.PropertyType.Kind == kind;
 }
Пример #11
0
 public bool AppliesTo(ProjectionProperty property)
 {
     return property.Name.StartsWith("Test");
 }
Пример #12
0
        private static MethodBuilder ImplementSetMethod(TypeBuilder typeBuilder,
            ProjectionProperty propertyInfo, FieldInfo propertyField)
        {
            var setMethod = typeBuilder.DefineMethod
            (
                string.Concat(SetterPrefix, propertyInfo.Name),
                MethodAttributes.Private   | MethodAttributes.NewSlot |
                MethodAttributes.Virtual   | MethodAttributes.Final   |
                MethodAttributes.HideBySig | MethodAttributes.SpecialName,
                null, // void
                new[] { propertyInfo.PropertyType.UnderlyingType }
            );

            setMethod.DefineParameter(1, ParameterAttributes.None, "value");

            var il = setMethod.GetILGenerator();
            EmitCallBaseSetter(il, BaseSetMethod, propertyField);

            typeBuilder.DefineMethodOverride(setMethod, propertyInfo.UnderlyingSetter);
            return setMethod;
        }
Пример #13
0
        private static void ImplementProjectionProperty(TypeBuilder typeBuilder,
            ProjectionProperty propertyInfo, string propertyFieldName)
        {
            var propertyField = typeBuilder.DefineField
            (
                propertyFieldName,
                typeof(ProjectionProperty),
                FieldAttributes.Public | FieldAttributes.Static
            );

            var property = typeBuilder.DefineProperty
            (
                propertyInfo.Name,
                PropertyAttributes.None,
                CallingConventions.HasThis,
                propertyInfo.PropertyType,
                null // parameterTypes
            );

            if (propertyInfo.CanRead)
            {
                var getMethod = ImplementGetMethod(typeBuilder, propertyInfo, propertyField);
                property.SetGetMethod(getMethod);
            }

            if (propertyInfo.CanWrite)
            {
                var setMethod = ImplementSetMethod(typeBuilder, propertyInfo, propertyField);
                property.SetSetMethod(setMethod);
            }
        }
Пример #14
0
        private static MethodBuilder ImplementGetMethod(TypeBuilder typeBuilder,
            ProjectionProperty propertyInfo, FieldInfo propertyField)
        {
            var getMethod = typeBuilder.DefineMethod
            (
                string.Concat(GetterPrefix, propertyInfo.Name),
                MethodAttributes.Private   | MethodAttributes.NewSlot |
                MethodAttributes.Virtual   | MethodAttributes.Final   |
                MethodAttributes.HideBySig | MethodAttributes.SpecialName,
                propertyInfo.PropertyType,
                Type.EmptyTypes
            );

            var il = getMethod.GetILGenerator();
            EmitCallBaseGetter      (il, BaseGetMethod, propertyField);
            EmitReturnTypedOrDefault(il, propertyInfo.PropertyType.UnderlyingType);

            typeBuilder.DefineMethodOverride(getMethod, propertyInfo.UnderlyingGetter);
            return getMethod;
        }
Пример #15
0
 private static string GetPropertyFieldName(ProjectionProperty property, int index)
 {
     // TODO: Use a name that is illegal in most .NET languages
     return string.Concat
     (
         "_p", index.ToString(),
         "_",  property.Name
     );
 }
Пример #16
0
        // TODO: 'trait' instead of 'attribute'?
        internal static Exception InvalidOverride(string name, Type declaringType, ProjectionProperty newProperty)
        {
            var message = string.Format
            (
                "Invalid 'Override' attribute on property {0}.{1}.  " +
                "The specified base property was not found: {2}.{3}.",
                newProperty.DeclaringType.UnderlyingType.GetPrettyName(true),
                newProperty.Name,
                declaringType.GetPrettyName(true),
                name
            );

            return new ProjectionException(message);
        }
Пример #17
0
 public bool AppliesTo(ProjectionProperty property)
 {
     return property.Name.Equals(name, comparison);
 }
Пример #18
0
 public bool AppliesTo(ProjectionProperty property)
 {
     return regex.IsMatch(property.Name);
 }
Пример #19
0
 internal void ProvideTraits(ProjectionProperty property, ITraitAggregator aggregator)
 {
     ProvideGeneralTraits (property, aggregator);
     ProvideSpecificTraits(property, aggregator);
 }
Пример #20
0
 public bool AppliesTo(ProjectionProperty property)
 {
     return HasKind(property.PropertyType.Kind);
 }
Пример #21
0
 public bool AppliesTo(ProjectionProperty property)
 {
     return AppliesTo(property.Name);
 }