コード例 #1
0
        public static void ReadObjectProperties(this IReadOnlyPropertySet pset, object ob, Type typeToScan, bool includeBaseMembers = false)
        {
            DataSerializer ser   = new DataSerializer(Services.ProjectService.DataContext);
            var            props = Services.ProjectService.DataContext.GetProperties(ser.SerializationContext, ob);

            var mso = pset as IMSBuildProjectObject;

            if (mso != null && mso.ParentProject != null)
            {
                ser.SerializationContext.BaseFile = mso.ParentProject.FileName;
            }
            ser.SerializationContext.DirectorySeparatorChar = '\\';

            foreach (var prop in props)
            {
                if (prop.IsExternal)
                {
                    continue;
                }
                object readVal = null;
                if (prop.PropertyType == typeof(FilePath))
                {
                    FilePath def = (string)prop.DefaultValue;
                    readVal = pset.GetPathValue(prop.Name, def);
                }
                else if (prop.DataType is PathDataType && prop.PropertyType == typeof(string))
                {
                    FilePath def = (string)prop.DefaultValue;
                    readVal = pset.GetPathValue(prop.Name, def);
                    readVal = readVal.ToString();
                }
                else if (prop.PropertyType == typeof(string))
                {
                    readVal = pset.GetValue(prop.Name, (string)prop.DefaultValue);
                }
                else if (prop.DataType.IsSimpleType)
                {
                    readVal = pset.GetValue(prop.Name, prop.PropertyType, prop.DefaultValue);
                }
                else if (prop.PropertyType.IsGenericType && prop.PropertyType.GetGenericTypeDefinition() == typeof(Nullable <>))
                {
                    readVal = pset.GetValue(prop.Name, prop.PropertyType, prop.DefaultValue);
                }
                else
                {
                    var val = pset.GetValue(prop.Name);
                    if (!string.IsNullOrEmpty(val))
                    {
                        try {
                            if (!prop.WrapObject)
                            {
                                val = "<a>" + val + "</a>";
                            }
                            var data = XmlConfigurationReader.DefaultReader.Read(new XmlTextReader(new StringReader(val)));
                            if (prop.HasSetter && prop.DataType.CanCreateInstance)
                            {
                                readVal = prop.Deserialize(ser.SerializationContext, ob, data);
                            }
                            else if (prop.DataType.CanReuseInstance)
                            {
                                // Try to deserialize over the existing instance
                                prop.Deserialize(ser.SerializationContext, ob, data, prop.GetValue(ob));
                                continue;
                            }
                            else
                            {
                                throw new InvalidOperationException("The property '" + prop.Name + "' does not have a setter.");
                            }
                        } catch (Exception ex) {
                            LoggingService.LogError("Cound not read project property '" + prop.Name + "'", ex);
                        }
                    }
                    else
                    {
                        continue;
                    }
                }
                prop.SetValue(ob, readVal);
            }
        }
コード例 #2
0
 string GetMetadata(string name)
 {
     return(metadata.GetValue(name));
 }
コード例 #3
0
 internal FrameworkReference(string include, IReadOnlyPropertySet metadata)
 {
     Include = include;
     TargetingPackVersion = metadata.GetValue("TargetingPackVersion");
 }