Imported Upstream version 3.6.0

Former-commit-id: da6be194a6b1221998fc28233f2503bd61dd9d14
This commit is contained in:
Jo Shields
2014-08-13 10:39:27 +01:00
commit a575963da9
50588 changed files with 8155799 additions and 0 deletions

View File

@ -0,0 +1,397 @@
//
// System.ComponentModel.Design.Serialization.BasicDesignerLoader
//
// Authors:
// Ivan N. Zlatev (contact i-nZ.net)
//
// (C) 2007 Ivan N. Zlatev
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
#if NET_2_0
using System;
using System.Collections;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.Windows.Forms;
namespace System.ComponentModel.Design.Serialization
{
public abstract class BasicDesignerLoader : DesignerLoader, IDesignerLoaderService
{
[Flags]
protected enum ReloadOptions
{
Default,
Force,
ModifyOnError,
NoFlush
}
private bool _loaded;
private bool _loading;
private IDesignerLoaderHost _host;
private int _dependenciesCount;
private bool _notificationsEnabled;
private bool _modified;
private string _baseComponentClassName;
private DesignerSerializationManager _serializationMananger;
private bool _flushing;
private bool _reloadScheduled;
private ReloadOptions _reloadOptions;
protected BasicDesignerLoader ()
{
_loading = _loaded = _flushing = _reloadScheduled = false;
_host = null;
_notificationsEnabled = false;
_modified = false;
_dependenciesCount = 0;
}
protected virtual void Initialize ()
{
_serializationMananger = new DesignerSerializationManager (_host);
DesignSurfaceServiceContainer serviceContainer = _host.GetService (typeof (IServiceContainer)) as DesignSurfaceServiceContainer;
if (serviceContainer != null) {
serviceContainer.AddService (typeof (IDesignerLoaderService), (IDesignerLoaderService) this);
serviceContainer.AddNonReplaceableService (typeof (IDesignerSerializationManager), _serializationMananger);
}
}
public override void BeginLoad (IDesignerLoaderHost host)
{
if (host == null)
throw new ArgumentNullException ("host");
if (_loaded)
throw new InvalidOperationException ("Already loaded.");
if (_host != null && _host != host)
throw new InvalidOperationException ("Trying to load with a different host");
if (_host == null) { // beingload is called on reload - no need to initialize twice.
_host = host;
Initialize ();
}
IDisposable session = _serializationMananger.CreateSession ();
IDesignerLoaderService loader = _host.GetService (typeof (IDesignerLoaderService)) as IDesignerLoaderService;
if (loader != null) {
_dependenciesCount = -1;
loader.AddLoadDependency ();
} else {
OnBeginLoad ();
}
bool successful = true;
try {
PerformLoad (_serializationMananger);
} catch (Exception e) {
successful = false;
_serializationMananger.Errors.Add (e);
}
if (loader != null)
loader.DependentLoadComplete (successful, _serializationMananger.Errors);
else
OnEndLoad (successful, _serializationMananger.Errors);
session.Dispose ();
}
protected abstract void PerformLoad (IDesignerSerializationManager serializationManager);
protected virtual void OnBeginLoad ()
{
_loading = true;
}
protected virtual void OnEndLoad (bool successful, ICollection errors)
{
_host.EndLoad (_baseComponentClassName, successful, errors);
if (successful) {
_loaded = true;
EnableComponentNotification (true);
} else {
if (_reloadScheduled) { // we are reloading
bool modify = ((_reloadOptions & ReloadOptions.ModifyOnError) == ReloadOptions.ModifyOnError);
if (modify) {
OnModifying ();
this.Modified = true;
}
}
}
_loading = false;
}
public override bool Loading {
get { return _loading; }
}
protected IDesignerLoaderHost LoaderHost {
get { return _host; }
}
protected virtual bool Modified {
get { return _modified; }
set { _modified = value; }
}
protected object PropertyProvider {
get {
if (!_loaded)
throw new InvalidOperationException ("host not initialized");
return _serializationMananger.PropertyProvider;
}
set {
if (!_loaded)
throw new InvalidOperationException ("host not initialized");
_serializationMananger.PropertyProvider = value;
}
}
protected bool ReloadPending {
get { return _reloadScheduled; }
}
protected virtual bool EnableComponentNotification (bool enable)
{
if (!_loaded)
throw new InvalidOperationException ("host not initialized");
IComponentChangeService service = _host.GetService (typeof (IComponentChangeService)) as IComponentChangeService;
if (service != null && _notificationsEnabled != enable) {
if (enable) {
service.ComponentAdding += new ComponentEventHandler (OnComponentAdding);
service.ComponentAdded += new ComponentEventHandler (OnComponentAdded);
service.ComponentRemoving += new ComponentEventHandler (OnComponentRemoving);
service.ComponentRemoved += new ComponentEventHandler (OnComponentRemoved);
service.ComponentChanging += new ComponentChangingEventHandler (OnComponentChanging);
service.ComponentChanged += new ComponentChangedEventHandler (OnComponentChanged);
service.ComponentRename += new ComponentRenameEventHandler (OnComponentRename);
} else {
service.ComponentAdding -= new ComponentEventHandler (OnComponentAdding);
service.ComponentAdded -= new ComponentEventHandler (OnComponentAdded);
service.ComponentRemoving -= new ComponentEventHandler (OnComponentRemoving);
service.ComponentRemoved -= new ComponentEventHandler (OnComponentRemoved);
service.ComponentChanging -= new ComponentChangingEventHandler (OnComponentChanging);
service.ComponentChanged -= new ComponentChangedEventHandler (OnComponentChanged);
service.ComponentRename -= new ComponentRenameEventHandler (OnComponentRename);
}
}
return _notificationsEnabled == true ? true : false;
}
private void OnComponentAdded (object sender, ComponentEventArgs args)
{
if (!_loading && _loaded)
this.Modified = true;
}
private void OnComponentRemoved (object sender, ComponentEventArgs args)
{
if (!_loading && _loaded)
this.Modified = true;
}
private void OnComponentAdding (object sender, ComponentEventArgs args)
{
if (!_loading && _loaded)
OnModifying ();
}
private void OnComponentRemoving (object sender, ComponentEventArgs args)
{
if (!_loading && _loaded)
OnModifying ();
}
private void OnComponentChanged (object sender, ComponentChangedEventArgs args)
{
if (!_loading && _loaded)
this.Modified = true;
}
private void OnComponentChanging (object sender, ComponentChangingEventArgs args)
{
if (!_loading && _loaded)
OnModifying ();
}
private void OnComponentRename (object sender, ComponentRenameEventArgs args)
{
if (!_loading && _loaded) {
OnModifying ();
this.Modified = true;
}
}
public override void Flush ()
{
if (!_loaded)
throw new InvalidOperationException ("host not initialized");
if (!_flushing && this.Modified) {
_flushing = true;
using ((IDisposable)_serializationMananger.CreateSession ()) {
try {
PerformFlush (_serializationMananger);
} catch (Exception e) {
_serializationMananger.Errors.Add (e);
ReportFlushErrors (_serializationMananger.Errors);
}
}
_flushing = false;
}
}
protected abstract void PerformFlush (IDesignerSerializationManager serializationManager);
// MSDN: The default implementation always returns true.
protected virtual bool IsReloadNeeded ()
{
return true;
}
protected virtual void OnBeginUnload ()
{
}
protected virtual void OnModifying ()
{
}
// MSDN: reloads are performed at idle time
protected void Reload (ReloadOptions flags)
{
if (!_reloadScheduled) {
_reloadScheduled = true;
_reloadOptions = flags;
bool force = ((flags & ReloadOptions.Force) == ReloadOptions.Force);
if (force)
ReloadCore ();
else
Application.Idle += new EventHandler (OnIdle);
}
}
private void OnIdle (object sender, EventArgs args)
{
Application.Idle -= new EventHandler (OnIdle);
ReloadCore ();
}
private void ReloadCore ()
{
bool flush = !((_reloadOptions & ReloadOptions.NoFlush) == ReloadOptions.NoFlush);
if (flush)
Flush ();
Unload ();
_host.Reload ();
BeginLoad (_host); // calls EndLoad, which will check for ReloadOptions.ModifyOnError
_reloadScheduled = false;
}
private void Unload ()
{
if (_loaded) {
OnBeginUnload ();
EnableComponentNotification (false);
_loaded = false;
_baseComponentClassName = null;
}
}
// The default implementation of ReportFlushErrors raises the last exception in the collection.
//
protected virtual void ReportFlushErrors (ICollection errors)
{
object last = null;
foreach (object o in errors)
last = o;
throw (Exception)last;
}
// Must be called during PerformLoad by subclasses.
protected void SetBaseComponentClassName (string name)
{
if (name == null)
throw new ArgumentNullException ("name");
_baseComponentClassName = name;
}
#region IDesignerLoaderService implementation
void IDesignerLoaderService.AddLoadDependency ()
{
_dependenciesCount++;
if (_dependenciesCount == 0) {
_dependenciesCount = 1;
OnBeginLoad ();
}
}
void IDesignerLoaderService.DependentLoadComplete (bool successful, ICollection errorCollection)
{
if (_dependenciesCount == 0)
throw new InvalidOperationException ("dependencies == 0");
_dependenciesCount--;
if (_dependenciesCount == 0) {
OnEndLoad (successful, errorCollection);
}
}
bool IDesignerLoaderService.Reload ()
{
if (_dependenciesCount == 0) {
this.Reload (ReloadOptions.Force);
return true;
}
return false;
}
#endregion
protected object GetService (Type serviceType)
{
if (_host != null)
return _host.GetService (serviceType);
return null;
}
public override void Dispose ()
{
this.LoaderHost.RemoveService (typeof (IDesignerLoaderService));
Unload ();
}
}
}
#endif

View File

@ -0,0 +1,291 @@
//
// System.ComponentModel.Design.Serialization.CodeDomDesignerLoader
//
// Authors:
// Ivan N. Zlatev (contact i-nZ.net)
//
// (C) 2007 Ivan N. Zlatev
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
#if NET_2_0
using System;
using System.Collections;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.CodeDom;
using System.CodeDom.Compiler;
namespace System.ComponentModel.Design.Serialization
{
public abstract class CodeDomDesignerLoader : BasicDesignerLoader, INameCreationService, IDesignerSerializationService
{
private CodeDomSerializer _rootSerializer;
protected CodeDomDesignerLoader ()
{
}
protected override void Initialize ()
{
base.Initialize ();
base.LoaderHost.AddService (typeof (IDesignerSerializationService), this);
base.LoaderHost.AddService (typeof (INameCreationService), this);
base.LoaderHost.AddService (typeof (ComponentSerializationService), new
CodeDomComponentSerializationService (base.LoaderHost));
if (this.TypeResolutionService != null &&
LoaderHost.GetService (typeof (ITypeResolutionService)) == null)
LoaderHost.AddService (typeof (ITypeResolutionService), this.TypeResolutionService);
IDesignerSerializationManager manager = base.LoaderHost.GetService (typeof (IDesignerSerializationManager)) as IDesignerSerializationManager;
if (manager != null)
manager.AddSerializationProvider (CodeDomSerializationProvider.Instance);
}
protected override bool IsReloadNeeded ()
{
if (this.CodeDomProvider is ICodeDomDesignerReload)
return ((ICodeDomDesignerReload) CodeDomProvider).ShouldReloadDesigner (Parse ());
return base.IsReloadNeeded ();
}
protected override void PerformLoad (IDesignerSerializationManager manager)
{
if (manager == null)
throw new ArgumentNullException ("manager");
CodeCompileUnit document = this.Parse ();
if (document == null)
throw new NotSupportedException ("The language did not provide a code parser for this file");
string namespaceName = null;
CodeTypeDeclaration rootDocument = GetFirstCodeTypeDecl (document, out namespaceName);
if (rootDocument == null)
throw new InvalidOperationException ("Cannot find a declaration in a namespace to load.");
_rootSerializer = manager.GetSerializer (manager.GetType (rootDocument.BaseTypes[0].BaseType),
typeof (RootCodeDomSerializer)) as CodeDomSerializer;
if (_rootSerializer == null)
throw new InvalidOperationException ("Serialization not supported for this class");
_rootSerializer.Deserialize (manager, rootDocument);
base.SetBaseComponentClassName (namespaceName + "." + rootDocument.Name);
}
private CodeTypeDeclaration GetFirstCodeTypeDecl (CodeCompileUnit document, out string namespaceName)
{
namespaceName = null;
foreach (CodeNamespace namesp in document.Namespaces) {
foreach (CodeTypeDeclaration declaration in namesp.Types) {
if (declaration.IsClass) {
namespaceName = namesp.Name;
return declaration;
}
}
}
return null;
}
protected override void PerformFlush (IDesignerSerializationManager manager)
{
if (_rootSerializer != null) {
CodeTypeDeclaration typeDecl = (CodeTypeDeclaration) _rootSerializer.Serialize (manager,
base.LoaderHost.RootComponent);
this.Write (MergeTypeDeclWithCompileUnit (typeDecl, this.Parse ()));
}
}
// Will either add the class or replace an existing class
// with the one from GenerateClass ()
//
private CodeCompileUnit MergeTypeDeclWithCompileUnit (CodeTypeDeclaration typeDecl, CodeCompileUnit unit)
{
CodeNamespace namespac = null;
int typeIndex = -1;
foreach (CodeNamespace namesp in unit.Namespaces) {
for (int i=0; i< namesp.Types.Count; i++) {
if (namesp.Types[i].IsClass) {
typeIndex = i;
namespac = namesp;
}
}
}
if (typeIndex != -1)
namespac.Types.RemoveAt (typeIndex);
namespac.Types.Add (typeDecl);
return unit;
}
protected override void OnBeginLoad ()
{
base.OnBeginLoad ();
IComponentChangeService service = base.GetService (typeof (IComponentChangeService)) as IComponentChangeService;
if (service != null)
service.ComponentRename += this.OnComponentRename_EventHandler;
}
protected override void OnBeginUnload ()
{
base.OnBeginUnload ();
IComponentChangeService service = base.GetService (typeof (IComponentChangeService)) as IComponentChangeService;
if (service != null)
service.ComponentRename -= this.OnComponentRename_EventHandler;
}
protected override void OnEndLoad (bool successful, ICollection errors)
{
base.OnEndLoad (successful, errors);
// XXX: msdn says overriden
}
private void OnComponentRename_EventHandler (object sender, ComponentRenameEventArgs args)
{
this.OnComponentRename (args.Component, args.OldName, args.NewName);
}
// MSDN says that here one should raise ComponentRename event and that's nonsense.
//
protected virtual void OnComponentRename (object component, string oldName, string newName)
{
// What shall we do with the drunken sailor,
// what shall we do with the drunken sailor early in the morning?
}
protected abstract CodeDomProvider CodeDomProvider { get; }
protected abstract ITypeResolutionService TypeResolutionService { get; }
protected abstract CodeCompileUnit Parse ();
protected abstract void Write (CodeCompileUnit unit);
public override void Dispose ()
{
base.Dispose ();
}
#region INameCreationService implementation
// very simplistic implementation to generate names like "button1", "someControl2", etc
//
string INameCreationService.CreateName (IContainer container, Type dataType)
{
if (dataType == null)
throw new ArgumentNullException ("dataType");
string name = dataType.Name;
char lower = Char.ToLower (name[0]);
name = name.Remove (0, 1);
name = name.Insert (0, Char.ToString (lower));
int uniqueId = 1;
bool unique = false;
while (!unique) {
if (container != null && container.Components[name + uniqueId] != null) {
uniqueId++;
} else {
unique = true;
name = name + uniqueId;
}
}
if (this.CodeDomProvider != null)
name = CodeDomProvider.CreateValidIdentifier (name);
return name;
}
bool INameCreationService.IsValidName (string name)
{
if (name == null)
throw new ArgumentNullException ("name");
bool valid = true;
if (base.LoaderHost != null && base.LoaderHost.Container.Components[name] != null) {
valid = false;
} else {
if (this.CodeDomProvider != null) {
valid = CodeDomProvider.IsValidIdentifier (name);
} else {
if (name.Trim().Length == 0)
valid = false;
foreach (char c in name) {
if (!Char.IsLetterOrDigit (c)) {
valid = false;
break;
}
}
}
}
return valid;
}
void INameCreationService.ValidateName (string name)
{
if (!((INameCreationService) this).IsValidName (name))
throw new ArgumentException ("Invalid name '" + name + "'");
}
#endregion
#region IDesignerSerializationService implementation
ICollection IDesignerSerializationService.Deserialize (object serializationData)
{
if (serializationData == null)
throw new ArgumentNullException ("serializationData");
ComponentSerializationService service = LoaderHost.GetService (typeof (ComponentSerializationService)) as ComponentSerializationService;
SerializationStore store = serializationData as SerializationStore;
if (service != null && serializationData != null)
return service.Deserialize (store, this.LoaderHost.Container);
return new object[0];
}
object IDesignerSerializationService.Serialize (ICollection objects)
{
if (objects == null)
throw new ArgumentNullException ("objects");
ComponentSerializationService service = LoaderHost.GetService (typeof (ComponentSerializationService)) as ComponentSerializationService;
if (service != null) {
SerializationStore store = service.CreateStore ();
foreach (object o in objects)
service.Serialize (store, o);
store.Close ();
return store;
}
return null;
}
#endregion
}
}
#endif

View File

@ -0,0 +1,48 @@
//
// System.ComponentModel.Design.Serialization.CodeDomLocalizationModel
//
// Author:
// Atsushi Enomoto (atsushi@ximian.com)
//
// Copyright (C) 2007 Novell, Inc.
//
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
#if NET_2_0
using System.Drawing;
using System.Drawing.Design;
using System.Drawing.Drawing2D;
using System.Security.Permissions;
namespace System.ComponentModel.Design.Serialization
{
public enum CodeDomLocalizationModel
{
None,
PropertyAssignment,
PropertyReflection
}
}
#endif

View File

@ -0,0 +1,70 @@
//
// System.ComponentModel.Design.Serialization.CodeDomLocalizationProvider
//
// Author:
// Atsushi Enomoto (atsushi@ximian.com)
//
// Copyright (C) 2007 Novell, Inc.
//
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
#if NET_2_0
using System.CodeDom;
using System.CodeDom.Compiler;
using System.ComponentModel;
using System.Globalization;
using System.Security.Permissions;
namespace System.ComponentModel.Design.Serialization
{
public sealed class CodeDomLocalizationProvider : IDisposable, IDesignerSerializationProvider
{
[MonoTODO]
public CodeDomLocalizationProvider (IServiceProvider provider, CodeDomLocalizationModel model)
{
throw new NotImplementedException ();
}
[MonoTODO]
public CodeDomLocalizationProvider (IServiceProvider provider, CodeDomLocalizationModel model, CultureInfo [] supportedCultures)
{
throw new NotImplementedException ();
}
[MonoTODO]
public void Dispose ()
{
}
[MonoTODO]
object IDesignerSerializationProvider.GetSerializer (IDesignerSerializationManager manager,
object currentSerializer, Type objectType,
Type serializerType)
{
throw new NotImplementedException ();
}
}
}
#endif

View File

@ -0,0 +1,108 @@
//
// System.ComponentModel.Design.Serialization.CodeDomSerializationProvider
//
// Authors:
// Ivan N. Zlatev (contact i-nZ.net)
//
// (C) 2007 Ivan N. Zlatev
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
#if NET_2_0
using System;
using System.Collections;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.CodeDom;
namespace System.ComponentModel.Design.Serialization
{
// Added as a provider by the RootCodeDomSerializationProvider
//
internal class CodeDomSerializationProvider : IDesignerSerializationProvider
{
private static CodeDomSerializationProvider _instance = null;
public static CodeDomSerializationProvider Instance {
get {
if (_instance == null)
_instance = new CodeDomSerializationProvider ();
return _instance;
}
}
public CodeDomSerializationProvider ()
{
_componentSerializer = new ComponentCodeDomSerializer ();
_propertySerializer = new PropertyCodeDomSerializer ();
_eventSerializer = new EventCodeDomSerializer ();
_collectionSerializer = new CollectionCodeDomSerializer ();
_primitiveSerializer = new PrimitiveCodeDomSerializer ();
_rootSerializer = new RootCodeDomSerializer ();
_enumSerializer = new EnumCodeDomSerializer ();
_othersSerializer = new CodeDomSerializer ();
}
private CodeDomSerializerBase _componentSerializer;
private CodeDomSerializerBase _propertySerializer;
private CodeDomSerializerBase _eventSerializer;
private CodeDomSerializerBase _primitiveSerializer;
private CodeDomSerializerBase _collectionSerializer;
private CodeDomSerializerBase _rootSerializer;
private CodeDomSerializerBase _enumSerializer;
private CodeDomSerializerBase _othersSerializer;
public object GetSerializer (IDesignerSerializationManager manager, object currentSerializer,
Type objectType, Type serializerType)
{
CodeDomSerializerBase serializer = null;
if (serializerType == typeof(CodeDomSerializer)) { // CodeDomSerializer
if (objectType == null) // means that value to serialize is null CodePrimitiveExpression (null)
serializer = _primitiveSerializer;
else if (typeof(IComponent).IsAssignableFrom (objectType))
serializer = _componentSerializer;
else if (objectType.IsEnum || typeof (Enum).IsAssignableFrom (objectType))
serializer = _enumSerializer;
else if (objectType.IsPrimitive || objectType == typeof (String))
serializer = _primitiveSerializer;
else if (typeof(ICollection).IsAssignableFrom (objectType))
serializer = _collectionSerializer;
else
serializer = _othersSerializer;
} else if (serializerType == typeof(MemberCodeDomSerializer)) { // MemberCodeDomSerializer
if (typeof (PropertyDescriptor).IsAssignableFrom (objectType))
serializer = _propertySerializer;
else if (typeof (EventDescriptor).IsAssignableFrom (objectType))
serializer = _eventSerializer;
} else if (serializerType == typeof (RootCodeDomSerializer)) {
serializer = _rootSerializer;
}
return serializer;
}
}
}
#endif

View File

@ -0,0 +1,190 @@
//
// System.ComponentModel.Design.Serialization.CodeDomSerializer
//
// Authors:
// Ivan N. Zlatev (contact i-nZ.net)
//
// (C) 2007 Ivan N. Zlatev
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
#if NET_2_0
using System;
using System.Collections;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.CodeDom;
namespace System.ComponentModel.Design.Serialization
{
public class CodeDomSerializer : CodeDomSerializerBase
{
public CodeDomSerializer ()
{
}
public virtual object SerializeAbsolute (IDesignerSerializationManager manager, object value)
{
if (value == null)
throw new ArgumentNullException ("value");
if (manager == null)
throw new ArgumentNullException ("manager");
SerializeAbsoluteContext context = new SerializeAbsoluteContext ();
manager.Context.Push (context);
object result = this.Serialize (manager, value);
manager.Context.Pop ();
return result;
}
public virtual object Serialize (IDesignerSerializationManager manager, object value)
{
if (value == null)
throw new ArgumentNullException ("value");
if (manager == null)
throw new ArgumentNullException ("manager");
object serialized = null;
bool isComplete = false;
CodeExpression createExpr = base.SerializeCreationExpression (manager, value, out isComplete);
if (createExpr != null) {
if (isComplete) {
serialized = createExpr;
} else {
CodeStatementCollection statements = new CodeStatementCollection ();
base.SerializeProperties (manager, statements, value, new Attribute[0]);
base.SerializeEvents (manager, statements, value, new Attribute[0]);
serialized = statements;
}
base.SetExpression (manager, value, createExpr);
}
return serialized;
}
[Obsolete ("This method has been deprecated. Use SerializeToExpression or GetExpression instead.")]
protected CodeExpression SerializeToReferenceExpression (IDesignerSerializationManager manager, object value)
{
return base.SerializeToExpression (manager, value);
}
// I am not sure what this does, but the only name I can think of this can get is a variable name from
// the expression
public virtual string GetTargetComponentName (CodeStatement statement, CodeExpression expression, Type targetType)
{
if (expression is CodeFieldReferenceExpression)
return ((CodeFieldReferenceExpression) expression).FieldName;
else if (expression is CodeVariableReferenceExpression)
return ((CodeVariableReferenceExpression) expression).VariableName;
return null;
}
public virtual CodeStatementCollection SerializeMember (IDesignerSerializationManager manager,
object owningobject, MemberDescriptor member)
{
if (member == null)
throw new ArgumentNullException ("member");
if (owningobject == null)
throw new ArgumentNullException ("owningobject");
if (manager == null)
throw new ArgumentNullException ("manager");
CodeStatementCollection statements = new CodeStatementCollection ();
CodeExpression expression = base.GetExpression (manager, owningobject);
if (expression == null) {
string name = manager.GetName (owningobject);
if (name == null)
name = base.GetUniqueName (manager, owningobject);
expression = new CodeVariableReferenceExpression (name);
base.SetExpression (manager, owningobject, expression);
}
if (member is PropertyDescriptor)
base.SerializeProperty (manager, statements, owningobject, (PropertyDescriptor) member);
if (member is EventDescriptor)
base.SerializeEvent (manager, statements, owningobject, (EventDescriptor) member);
return statements;
}
public virtual CodeStatementCollection SerializeMemberAbsolute (IDesignerSerializationManager manager,
object owningobject, MemberDescriptor member)
{
if (member == null)
throw new ArgumentNullException ("member");
if (owningobject == null)
throw new ArgumentNullException ("owningobject");
if (manager == null)
throw new ArgumentNullException ("manager");
SerializeAbsoluteContext context = new SerializeAbsoluteContext (member);
manager.Context.Push (context);
CodeStatementCollection result = this.SerializeMember (manager, owningobject, member);
manager.Context.Pop ();
return result;
}
public virtual object Deserialize (IDesignerSerializationManager manager, object codeObject)
{
object deserialized = null;
CodeExpression expression = codeObject as CodeExpression;
if (expression != null)
deserialized = base.DeserializeExpression (manager, null, expression);
CodeStatement statement = codeObject as CodeStatement;
if (statement != null)
deserialized = DeserializeStatementToInstance (manager, statement);
CodeStatementCollection statements = codeObject as CodeStatementCollection;
if (statements != null) {
foreach (CodeStatement s in statements) {
if (deserialized == null)
deserialized = DeserializeStatementToInstance (manager, s);
else
DeserializeStatement (manager, s);
}
}
return deserialized;
}
protected object DeserializeStatementToInstance (IDesignerSerializationManager manager, CodeStatement statement)
{
CodeAssignStatement assignment = statement as CodeAssignStatement;
if (assignment != null) {
// CodeFieldReferenceExpression
//
CodeFieldReferenceExpression fieldRef = assignment.Left as CodeFieldReferenceExpression;
if (fieldRef != null)
return base.DeserializeExpression (manager, fieldRef.FieldName, assignment.Right);
}
base.DeserializeStatement (manager, statement);
return null;
}
}
}
#endif

View File

@ -0,0 +1,84 @@
//
// System.ComponentModel.Design.Serialization.CodeDomSerializerException.cs
//
// Author:
// Zoltan Varga (vargaz@gmail.com)
//
// Copyright (C) 2004-2005 Novell (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System.CodeDom;
using System.Runtime.Serialization;
namespace System.ComponentModel.Design.Serialization {
#if NET_2_0
[Serializable]
#endif
public class CodeDomSerializerException : SystemException
{
private CodeLinePragma linePragma;
public CodeDomSerializerException (Exception ex, CodeLinePragma linePragma)
: base (String.Empty, ex) {
this.linePragma = linePragma;
}
public CodeDomSerializerException (String message, CodeLinePragma linePragma)
: base (message) {
this.linePragma = linePragma;
}
[MonoTODO]
protected CodeDomSerializerException (SerializationInfo info, StreamingContext context) {
throw new NotImplementedException ();
}
#if NET_2_0
[MonoTODO]
public CodeDomSerializerException (string message, IDesignerSerializationManager manager)
{
throw new NotImplementedException ();
}
[MonoTODO]
public CodeDomSerializerException (Exception ex, IDesignerSerializationManager manager)
{
throw new NotImplementedException ();
}
#endif
[MonoTODO]
public override void GetObjectData (SerializationInfo info, StreamingContext context)
{
throw new NotImplementedException();
}
public CodeLinePragma LinePragma {
get {
return linePragma;
}
}
}
}

View File

@ -0,0 +1,156 @@
//
// System.ComponentModel.Design.Serialization.CollectionCodeDomSerializer
//
// Authors:
// Ivan N. Zlatev (contact i-nZ.net)
//
// (C) 2007 Ivan N. Zlatev
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
#if NET_2_0
using System;
using System.Collections;
using System.Reflection;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.CodeDom;
namespace System.ComponentModel.Design.Serialization
{
public class CollectionCodeDomSerializer : CodeDomSerializer
{
public CollectionCodeDomSerializer ()
{
}
// FIXME: What is this supposed to do?
protected bool MethodSupportsSerialization (MethodInfo method)
{
return true;
}
public override object Serialize (IDesignerSerializationManager manager, object value)
{
if (value == null)
throw new ArgumentNullException ("value");
if (manager == null)
throw new ArgumentNullException ("manager");
ICollection originalCollection = value as ICollection;
if (originalCollection == null)
throw new ArgumentException ("originalCollection is not an ICollection");
CodeExpression targetExpression = null;
ExpressionContext exprContext = manager.Context[typeof (ExpressionContext)] as ExpressionContext;
RootContext root = manager.Context[typeof (RootContext)] as RootContext;
if (exprContext != null && exprContext.PresetValue == value)
targetExpression = exprContext.Expression;
else if (root != null)
targetExpression = root.Expression;
ArrayList valuesToSerialize = new ArrayList ();
foreach (object o in originalCollection)
valuesToSerialize.Add (o);
return this.SerializeCollection (manager, targetExpression, value.GetType (), originalCollection, valuesToSerialize);
}
protected virtual object SerializeCollection (IDesignerSerializationManager manager, CodeExpression targetExpression,
Type targetType, ICollection originalCollection, ICollection valuesToSerialize)
{
if (valuesToSerialize == null)
throw new ArgumentNullException ("valuesToSerialize");
if (originalCollection == null)
throw new ArgumentNullException ("originalCollection");
if (targetType == null)
throw new ArgumentNullException ("targetType");
if (manager == null)
throw new ArgumentNullException ("manager");
if (valuesToSerialize.Count == 0)
return null;
MethodInfo method = null;
try {
object sampleParam = null;
IEnumerator e = valuesToSerialize.GetEnumerator ();
e.MoveNext ();
sampleParam = e.Current;
// try to find a method matching the type of the sample parameter.
// Assuming objects in the collection are from the same base type
method = GetExactMethod (targetType, "Add", new object [] { sampleParam });
} catch {
base.ReportError (manager, "A compatible Add/AddRange method is missing in the collection type '"
+ targetType.Name + "'");
}
if (method == null)
return null;
CodeStatementCollection statements = new CodeStatementCollection ();
foreach (object value in valuesToSerialize) {
CodeMethodInvokeExpression methodInvoke = new CodeMethodInvokeExpression ();
methodInvoke.Method = new CodeMethodReferenceExpression (targetExpression, "Add");
CodeExpression expression = base.SerializeToExpression (manager, value);
if (expression != null) {
methodInvoke.Parameters.AddRange (new CodeExpression[] { expression });
statements.Add (methodInvoke);
}
}
return statements;
}
// Searches for a method on type that matches argument types
//
private MethodInfo GetExactMethod (Type type, string methodName, ICollection argsCollection)
{
object[] arguments = null;
Type[] types = Type.EmptyTypes;
if (argsCollection != null) {
arguments = new object[argsCollection.Count];
types = new Type[argsCollection.Count];
argsCollection.CopyTo (arguments, 0);
for (int i=0; i < arguments.Length; i++) {
if (arguments[i] == null)
types[i] = null;
else
types[i] = arguments[i].GetType ();
}
}
return type.GetMethod (methodName, types);
}
}
}
#endif

View File

@ -0,0 +1,116 @@
//
// System.ComponentModel.Design.Serialization.ComponentCodeDomSerializer
//
// Authors:
// Ivan N. Zlatev (contact i-nZ.net)
//
// (C) 2007 Ivan N. Zlatev
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
#if NET_2_0
using System;
using System.Collections;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.CodeDom;
namespace System.ComponentModel.Design.Serialization
{
// A serializer for the IComponent Type, supplied by the CodeDomSerializationProvider,
// added as a provider by the RootComponentCodeDomSerializer
//
internal class ComponentCodeDomSerializer : CodeDomSerializer
{
public ComponentCodeDomSerializer ()
{
}
public override object Serialize (IDesignerSerializationManager manager, object value)
{
if (value == null)
throw new ArgumentNullException ("value");
if (manager == null)
throw new ArgumentNullException ("manager");
RootContext rootContext = manager.Context[typeof (RootContext)] as RootContext;
if (rootContext != null && rootContext.Value == value)
return rootContext.Expression;
CodeStatementCollection statements = new CodeStatementCollection ();
if (((IComponent)value).Site == null) {
ReportError (manager, "Component of type '" + value.GetType().Name + "' not sited");
return statements;
}
// the trick with the nested components is that GetName will return the full name
// e.g splitter1.Panel1 and thus the code below will create a reference to that.
//
string name = manager.GetName (value);
CodeExpression componentRef = null;
if (rootContext != null)
componentRef = new CodeFieldReferenceExpression (rootContext.Expression , name);
else
componentRef = new CodeFieldReferenceExpression (new CodeThisReferenceExpression () , name);
base.SetExpression (manager, value, componentRef);
ExpressionContext context = manager.Context[typeof (ExpressionContext)] as ExpressionContext;
// Perform some heuristics here.
//
// If there is an ExpressionContext of PropertyReference where PresetValue == this
// partial serialization doesn't make sense, so perform full. E.g in the case of:
//
// PropertyCodeDomSerializer.SerializeContentProperty and splitContainer1.*Panel1*
//
if (context == null || context.PresetValue != value ||
(context.PresetValue == value && (context.Expression is CodeFieldReferenceExpression ||
context.Expression is CodePropertyReferenceExpression))) {
bool isComplete = true;
statements.Add (new CodeCommentStatement (String.Empty));
statements.Add (new CodeCommentStatement (name));
statements.Add (new CodeCommentStatement (String.Empty));
// Do not serialize a creation expression for Nested components
//
if (! (((IComponent)value).Site is INestedSite)) {
CodeStatement assignment = new CodeAssignStatement (componentRef,
base.SerializeCreationExpression (manager, value,
out isComplete));
assignment.UserData["statement-order"] = "initializer";
statements.Add (assignment);
}
base.SerializeProperties (manager, statements, value, new Attribute[0]);
base.SerializeEvents (manager, statements, value);
}
return statements;
}
}
}
#endif

View File

@ -0,0 +1,84 @@
//
// System.ComponentModel.Design.Serialization.EnumCodeDomSerializer
//
// Authors:
// Ivan N. Zlatev (contact i-nZ.net)
//
// (C) 2007 Ivan N. Zlatev
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
#if NET_2_0
using System;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.CodeDom;
namespace System.ComponentModel.Design.Serialization
{
internal class EnumCodeDomSerializer : CodeDomSerializer
{
public EnumCodeDomSerializer ()
{
}
public override object Serialize (IDesignerSerializationManager manager, object value)
{
if (manager == null)
throw new ArgumentNullException ("manager");
if (value == null)
throw new ArgumentNullException ("value");
Enum[] enums = null;
TypeConverter converter = TypeDescriptor.GetConverter (value);
if (converter.CanConvertTo (typeof (Enum[])))
enums = (Enum[]) converter.ConvertTo (value, typeof (Enum[]));
else
enums = new Enum[] { (Enum) value };
CodeExpression left = null;
CodeExpression right = null;
foreach (Enum e in enums) {
right = GetEnumExpression (e);
if (left == null) // just the first time
left = right;
else
left = new CodeBinaryOperatorExpression (left, CodeBinaryOperatorType.BitwiseOr, right);
}
return left;
}
private CodeExpression GetEnumExpression (Enum e)
{
TypeConverter converter = TypeDescriptor.GetConverter (e);
if (converter != null && converter.CanConvertTo (typeof (string)))
return new CodeFieldReferenceExpression (new CodeTypeReferenceExpression (e.GetType().FullName),
(string) converter.ConvertTo (e, typeof (string)));
else
return null;
}
}
}
#endif

View File

@ -0,0 +1,89 @@
//
// System.ComponentModel.Design.Serialization.EventCodeDomSerializer
//
// Authors:
// Ivan N. Zlatev (contact i-nZ.net)
//
// (C) 2007 Ivan N. Zlatev
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
#if NET_2_0
using System;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.CodeDom;
namespace System.ComponentModel.Design.Serialization
{
internal class EventCodeDomSerializer : MemberCodeDomSerializer
{
private CodeThisReferenceExpression _thisReference;
public EventCodeDomSerializer ()
{
// don't waste memory on something that is constant when generating the
// event codedom code - keep it as a field.
_thisReference = new CodeThisReferenceExpression ();
}
public override void Serialize (IDesignerSerializationManager manager, object value, MemberDescriptor descriptor,
CodeStatementCollection statements)
{
if (statements == null)
throw new ArgumentNullException ("statements");
if (manager == null)
throw new ArgumentNullException ("manager");
if (value == null)
throw new ArgumentNullException ("value");
if (descriptor == null)
throw new ArgumentNullException ("descriptor");
IEventBindingService service = manager.GetService (typeof (IEventBindingService)) as IEventBindingService;
if (service != null) {
EventDescriptor eventDescriptor = (EventDescriptor) descriptor;
string methodName = (string) service.GetEventProperty (eventDescriptor).GetValue (value);
if (methodName != null) {
CodeDelegateCreateExpression listener = new CodeDelegateCreateExpression (new CodeTypeReference (eventDescriptor.EventType),
_thisReference, methodName);
CodeExpression targetObject = base.SerializeToExpression (manager, value);
CodeEventReferenceExpression eventRef = new CodeEventReferenceExpression (targetObject, eventDescriptor.Name);
statements.Add (new CodeAttachEventStatement (eventRef, listener));
}
}
}
public override bool ShouldSerialize (IDesignerSerializationManager manager, object value, MemberDescriptor descriptor)
{
IEventBindingService service = manager.GetService (typeof (IEventBindingService)) as IEventBindingService;
if (service != null) // serialize only if there is an event to serialize
return service.GetEventProperty ((EventDescriptor)descriptor).GetValue (value) != null;
return false;
}
}
}
#endif

View File

@ -0,0 +1,78 @@
//
// System.ComponentModel.Design.Serialization.ExpressionContext
//
// Authors:
// Ivan N. Zlatev (contact@i-nZ.net)
//
// (C) 2007 Ivan N. Zlatev
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
#if NET_2_0
using System;
using System.CodeDom;
namespace System.ComponentModel.Design.Serialization
{
public sealed class ExpressionContext
{
private object _owner;
private Type _expressionType;
private CodeExpression _expression;
private object _presetValue;
public ExpressionContext (CodeExpression expression, Type expressionType, object owner)
{
_expression = expression;
_expressionType = expressionType;
_owner = owner;
_presetValue = null;
}
public ExpressionContext (CodeExpression expression, Type expressionType, object owner, object presetValue)
{
_expression = expression;
_expressionType = expressionType;
_owner = owner;
_presetValue = presetValue;
}
public object PresetValue {
get { return _presetValue; }
}
public CodeExpression Expression {
get { return _expression; }
}
public Type ExpressionType {
get { return _expressionType; }
}
public object Owner {
get { return _owner; }
}
}
}
#endif

View File

@ -0,0 +1,39 @@
// System.ComponentModel.Design.Serialization.ICodeDomDesignerReload.cs
//
// Author:
// Alejandro Sánchez Acosta <raciel@gnome.org>
//
// (C) Alejandro Sánchez Acosta
//
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System.CodeDom;
using System.Web.UI.Design;
namespace System.ComponentModel.Design.Serialization
{
public interface ICodeDomDesignerReload
{
bool ShouldReloadDesigner (CodeCompileUnit newTree);
}
}

View File

@ -0,0 +1,51 @@
//
// System.ComponentModel.Design.Serialization.MemberCodeDomSerializer
//
// Authors:
// Ivan N. Zlatev (contact i-nZ.net)
//
// (C) 2007 Ivan N. Zlatev
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
#if NET_2_0
using System;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.CodeDom;
namespace System.ComponentModel.Design.Serialization
{
public abstract class MemberCodeDomSerializer : CodeDomSerializerBase
{
protected MemberCodeDomSerializer ()
{
}
public abstract void Serialize (IDesignerSerializationManager manager, object value, MemberDescriptor descriptor, CodeStatementCollection statements);
public abstract bool ShouldSerialize (IDesignerSerializationManager manager, object value, MemberDescriptor descriptor);
}
}
#endif

View File

@ -0,0 +1,81 @@
//
// System.ComponentModel.Design.Serialization.ObjectStatementCollection
//
// Authors:
// Ivan N. Zlatev (contact i-nZ.net)
//
// (C) 2007 Ivan N. Zlatev
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
#if NET_2_0
using System;
using System.Collections;
using System.CodeDom;
namespace System.ComponentModel.Design.Serialization
{
public sealed class ObjectStatementCollection : IEnumerable
{
private Hashtable _statements;
internal ObjectStatementCollection ()
{
_statements = new Hashtable ();
}
public bool ContainsKey (object statementOwner)
{
return _statements.ContainsKey (statementOwner);
}
public IDictionaryEnumerator GetEnumerator()
{
return _statements.GetEnumerator ();
}
public CodeStatementCollection this[object owner]
{
get { return _statements[owner] as CodeStatementCollection; }
}
IEnumerator IEnumerable.GetEnumerator()
{
return this.GetEnumerator ();
}
public void Populate (object owner)
{
if (_statements[owner] == null)
_statements[owner] = null;
}
public void Populate (ICollection statementOwners)
{
foreach (object o in statementOwners)
this.Populate (o);
}
}
}
#endif

View File

@ -0,0 +1,49 @@
//
// System.ComponentModel.Design.Serialization.PrimitiveCodeDomSerializer
//
// Authors:
// Ivan N. Zlatev (contact i-nZ.net)
//
// (C) 2007 Ivan N. Zlatev
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
#if NET_2_0
using System;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.CodeDom;
namespace System.ComponentModel.Design.Serialization
{
internal class PrimitiveCodeDomSerializer : CodeDomSerializer
{
public override object Serialize (IDesignerSerializationManager manager, object value)
{
return new CodePrimitiveExpression (value);
}
}
}
#endif

View File

@ -0,0 +1,182 @@
//
// System.ComponentModel.Design.Serialization.PropertyCodeDomSerializer
//
// Authors:
// Ivan N. Zlatev (contact i-nZ.net)
//
// (C) 2007 Ivan N. Zlatev
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
#if NET_2_0
using System;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.CodeDom;
namespace System.ComponentModel.Design.Serialization
{
internal class PropertyCodeDomSerializer : MemberCodeDomSerializer
{
public PropertyCodeDomSerializer ()
{
}
public override void Serialize (IDesignerSerializationManager manager, object value, MemberDescriptor descriptor, CodeStatementCollection statements)
{
if (manager == null)
throw new ArgumentNullException ("manager");
if (value == null)
throw new ArgumentNullException ("value");
if (descriptor == null)
throw new ArgumentNullException ("descriptor");
if (statements == null)
throw new ArgumentNullException ("statements");
PropertyDescriptor property = (PropertyDescriptor) descriptor;
if (property.Attributes.Contains (DesignerSerializationVisibilityAttribute.Content))
SerializeContentProperty (manager, value, property, statements);
else
SerializeNormalProperty (manager, value, property, statements);
}
private void SerializeNormalProperty (IDesignerSerializationManager manager,
object instance, PropertyDescriptor descriptor, CodeStatementCollection statements)
{
CodeAssignStatement assignment = new CodeAssignStatement ();
CodeExpression leftSide = null;
CodePropertyReferenceExpression propRef = null;
ExpressionContext expression = manager.Context[typeof (ExpressionContext)] as ExpressionContext;
RootContext root = manager.Context[typeof (RootContext)] as RootContext;
if (expression != null && expression.PresetValue == instance && expression.Expression != null) {
leftSide = new CodePropertyReferenceExpression (expression.Expression, descriptor.Name);
} else if (root != null && root.Value == instance) {
leftSide = new CodePropertyReferenceExpression (root.Expression, descriptor.Name);
} else {
propRef = new CodePropertyReferenceExpression ();
propRef.PropertyName = descriptor.Name;
propRef.TargetObject = base.SerializeToExpression (manager, instance);
leftSide = propRef;
}
CodeExpression rightSide = null;
MemberRelationship relationship = GetRelationship (manager, instance, descriptor);
if (!relationship.IsEmpty) {
propRef = new CodePropertyReferenceExpression ();
propRef.PropertyName = relationship.Member.Name;
propRef.TargetObject = base.SerializeToExpression (manager, relationship.Owner);
rightSide = propRef;
} else {
rightSide = base.SerializeToExpression (manager, descriptor.GetValue (instance));
}
if (rightSide == null || leftSide == null) {
base.ReportError (manager, "Cannot serialize " + ((IComponent)instance).Site.Name + "." + descriptor.Name,
"Property Name: " + descriptor.Name + System.Environment.NewLine +
"Property Type: " + descriptor.PropertyType.Name + System.Environment.NewLine);
} else {
assignment.Left = leftSide;
assignment.Right = rightSide;
statements.Add (assignment);
}
}
private void SerializeContentProperty (IDesignerSerializationManager manager, object instance,
PropertyDescriptor descriptor, CodeStatementCollection statements)
{
CodePropertyReferenceExpression propRef = new CodePropertyReferenceExpression ();
propRef.PropertyName = descriptor.Name;
object propertyValue = descriptor.GetValue (instance);
ExpressionContext expressionCtx = manager.Context[typeof (ExpressionContext)] as ExpressionContext;
if (expressionCtx != null && expressionCtx.PresetValue == instance)
propRef.TargetObject = expressionCtx.Expression;
else
propRef.TargetObject = base.SerializeToExpression (manager, instance);
CodeDomSerializer serializer = manager.GetSerializer (propertyValue.GetType (), typeof (CodeDomSerializer)) as CodeDomSerializer;
if (propRef.TargetObject != null && serializer != null) {
manager.Context.Push (new ExpressionContext (propRef, propRef.GetType (), null, propertyValue));
object serialized = serializer.Serialize (manager, propertyValue);
manager.Context.Pop ();
CodeStatementCollection serializedStatements = serialized as CodeStatementCollection;
if (serializedStatements != null)
statements.AddRange (serializedStatements);
CodeStatement serializedStatement = serialized as CodeStatement;
if (serializedStatement != null)
statements.Add (serializedStatement);
CodeExpression serializedExpr = serialized as CodeExpression;
if (serializedExpr != null)
statements.Add (new CodeAssignStatement (propRef, serializedExpr));
}
}
public override bool ShouldSerialize (IDesignerSerializationManager manager, object value, MemberDescriptor descriptor)
{
if (manager == null)
throw new ArgumentNullException ("manager");
if (value == null)
throw new ArgumentNullException ("value");
if (descriptor == null)
throw new ArgumentNullException ("descriptor");
PropertyDescriptor property = (PropertyDescriptor) descriptor;
if (property.Attributes.Contains (DesignOnlyAttribute.Yes))
return false;
SerializeAbsoluteContext absolute = manager.Context[typeof (SerializeAbsoluteContext)] as SerializeAbsoluteContext;
if (absolute != null && absolute.ShouldSerialize (descriptor))
return true;
bool result = property.ShouldSerializeValue (value);
if (!result) {
if (!GetRelationship (manager, value, descriptor).IsEmpty)
result = true;
}
return result;
}
private MemberRelationship GetRelationship (IDesignerSerializationManager manager, object value, MemberDescriptor descriptor)
{
MemberRelationshipService service = manager.GetService (typeof (MemberRelationshipService)) as MemberRelationshipService;
if (service != null)
return service[value, descriptor];
else
return MemberRelationship.Empty;
}
}
}
#endif

Some files were not shown because too many files have changed in this diff Show More