예제 #1
0
        public void Ctor_Immutable(bool immutable)
        {
            var attribute = new ImmutableObjectAttribute(immutable);

            Assert.Equal(immutable, attribute.Immutable);
            Assert.Equal(!immutable, attribute.IsDefaultAttribute());
        }
예제 #2
0
 public void Equals_Object_ReturnsExpected(ImmutableObjectAttribute attribute, object other, bool expected)
 {
     Assert.Equal(expected, attribute.Equals(other));
     if (other is ImmutableObjectAttribute)
     {
         Assert.Equal(expected, attribute.GetHashCode().Equals(other.GetHashCode()));
     }
 }
        public override bool Equals(object obj)
        {
            if (obj == this)
            {
                return(true);
            }

            ImmutableObjectAttribute other = obj as ImmutableObjectAttribute;

            return(other?.Immutable == Immutable);
        }
예제 #4
0
        public static object CloneDirectoryData(object data)
        {
            if (data == null)
            {
                return(null);
            }
            if (data.GetType() == typeof(RawSecurityDescriptor))
            {
                int    binaryLength = ((RawSecurityDescriptor)data).BinaryLength;
                byte[] binaryForm   = new byte[binaryLength];
                ((RawSecurityDescriptor)data).GetBinaryForm(binaryForm, 0);
                return(new RawSecurityDescriptor(binaryForm, 0));
            }
            if (data is ICloneable)
            {
                return(((ICloneable)data).Clone());
            }
            if (data.GetType() == typeof(SecurityIdentifier) || data.GetType() == typeof(PSCredential))
            {
                return(data);
            }
            ImmutableObjectAttribute immutableObjectAttribute = (ImmutableObjectAttribute)data.GetType().GetTypeInfo().GetCustomAttribute(typeof(ImmutableObjectAttribute));

            if (immutableObjectAttribute != null && immutableObjectAttribute.Immutable)
            {
                return(data);
            }
            object result;

            try
            {
                result = CloneHelper.SerializeObj(data);
            }
            catch (SerializationException)
            {
                throw new CannotCloneException(DataStrings.DataNotCloneable(data.GetType().Name));
            }
            return(result);
        }
예제 #5
0
 public void DefaultProperties_GetImmutable_ReturnsExpected(ImmutableObjectAttribute attribute, bool expectedImmutableObject)
 {
     Assert.Equal(expectedImmutableObject, attribute.Immutable);
     Assert.Equal(!expectedImmutableObject, attribute.IsDefaultAttribute());
 }
 public void NameTests(ImmutableObjectAttribute attribute, bool isImmutable)
 {
     Assert.Equal(isImmutable, attribute.Immutable);
 }
        public void GetImmutable(bool value)
        {
            var attribute = new ImmutableObjectAttribute(value);

            Assert.Equal(value, attribute.Immutable);
        }
예제 #8
0
 public void NameTests(ImmutableObjectAttribute attribute, bool isImmutable)
 {
     Assert.Equal(isImmutable, attribute.Immutable);
 }
예제 #9
0
        public void GetImmutable(bool value)
        {
            var attribute = new ImmutableObjectAttribute(value);

            Assert.Equal(value, attribute.Immutable);
        }