Ejemplo n.º 1
0
        public static TestProperty Register(string id, string label, Type valueType, TestPropertyAttributes attributes, Type owner)
        {
            ValidateArg.NotNullOrEmpty(id, "id");
            ValidateArg.NotNull(label, "label");
            ValidateArg.NotNull(valueType, "valueType");
            ValidateArg.NotNull(owner, "owner");

            return Register(id, label, string.Empty, string.Empty, valueType, null, attributes, owner);
        }
Ejemplo n.º 2
0
        public static TestProperty Register(string id, string label, Type valueType, TestPropertyAttributes attributes, Type owner)
        {
            ValidateArg.NotNullOrEmpty(id, nameof(id));
            ValidateArg.NotNull(label, nameof(label));
            ValidateArg.NotNull(valueType, nameof(valueType));
            ValidateArg.NotNull(owner, nameof(owner));

            return Register(id, label, string.Empty, string.Empty, valueType, null, attributes, owner);
        }
Ejemplo n.º 3
0
        public static TestProperty Register(string id, string label, Type valueType, TestPropertyAttributes attributes, Type owner)
        {
            if (string.IsNullOrEmpty(id))
                throw new ArgumentNullException(nameof(id));
            if (label is null)
                throw new ArgumentNullException(nameof(label));
            if (valueType is null)
                throw new ArgumentNullException(nameof(valueType));
            if (owner is null)
                throw new ArgumentNullException(nameof(owner));

            return Register(id, label, string.Empty, string.Empty, valueType, null, attributes, owner);
        }
Ejemplo n.º 4
0
        private TestProperty(string id, string label, string category, string description, Type valueType, ValidateValueCallback validateValueCallback, TestPropertyAttributes attributes)
        {
            ValidateArg.NotNullOrEmpty(id, "id");
            ValidateArg.NotNull(label, "label");
            ValidateArg.NotNull(category, "category");
            ValidateArg.NotNull(description, "description");
            ValidateArg.NotNull(valueType, "valueType");

            // If the type of property is unexpected, then fail as otherwise we will not be to serialize it over the wcf channel and serialize it in db.
            if (valueType == typeof(KeyValuePair<string, string>[]))
            {
                this.ValueType = "System.Collections.Generic.KeyValuePair`2[[System.String],[System.String]][]";
            }
            else if (valueType == typeof(string)
                || valueType == typeof(Uri)
                || valueType == typeof(string[])
                || valueType.AssemblyQualifiedName.Contains("System.Private")
                || valueType.AssemblyQualifiedName.Contains("mscorlib"))
            {
                // This comparison is a check to ensure assembly information is not embedded in data.
                // Use type.FullName instead of type.AssemblyQualifiedName since the internal assemblies
                // are different in desktop and coreclr. Thus AQN in coreclr includes System.Private.CoreLib which
                // is not available on the desktop.
                // Note that this doesn't handle generic types. Such types will fail during serialization.
                this.ValueType = valueType.FullName;
            }
            else if (valueType.GetTypeInfo().IsValueType)
            {
                // In case of custom types, let the assembly qualified name be available to help
                // deserialization on the client.
                this.ValueType = valueType.AssemblyQualifiedName;
            }
            else
            {
                throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, Resources.Resources.UnexpectedTypeOfProperty, valueType, id));
            }

            this.Id = id;
            this.Label = label;
            this.Category = category;
            this.Description = description;
            this.ValidateValueCallback = validateValueCallback;
            this.Attributes = attributes;
            this.valueType = valueType;
        }
Ejemplo n.º 5
0
        public static TestProperty Register(string id, string label, string category, string description, Type valueType, ValidateValueCallback validateValueCallback, TestPropertyAttributes attributes, Type owner)
        {
            ValidateArg.NotNullOrEmpty(id, "id");
            ValidateArg.NotNull(label, "label");
            ValidateArg.NotNull(category, "category");
            ValidateArg.NotNull(description, "description");
            ValidateArg.NotNull(valueType, "valueType");
            ValidateArg.NotNull(owner, "owner");

            TestProperty result;

            lock (s_properties)
            {
                if (s_properties.TryGetValue(id, out var propertyTypePair))
                {
                    // verify the data valueType is valid
                    if (propertyTypePair.Key.ValueType == valueType.AssemblyQualifiedName
                        || propertyTypePair.Key.ValueType == valueType.FullName
                        || propertyTypePair.Key.valueType == valueType)
                    {
                        // add the owner to set of owners for this GraphProperty object
                        propertyTypePair.Value.Add(owner);
                        result = propertyTypePair.Key;
                    }
                    else
                    {
                        // not the data valueType we expect, throw an exception
                        string message = string.Format(
                            CultureInfo.CurrentCulture,
                            Resources.Resources.Exception_RegisteredTestPropertyHasDifferentValueType,
                            id,
                            valueType.ToString(),
                            propertyTypePair.Key.ValueType);

                        throw new InvalidOperationException(message);
                    }
                }
                else
                {
                    // create a new TestProperty object
                    result = new TestProperty(id, label, category, description, valueType, validateValueCallback, attributes);

                    // setup the data pair used to track owners of this GraphProperty
                    propertyTypePair = new KeyValuePair<TestProperty, HashSet<Type>>(result, new HashSet<Type>());
                    propertyTypePair.Value.Add(owner);

                    // add to the dictionary
                    s_properties[id] = propertyTypePair;
                }
            }

            return result;
        }
Ejemplo n.º 6
0
 public static Common.Models.TestPropertyAttributes Convert(this TestPropertyAttributes testPropertyAttributes)
 {
     return((Common.Models.TestPropertyAttributes)testPropertyAttributes);
 }