MergeIntoBean(ConfigurationPropertiesImpl properties, Configuration config) { SafeType <Configuration> configType = SafeType <Configuration> .Get(config); IDictionary <string, PropertyInfo> descriptors = GetFilteredProperties(configType); foreach (ConfigurationPropertyImpl property in properties.Properties) { String name = property.Name; PropertyInfo desc = CollectionUtil.GetValue(descriptors, name, null); if (desc == null) { String FMT = "Class ''{0}'' does not have a property ''{1}''."; String MSG = String.Format(FMT, configType.RawType.Name, name); throw new ArgumentException(MSG); } object val = property.Value; //some value types such as arrays //are mutable. make sure the config object //has its own copy val = SerializerUtil.CloneObject(val); desc.SetValue(config, val, null); } }
public APIConfiguration CreateDefaultAPIConfiguration() { APIConfigurationImpl rv = (APIConfigurationImpl) SerializerUtil.CloneObject(_defaultAPIConfiguration); rv.ConnectorInfo = this; return(rv); }
/// <summary> /// Builds up the maps of supported operations and calls. /// </summary> public AbstractConnectorFacade(APIConfigurationImpl configuration) { Assertions.NullCheck(configuration, "configuration"); //clone in case application tries to modify //after the fact. this is necessary to //ensure thread-safety of a ConnectorFacade //also, configuration is used as a key in the //pool, so it is important that it not be modified. _configuration = (APIConfigurationImpl)SerializerUtil.CloneObject(configuration); //parent ref not included in the clone _configuration.ConnectorInfo = (configuration.ConnectorInfo); }
/// <summary> /// Create a new ObjectPool /// </summary> /// <param name="handler">Handler for objects</param> /// <param name="config">Configuration for the pool</param> public ObjectPool(ObjectPoolHandler <T> handler, ObjectPoolConfiguration config) { Assertions.NullCheck(handler, "handler"); Assertions.NullCheck(config, "config"); _handler = handler; //clone it _config = (ObjectPoolConfiguration)SerializerUtil.CloneObject(config); //validate it _config.Validate(); }
public void TestRange() { for (byte i = 0; i < 0xFF; i++) { byte expected = i; GuardedByteArray gba = new GuardedByteArray(); gba = (GuardedByteArray)SerializerUtil.CloneObject(gba); gba.AppendByte(i); gba.Access(new GuardedByteArray.LambdaAccessor(clearChars => { int v = (byte)clearChars[0]; Assert.AreEqual(expected, v); })); } }
/// <summary> /// Derives another RemoteConnectorInfoManagerImpl with /// a different RemoteFrameworkConnectionInfo but with the /// same metadata /// </summary> /// <param name="info"></param> public RemoteConnectorInfoManagerImpl Derive(RemoteFrameworkConnectionInfo info) { RemoteConnectorInfoManagerImpl rv = new RemoteConnectorInfoManagerImpl(); IList <Object> remoteInfosObj = (IList <Object>)SerializerUtil.CloneObject(_connectorInfo); IList <ConnectorInfo> remoteInfos = CollectionUtil.NewList <object, ConnectorInfo>(remoteInfosObj); foreach (ConnectorInfo remoteInfo in remoteInfos) { ((RemoteConnectorInfoImpl)remoteInfo).RemoteConnectionInfo = (info); } rv._connectorInfo = CollectionUtil.AsReadOnlyList(remoteInfos); return(rv); }
public void TestUnicode() { for (int i = 0; i < 0xFFFF; i++) { int expected = i; char c = (char)i; GuardedString gs = new GuardedString(); gs = (GuardedString)SerializerUtil.CloneObject(gs); gs.AppendChar(c); gs.Access(clearChars => { int v = (int)clearChars[0]; Assert.AreEqual(expected, v); }); } }
protected virtual Object CloneObject(Object o) { return(SerializerUtil.CloneObject(o)); }