コード例 #1
0
        public bool Equals(SerializedPropertyInfo other)
        {
            if (other == null)
            {
                return(false);
            }

            if (IsString != other.IsString)
            {
                return(false);
            }

            if (!ReferenceEquals(SerializedValue, other.SerializedValue))
            {
                if (SerializedValue == null || other.SerializedValue == null)
                {
                    return(false);
                }

                if (!SerializedValue.Equals(other.SerializedValue))
                {
                    return(false);
                }
            }

            return(true);
        }
コード例 #2
0
        public T GetProperty <T>(string propertyName)
        {
            if (Properties?.ContainsKey(propertyName) != true)
            {
                throw new InvalidOperationException(
                          string.Format(
                              CultureInfo.CurrentCulture,
                              SdkResources.PropertyDoesNotExist,
                              propertyName));
            }

            SerializedPropertyInfo propValue = Properties[propertyName];

            if (propValue == null)
            {
                if (typeof(T).IsValueType)
                {
                    throw new InvalidOperationException(
                              string.Format(
                                  CultureInfo.CurrentCulture,
                                  SdkResources.PropertyOfValueTypeCannotBeNull,
                                  propertyName,
                                  typeof(T).FullName));
                }

                // This will return null for reference types. Could not set null here b/c T could be a value type as well.
                return(default);
コード例 #3
0
        public static void Write(JsonWriter writer, SerializedPropertyInfo value)
        {
            SerializedPropertyInfo spi = (SerializedPropertyInfo)value;

            if (spi == null || spi.SerializedValue == null)
            {
                writer.WriteNull();
            }
            else
            {
                writer.WriteRawValue(spi.SerializedValue);
            }
        }
コード例 #4
0
        public void SetProperty <T>(string propertyName, T value)
        {
            if (Properties == null)
            {
                Properties = new Dictionary <string, SerializedPropertyInfo>();
            }

            bool isString = typeof(T) == typeof(string);

            string serializedValue;

            if (value == null)
            {
                serializedValue = NullValue;
            }
            else
            {
                if (isString)
                {
                    serializedValue = JsonConvert.ToString(value);
                }
                else
                {
                    // Use the appropriate serializer settings
                    JsonSerializerSettings settings = null;

                    if (propertyName.StartsWith("sarifv2/"))
                    {
                        settings = SarifTransformerUtilities.JsonSettingsV2Compact;
                    }
                    else if (propertyName.StartsWith("sarifv1/"))
                    {
                        settings = SarifTransformerUtilities.JsonSettingsV1Compact;
                    }

                    serializedValue = JsonConvert.SerializeObject(value, settings);
                }
            }

            Properties[propertyName] = new SerializedPropertyInfo(serializedValue, isString);
        }
コード例 #5
0
        public void SetPropertiesFrom(IPropertyBagHolder other)
        {
            if (other == null)
            {
                throw new ArgumentNullException(nameof(other));
            }

            // We need the concrete class because the IPropertyBagHolder interface
            // doesn't expose the raw Properties array.
            PropertyBagHolder otherHolder = other as PropertyBagHolder;

            Debug.Assert(otherHolder != null);

            Properties = other.PropertyNames.Count > 0 ? new Dictionary <string, SerializedPropertyInfo>() : null;

            foreach (string propertyName in other.PropertyNames)
            {
                SerializedPropertyInfo otherInfo = otherHolder.Properties[propertyName];
                Properties[propertyName] = new SerializedPropertyInfo(otherInfo.SerializedValue, otherInfo.IsString);
            }
        }
コード例 #6
0
        public void SetProperty <T>(string propertyName, T value)
        {
            if (Properties == null)
            {
                Properties = new Dictionary <string, SerializedPropertyInfo>();
            }

            bool isString = typeof(T) == typeof(string);

            string serializedValue;

            if (value == null)
            {
                serializedValue = NullValue;
            }
            else
            {
                serializedValue = isString
                    ? JsonConvert.ToString(value)
                    : JsonConvert.SerializeObject(value);
            }

            Properties[propertyName] = new SerializedPropertyInfo(serializedValue, isString);
        }