public void Add(PropertyData propertyData) {
            if (this.propertyData != null) {
                throw new AuditException("Only one property can be added!");
            }

            this.propertyData = propertyData;
        }
Ejemplo n.º 2
0
 public void Add(PropertyData propertyData)
 {
     var single = new SinglePropertyMapper();
     single.Add(propertyData);
     Properties.Add(propertyData, single);
     PropertyDatas.Add(propertyData.Name, propertyData);
 }
 public OneToOneNotOwningMapper(String owningReferencePropertyName, String owningEntityName,
     PropertyData propertyData)
 {
     this.owningReferencePropertyName = owningReferencePropertyName;
     this.owningEntityName = owningEntityName;
     this.propertyData = propertyData;
 }
 public PropertyWeaver(MsCoreReferenceFinder msCoreReferenceFinder, Logger logger, PropertyData propertyData, TypeNode typeNode)
 {
     this.msCoreReferenceFinder = msCoreReferenceFinder;
     this.logger = logger;
     this.propertyData = propertyData;
     this.typeNode = typeNode;
 }
Ejemplo n.º 5
0
 public ToOneIdMapper(IIdMapper delegat, PropertyData propertyData, String referencedEntityName, bool nonInsertableFake)
 {
     this.delegat = delegat;
     this.propertyData = propertyData;
     this.referencedEntityName = referencedEntityName;
     this.nonInsertableFake = nonInsertableFake;
 }
Ejemplo n.º 6
0
    public string CheckForWarning(PropertyData propertyData, InvokerTypes invokerType)
    {
        var propertyDefinition = propertyData.PropertyDefinition;
        var setMethod = propertyDefinition.SetMethod;

        if (setMethod.Name == "set_Item" && setMethod.Parameters.Count == 2 && setMethod.Parameters[1].Name == "value")
        {
            return "Property is an indexer.";
        }
        if (setMethod.Parameters.Count > 1)
        {
            return "Property takes more than one parameter.";
        }
        if (setMethod.IsAbstract)
        {
            return "Property is abstract.";
        }
        if ((propertyData.BackingFieldReference == null) && (propertyDefinition.GetMethod == null))
        {
            return "Property has no field set logic or it contains multiple sets and the names cannot be mapped to a property.";
        }
        if (invokerType == InvokerTypes.BeforeAfter && (propertyDefinition.GetMethod == null))
        {
            return "When using a before/after invoker the property have a 'get'.";
        }
        return null;
    }
Ejemplo n.º 7
0
 public void Should_Return_False_For_PropertyInfo_Objects_With_Different_Names()
 {
     var type = new { Prop1 = 10, Prop2 = 20 }.GetType();
       var propData1 = new PropertyData(type.GetProperties()[0]);
       var propData2 = new PropertyData(type.GetProperties()[1]);
       Assert.IsFalse(propData1.Equals(propData2));
 }
Ejemplo n.º 8
0
        public void ToCode_given_CommentAndNameAndType_should_ReturnCode()
        {
            //	#	Arrange.
            var sut = new PropertyData
            {
                Comment = new CommentData("MyComment"),
                Scope = Common.VisibilityScope.Private,
                Name = "CustomerID",
                SystemType = typeof(int)
            };

            //	#	Act.
            var res = sut.ToCode();

            //	#	Assert.
            Assert.AreEqual(3, res.Count);
            CollectionAssert.AreEqual(
                new[]
                {
                    "/// <summary> MyComment",
                    "/// </summary>",
                    "private System.Int32 CustomerID{ get; set; }"
                },
                res.ToList());
        }
Ejemplo n.º 9
0
 public PropertyWeaver(ModuleWeaver moduleWeaver, PropertyData propertyData, TypeNode typeNode, TypeSystem typeSystem )
 {
     this.moduleWeaver = moduleWeaver;
     this.propertyData = propertyData;
     this.typeNode = typeNode;
     this.typeSystem = typeSystem;
 }
 public CommonCollectionMapperData(AuditEntitiesConfiguration verEntCfg, String versionsMiddleEntityName,
                                   PropertyData collectionReferencingPropertyData, MiddleIdData referencingIdData,
                                   IRelationQueryGenerator queryGenerator) {
     this._verEntCfg = verEntCfg;
     this._versionsMiddleEntityName = versionsMiddleEntityName;
     this._collectionReferencingPropertyData = collectionReferencingPropertyData;
     this._referencingIdData = referencingIdData;
     this._queryGenerator = queryGenerator;
 }
Ejemplo n.º 11
0
        /// <summary>
        /// Initializes a new instance of the <see cref="PropertyValue"/> class.
        /// </summary>
        /// <param name="propertyData">The property data.</param>
        /// <param name="name">The name of the property.</param>
        /// <param name="value">The value of the property.</param>
        /// <exception cref="ArgumentNullException">The <paramref name="propertyData"/> is <c>null</c>.</exception>
        /// <exception cref="ArgumentException">The <paramref name="name"/> is <c>null</c> or whitespace.</exception>
        public PropertyValue(PropertyData propertyData, string name, object value)
        {
            Argument.IsNotNull("propertyData", propertyData);
            Argument.IsNotNullOrWhitespace("name", name);

            PropertyData = propertyData;
            Name = name;
            Value = value;
        }
        public ICompositeMapperBuilder AddComponent(PropertyData propertyData, String componentClassName) {
            if (Properties[propertyData] != null) {
			    // This is needed for second pass to work properly in the components mapper
                return (ICompositeMapperBuilder) Properties[propertyData];
            }

            ComponentPropertyMapper componentMapperBuilder = new ComponentPropertyMapper(propertyData, componentClassName);
		    AddComposite(propertyData, componentMapperBuilder);

            return componentMapperBuilder;
        }
Ejemplo n.º 13
0
        public string Map(PageData pageData, PropertyData propertyData)
        {
            var propertyDate = propertyData as PropertyDate;
            if (propertyDate != null)
            {
                var d = propertyDate.Date;
                return d != default(DateTime) ? UnixTicks(d).ToString(CultureInfo.InvariantCulture) : (-1).ToString(CultureInfo.InvariantCulture);
            }

            return String.Empty;
        }
 protected override void HandleSetterAccessor(IInvocation invocation, PropertyData propertyData)
 {
     IPropertyDataInterceptor propertyInterceptor = _contentDataInterceptorHandler.GetPropertyInterceptor(propertyData.GetType());
     if (propertyInterceptor != null)
     {
         Type parameterType = invocation.Method.GetParameters()[0].ParameterType;
         propertyInterceptor.SetValue(propertyData, parameterType, invocation.Arguments[0]);
     }
     else
     {
         propertyData.Value = invocation.Arguments[0];
     }
 }
Ejemplo n.º 15
0
    public void IsIndexer()
    {
        var checker = new ModuleWeaver();
        var propertyDefinition = DefinitionFinder.FindType<IndexerClass>()
            .Properties
            .First();

        var propertyData = new PropertyData
        {
            PropertyDefinition = propertyDefinition,
        };
        var message = checker.CheckForWarning(propertyData, InvokerTypes.String);
        Approvals.Verify(message);
    }
 protected override void HandleGetterAccessor(IInvocation invocation, PropertyData propertyData)
 {
     IPropertyDataInterceptor propertyInterceptor = _contentDataInterceptorHandler.GetPropertyInterceptor(propertyData.GetType());
     if (propertyInterceptor != null)
     {
         invocation.ReturnValue = propertyInterceptor.GetValue(propertyData, invocation.Method.ReturnType);
     }
     else if ((propertyData.Value == null) && invocation.Method.ReturnType.IsValueType)
     {
         invocation.ReturnValue = Activator.CreateInstance(invocation.Method.ReturnType);
     }
     else
     {
         invocation.ReturnValue = propertyData.Value;
     }
 }
Ejemplo n.º 17
0
        public void ToCode_given_NameAndType_should_ReturnCode()
        {
            //	#	Arrange.
            var sut = new PropertyData
            {
                Scope = Common.VisibilityScope.Public,
                Name = "MyName",
                SystemType = typeof(string)
            };

            //	#	Act.
            var res = sut.ToCode();

            //	#	Assert.
            Assert.AreEqual(1, res.Count);
            Assert.AreEqual(
                @"public System.String MyName{ get; set; }",
                res[0]);
        }
Ejemplo n.º 18
0
        private void AddControl(string propertyName, PropertyData propertyValue, Guid propertyTypeId, string headerText, string parameters) {
            var propertyType = Core.PropertyType.GetPropertyType(propertyTypeId);
            var editControl = propertyType.EditControl;

            var loadControl = (PropertyEditorBase)LoadControl(editControl);
            loadControl.PropertyName = propertyName;
            loadControl.PropertyLabel = headerText;
            
            if (propertyValue != null) {
                loadControl.PropertyValue = propertyValue;
            }

            if (!string.IsNullOrEmpty(parameters)) {
                loadControl.Parameters = parameters;
            }

            EditControls.Controls.Add(loadControl);
            _controls.Add(loadControl);
        }
Ejemplo n.º 19
0
    public string CheckForErrors(PropertyData propertyData, bool isBeforeAfter)
    {
        var propertyDefinition = propertyData.PropertyDefinition;
        if (propertyDefinition.SetMethod.Name == "set_Item" && propertyDefinition.SetMethod.Parameters.Count == 2 && propertyDefinition.SetMethod.Parameters[1].Name == "value")
        {
            return "Property is an indexer.";
        }
        if (propertyDefinition.SetMethod.IsAbstract)
        {
            return "Property is abstract.";
        }
        if (propertyData.CheckForEquality && (propertyData.BackingFieldReference == null) && (propertyDefinition.GetMethod == null))
        {
            return "When using CheckForEquality the property set must contain code that sets the backing field or have a property Get. Either the property contains no field set or it contains multiple sets and the names cannot be mapped to a property.";
        }
        if (isBeforeAfter && (propertyDefinition.GetMethod == null))
        {
            return "When using a before/after invoker the property have a 'get'.";
        }

        return null;
    }
Ejemplo n.º 20
0
        public string Map(PageData pageData, PropertyData propertyData)
        {
            //http://tedgustaf.com/en/blog/2009/9/parse-an-episerver-xhtml-property-with-dynamic-content/

            // Create a Property control which will parse the XHTML value for us
            var ctrl = new PropertyLongStringControl { PropertyData = propertyData };

            // Set the PropertyData to the property we want to parse
            // Initialize the Property control
            ctrl.SetupControl();

            // Create a string writer...
            var sw = new StringWriter();

            // ...and an HtmlTextWriter using that string writer
            var htw = new HtmlTextWriter(sw);

            // Render the Property control to get the markup
            ctrl.RenderControl(htw);

            return string.Format("\"{0}\"", Utils.EscapeStringForJs(sw.ToString()));
        }
Ejemplo n.º 21
0
        /// <summary>
        /// Extract the properties for a type.
        /// </summary>
        /// <param name="context"></param>
        /// <param name="typeInfo"></param>
        /// <param name="type"></param>
        public void ExtractProperties(IExtractorCollector context, TypeData typeInfo, Type type)
        {
            //this should only get properties either directly on the type or ovverriden on the type. Properties of base classes should not be added
            PropertyInfo[] properties = type.GetProperties( BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Static);
            foreach (PropertyInfo property in properties) {
                PropertyData propertyData = new PropertyData() {
                    Name = property.Name,
                    TypeName = property.PropertyType.AssemblyQualifiedName,
                };

                AccessType getAccessType = AccessType.None;
                AccessType setAccessType = AccessType.Private;
                MethodInfo getMethod = property.GetGetMethod(true);
                MethodInfo setMethod = property.GetSetMethod(true);
                MethodInfo anyAccessor = getMethod ?? setMethod;

                if (getMethod != null) {
                    if (getMethod.IsFamily)
                        getAccessType = AccessType.Protected;
                    else if (getMethod.IsPublic)
                        getAccessType = AccessType.Public;
                    else
                        getAccessType = AccessType.Private;
                }
                if (setMethod != null) {
                    if (setMethod.IsFamily)
                        setAccessType = AccessType.Protected;
                    else if (setMethod.IsPublic)
                        setAccessType = AccessType.Public;
                }

                propertyData.GetAccessType = getAccessType;
                propertyData.SetAccessType = setAccessType;
                propertyData.IsStatic = anyAccessor.IsStatic;
                propertyData.IsVirtual = anyAccessor.IsVirtual;
                propertyData.IsAbstract = anyAccessor.IsAbstract;
                context.AddProperty(typeInfo, propertyData);
            }
        }
Ejemplo n.º 22
0
        public ICompositeMapperBuilder AddComponent(PropertyData propertyData, string componentClassName)
        {
            if (Properties.ContainsKey(propertyData))
            {
                // This is needed for second pass to work properly in the components mapper
                return (ICompositeMapperBuilder) Properties[propertyData];
            }

            ICompositeMapperBuilder componentMapperBuilder;
            //todo: rk - not really reliable I think!
            if(componentClassName==null)
            {
                componentMapperBuilder = new DynamicComponentPropertyMapper(propertyData);
            }
            else
            {
                componentMapperBuilder = new ComponentPropertyMapper(propertyData, componentClassName);
            }

            AddComposite(propertyData, (IPropertyMapper) componentMapperBuilder);

            return componentMapperBuilder;
        }
Ejemplo n.º 23
0
        /// <summary>
        /// Validates the property using data annotations.
        /// </summary>
        /// <param name="propertyName">Name of the property.</param>
        /// <param name="value">The value to validate.</param>
        /// <param name="catelPropertyData">The catel property data. Can be <c>null</c> for non-Catel properties.</param>
        /// <returns><c>true</c> if no errors using data annotations are found; otherwise <c>false</c>.</returns>
        private bool ValidatePropertyUsingAnnotations(string propertyName, object value, PropertyData catelPropertyData)
        {
            if (SuspendValidation)
            {
                _propertiesNotCheckedDuringDisabledValidation.Add(propertyName);
                return true;
            }

#if !WINDOWS_PHONE && !NETFX_CORE && !PCL && !NET35
            var type = GetType();

            try
            {
                if (!_propertyValuesIgnoredOrFailedForValidation[type].Contains(propertyName))
                {
                    if (catelPropertyData != null)
                    {
                        var propertyInfo = catelPropertyData.GetPropertyInfo(type);
                        if (propertyInfo == null || !propertyInfo.HasPublicGetter)
                        {
                            _propertyValuesIgnoredOrFailedForValidation[type].Add(propertyName);
                            return false;
                        }
                    }
                    else
                    {
#if NET
                        if (type.GetPropertyEx(propertyName) == null)
                        {
                            Log.Debug("Property '{0}' cannot be found via reflection, ignoring this property for type '{1}'", propertyName, type.FullName);

                            _propertyValuesIgnoredOrFailedForValidation[type].Add(propertyName);
                            return false;
                        }
#else
                        // Checking via reflection is faster than catching the exception
                        if (!Reflection.PropertyHelper.IsPublicProperty(this, propertyName))
                        {
                            Log.Debug("Property '{0}' is not a public property, cannot validate non-public properties in silverlight", propertyName);

                            _propertyValuesIgnoredOrFailedForValidation[type].Add(propertyName);
                            return false;
                        }
#endif
                    }

                    if (!_dataAnnotationsValidationContext.ContainsKey(propertyName))
                    {
                        _dataAnnotationsValidationContext[propertyName] = new System.ComponentModel.DataAnnotations.ValidationContext(this, null, null) { MemberName = propertyName };
                    }

                    System.ComponentModel.DataAnnotations.Validator.ValidateProperty(value, _dataAnnotationsValidationContext[propertyName]);

                    // If succeeded, clear any previous error
                    if (_dataAnnotationValidationResults.ContainsKey(propertyName))
                    {
                        _dataAnnotationValidationResults[propertyName] = null;
                    }
                }
            }
            catch (System.ComponentModel.DataAnnotations.ValidationException validationException)
            {
                _dataAnnotationValidationResults[propertyName] = validationException.Message;
                return false;
            }
            catch (Exception ex)
            {
                _propertyValuesIgnoredOrFailedForValidation[type].Add(propertyName);

                Log.Warning(ex, "Failed to validate property '{0}' via Validator (property does not exists?)", propertyName);
            }
#endif

            return true;
        }
Ejemplo n.º 24
0
        /// <summary>
        /// Saves the properties data.
        /// </summary>
        /// <param name="classType">Type of the class.</param>
        /// <param name="items">The items.</param>
        /// <param name="languageId">The language id.</param>
        /// <returns></returns>
        public static object SavePropertiesData(Type classType, PropertyData[] items, int languageId)
        {
            PropertyInfo[] propertyInfoArray = classType.GetProperties(
                BindingFlags.Static | BindingFlags.Instance | BindingFlags.Public);

            object obj = null;
            if (classType.IsClass)
            {
                if (languageId == NO_LANGUAGE)
                    obj = Activator.CreateInstance(classType);
                else
                {
                    try
                    {
                        obj = Activator.CreateInstance(classType, new object[] {languageId});
                    }
                    catch (MissingMethodException)
                    {
                        obj = Activator.CreateInstance(classType);
                    }
                }
            }

            foreach (PropertyInfo propertyInfo in propertyInfoArray)
            {
                if (propertyInfo.CanRead && propertyInfo.CanWrite)
                {
                    string propertyDesc = GetDescriptionAttribute(propertyInfo);
                    if (propertyDesc == null)
                        continue;

                    string id = classType.FullName + propertyInfo.Name;

                    foreach (PropertyData item in items)
                    {
                        if (id == item.ID)
                        {
                            propertyInfo.SetValue(obj, item.Value, null);
                            break;
                        }
                    }
                }
            }

            Type[] nestedTypes = classType.GetNestedTypes(
                BindingFlags.Public | BindingFlags.Instance);

            foreach (Type nestedType in nestedTypes)
            {
                SavePropertiesData(nestedType, items, languageId);
            }

            return obj;
        }
Ejemplo n.º 25
0
        private static PropertyData[] GetPropertiesData(Type classType, object objectInstance, int languageId)
        {
            List<PropertyData> lSettingsItems = new List<PropertyData>();

            PropertyInfo[] propertyInfoArray = classType.GetProperties(
                BindingFlags.Static | BindingFlags.Instance | BindingFlags.Public);

            if (!classType.IsAbstract)
            {
                object obj = null;
                if (objectInstance == null)
                {
                    if (classType.IsClass)
                    {
                        if (languageId == NO_LANGUAGE)
                            obj = Activator.CreateInstance(classType);
                        else
                        {
                            try
                            {
                                obj = Activator.CreateInstance(classType, new object[] { languageId });
                            }
                            catch (MissingMethodException)
                            {
                                obj = Activator.CreateInstance(classType);
                            }
                        }
                    }
                }
                else obj = objectInstance;

                foreach (PropertyInfo propertyInfo in propertyInfoArray)
                {
                    string propertyDesc = GetDescriptionAttribute(propertyInfo);
                    if (propertyDesc == null)
                        continue;

                    string propertyHint = GetHintAttribute(propertyInfo);

                    string classDesc = GetDescriptionAttribute(classType);
                    if (classDesc == null)
                        throw new NoAttributeFoundException(
                            "The parent class should also have description attribute!");

                    Hashtable propertiesToApply = GetPropertiesToApply(propertyInfo);

                    Type controlType;
                    string controlProperty;

                    GetControlInfo(propertyInfo, out controlType, out controlProperty);

                    PropertyData item = new PropertyData();
                    item.ClassDesc = classDesc;
                    item.PropertyName = propertyInfo.Name;
                    item.PropertyDesc = propertyDesc;
                    item.PropertyHint = propertyHint;
                    item.Value = propertyInfo.GetValue(obj, null);
                    item.ID = classType.FullName + propertyInfo.Name;
                    item.ControlType = controlType;
                    item.ControlProperty = controlProperty;
                    item.PropertiesToApply = propertiesToApply;
                    lSettingsItems.Add(item);
                }

                Type[] nestedTypes = classType.GetNestedTypes(
                    BindingFlags.Public | BindingFlags.Instance);

                foreach (Type nestedType in nestedTypes)
                {
                    lSettingsItems.AddRange(GetPropertiesData(nestedType, languageId));
                }
            }
            return lSettingsItems.ToArray();
        }
Ejemplo n.º 26
0
 public string Map(PageData pageData, PropertyData propertyData)
 {
     return string.Format("\"{0}\"", propertyData);
 }
Ejemplo n.º 27
0
        private void HandleGradientDropOnGradientLevelPairList(PropertyData property, Element element, Dictionary<Element, Tuple<object, PropertyDescriptor>> elementValues, ColorGradient gradient)
        {
            List<GradientLevelPair> gradients = property.Descriptor.GetValue(element.EffectNode.Effect) as List<GradientLevelPair>;
            if (gradients == null) return;

            var parameterPickerControls = CreateGradientLevelPairPickerControls(property, gradients);

            var parameterPicker = CreateParameterPicker(parameterPickerControls);

            ShowMultiDropMessage();
            var dr = parameterPicker.ShowDialog();
            if (dr == DialogResult.OK)
            {
                var newGradients = gradients.ToList();
                newGradients[parameterPicker.SelectedControl.Index] = new GradientLevelPair(gradient, gradients[parameterPicker.SelectedControl.Index].Curve);
                elementValues.Add(element, new Tuple<object, PropertyDescriptor>(parameterPicker.PropertyInfo.GetValue(element.EffectNode.Effect), parameterPicker.PropertyInfo));
                UpdateEffectProperty(parameterPicker.PropertyInfo, element, newGradients);
            }
        }
Ejemplo n.º 28
0
        /// <summary>
        /// Registers a property for a specific type.
        /// </summary>
        /// <param name="name">The name of the property.</param>
        /// <param name="propertyData">The property data.</param>
        /// <exception cref="ArgumentException">The <paramref name="name"/> is <c>null</c> or whitespace.</exception>
        /// <exception cref="ArgumentNullException">The <paramref name="propertyData"/> is <c>null</c>.</exception>
        /// <exception cref="PropertyAlreadyRegisteredException">A property with the same name is already registered.</exception>
        public void RegisterProperty(string name, PropertyData propertyData)
        {
            Argument.IsNotNullOrWhitespace("name", name);
            Argument.IsNotNull("propertyData", propertyData);

            lock (_lockObject)
            {
                if (_catelProperties.ContainsKey(name))
                {
                    throw new PropertyAlreadyRegisteredException(name, Type);
                }

                _catelProperties.Add(name, propertyData);
            }
        }
        private string Render(string templateCode, string templateFile)
        {
            DTE vs = this.GetService<DTE>(true);
              string basePath = this.GetBasePath();
              Microsoft.VisualStudio.TextTemplating.ITextTemplatingEngine engine = new Microsoft.VisualStudio.TextTemplating.Engine();
              IValueInfoService service = (IValueInfoService)this.GetService(typeof(IValueInfoService));
              Dictionary<string, PropertyData> arguments = new Dictionary<string, PropertyData>();
              foreach (string str2 in base.additionalArguments.Keys)
              {
            Type type = null;
            try
            {
              type = service.GetInfo(str2).Type;
            }
            catch (ArgumentException)
            {
              if (base.additionalArguments[str2] != null)
              {
                type = base.additionalArguments[str2].GetType();
              }
              else
              {
                continue;
              }
            }
            PropertyData data = new PropertyData(base.additionalArguments[str2], type);
            arguments.Add(str2, data);
              }
              TemplateHost host = new TemplateHost(basePath, arguments);
              host.TemplateFile = templateFile;
              Helpers.LogMessage(vs, this, templateFile);

              string str3 = engine.ProcessTemplate(templateCode, host);
              if (host.Errors.HasErrors)
              {
            string errors = "";
            foreach (CompilerError error in host.Errors)
            {
              Helpers.LogMessage(vs, this, error.ErrorText);
              errors += error.ErrorText + Environment.NewLine;
            }
            throw new TemplateException(host.Errors);
              }
              if (host.Errors.HasWarnings)
              {
            StringBuilder builder = new StringBuilder();
            foreach (CompilerError error in host.Errors)
            {
              builder.AppendLine(error.ErrorText);
            }
            //Trace.WriteLine(string.Format(CultureInfo.CurrentCulture, "CompilationWarnings", new object[] { templateFile, builder.ToString() }));
              }
              return str3;
        }
Ejemplo n.º 30
0
 public string Map(PageData pageData, PropertyData propertyData)
 {
     return string.Format("{0}", (propertyData.Value != null).ToString(CultureInfo.InvariantCulture)).ToLower();
 }