User: xtoff
Date: 2009/12/20 01:48 AM

Added:
 
/InversionOfControl/trunk/src/Castle.MicroKernel/SubSystems/Conversion/Converters/
  TypeDescriptor.cs

Modified:
 /InversionOfControl/trunk/src/Castle.MicroKernel/
  Castle.MicroKernel-vs2008.csproj
 /InversionOfControl/trunk/src/Castle.MicroKernel/LifecycleConcerns/
  SupportInitializeConcern.cs

Log:
 - for Silverlight support:
  -- excluded SupportInitializeConcern as ISupportInitialize is internal in 
Silverlight
  -- added our own minimalistic naive implementation of TypeDescriptor for 
ComponentModelConverter's use, as that class does not exist in Silverlight

File Changes:

Directory: /InversionOfControl/trunk/src/Castle.MicroKernel/
============================================================

File [modified]: Castle.MicroKernel-vs2008.csproj
Delta lines: +5 -2
===================================================================

--- 
InversionOfControl/trunk/src/Castle.MicroKernel/LifecycleConcerns/SupportInitializeConcern.cs
       2009-12-20 06:09:22 UTC (rev 6490)
+++ 
InversionOfControl/trunk/src/Castle.MicroKernel/LifecycleConcerns/SupportInitializeConcern.cs
       2009-12-20 08:48:40 UTC (rev 6491)
@@ -14,6 +14,7 @@
 
 namespace Castle.MicroKernel.LifecycleConcerns
 {
+#if (!SILVERLIGHT)
        using System;
        using System.ComponentModel;
 
@@ -22,9 +23,8 @@
        /// <summary>
        /// Summary description for SupportInitializeConcern.
        /// </summary>
-#if (!SILVERLIGHT)
+
        [Serializable]
-#endif
        public class SupportInitializeConcern : ILifecycleConcern
        {
                private static readonly SupportInitializeConcern instance = new 
SupportInitializeConcern();
@@ -44,4 +44,7 @@
                        (component as ISupportInitialize).EndInit();
                }
        }
+#else
+#warning ISupportInitialize is internal in Silverlight
+#endif

Directory: 
/InversionOfControl/trunk/src/Castle.MicroKernel/SubSystems/Conversion/Converters/
=============================================================================================

File [added]: TypeDescriptor.cs
Delta lines: +0 -0
===================================================================

Directory: /InversionOfControl/trunk/src/Castle.MicroKernel/LifecycleConcerns/
==============================================================================

File [modified]: SupportInitializeConcern.cs
Delta lines: +78 -0
===================================================================

--- 
InversionOfControl/trunk/src/Castle.MicroKernel/SubSystems/Conversion/Converters/TypeDescriptor.cs
                          (rev 0)
+++ 
InversionOfControl/trunk/src/Castle.MicroKernel/SubSystems/Conversion/Converters/TypeDescriptor.cs
  2009-12-20 08:48:40 UTC (rev 6491)
@@ -0,0 +1,78 @@
+// Copyright 2004-2009 Castle Project - http://www.castleproject.org/
+// 
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+// 
+//     http://www.apache.org/licenses/LICENSE-2.0
+// 
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+namespace Castle.MicroKernel.SubSystems.Conversion
+{
+#if (SILVERLIGHT)
+       using System;
+       using System.Collections.Generic;
+       using System.ComponentModel;
+
+       using Castle.Core.Internal;
+       
+       /// <summary>
+       /// Our own minimalistic implementation of TypeDescriptor class, which 
does not exist in Silverlight.
+       /// It exists solely to support functionality of <see 
cref="ComponentModelConverter"/> and does not provide
+       /// full functionality of the actualy thing from the full .NET 
framework.
+       /// </summary>
+       public class TypeDescriptor
+       {
+               private static readonly Lock @lock = Lock.Create();
+               private static readonly IDictionary<Type,TypeConverter> 
convertersByType = new Dictionary<Type, TypeConverter>();
+
+
+               public static TypeConverter GetConverter(Type type)
+               {
+                       using(var holder = @lock.ForReadingUpgradeable())
+                       {
+                               TypeConverter converter;
+                               if (convertersByType.TryGetValue(type, out 
converter))
+                               {
+                                       return converter;
+                               }
+
+                               holder.Upgrade();
+                               if (convertersByType.TryGetValue(type, out 
converter))
+                               {
+                                       return converter;
+                               }
+
+                               var converterAttribute = 
Attribute.GetCustomAttribute(type, typeof(TypeConverterAttribute), false) as 
TypeConverterAttribute;
+                               if (converterAttribute == null)
+                               {
+                                       return null;
+                               }
+                               var converterType = 
Type.GetType(converterAttribute.ConverterTypeName, false);
+                               if (converterType == null)
+                               {
+                                       // this should really never happen, but 
just in case...
+                                       return null;
+                               }
+                               try
+                               {
+                                       converter = 
(TypeConverter)Activator.CreateInstance(converterType);
+                               }
+                               catch (Exception)
+                               {
+                                       // bummer... looks like we're dealing 
with some fancy converter.
+                                       // we should really get some logging in 
place here...
+                                       return null;
+                               }
+                               convertersByType.Add(type, converter);
+                               return converter;
+                       }
+               }
+       }
+#endif
+}

--

You received this message because you are subscribed to the Google Groups 
"Castle Project Commits" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/castle-project-commits?hl=en.


Reply via email to