public static CustomProperty CreateCustomProperty(IServiceProvider serviceProvider, string customPropertyName, PropertyDescriptor propertyDescriptor, object propertyOwner)
        {
            CustomProperty property = new CustomProperty(serviceProvider)
            {
                Name = customPropertyName
            };

            if (TypeProvider.IsAssignable(typeof(ActivityBind), propertyDescriptor.PropertyType))
            {
                System.Type type = PropertyDescriptorUtils.GetBaseType(propertyDescriptor, propertyOwner, serviceProvider);
                if (type == null)
                {
                    throw new InvalidOperationException(SR.GetString("Error_CantDeterminePropertyBaseType", new object[] { propertyDescriptor.Name }));
                }
                property.Type = type.FullName;
            }
            else
            {
                property.Type = propertyDescriptor.PropertyType.FullName;
            }
            if (propertyDescriptor is ActivityBindPropertyDescriptor)
            {
                DependencyProperty property2 = DependencyProperty.FromName(propertyDescriptor.Name, propertyDescriptor.ComponentType);
                property.IsEvent = (property2 != null) && property2.IsEvent;
            }
            property.Category = propertyDescriptor.Category;
            return(property);
        }
        public override void SetValue(object component, object value)
        {
            Activity activity = component as Activity;

            if (activity != null)
            {
                ISite site = PropertyDescriptorUtils.GetSite(ServiceProvider, component);
                if (site == null)
                {
                    throw new Exception(SR.GetString(SR.General_MissingService, typeof(ISite).FullName));
                }

                IIdentifierCreationService identifierCreationService = site.GetService(typeof(IIdentifierCreationService)) as IIdentifierCreationService;
                if (identifierCreationService == null)
                {
                    throw new Exception(SR.GetString(SR.General_MissingService, typeof(IIdentifierCreationService).FullName));
                }

                string newID = value as string;
                identifierCreationService.ValidateIdentifier(activity, newID);

                DesignerHelpers.UpdateSiteName(activity, newID);
                base.SetValue(component, value);
            }
        }
Exemplo n.º 3
0
        public static CustomProperty CreateCustomProperty(IServiceProvider serviceProvider, string customPropertyName, PropertyDescriptor propertyDescriptor, object propertyOwner)
        {
            CustomProperty newCustomProperty = new CustomProperty(serviceProvider);

            newCustomProperty.Name = customPropertyName;
            if (TypeProvider.IsAssignable(typeof(ActivityBind), propertyDescriptor.PropertyType))
            {
                Type baseType = PropertyDescriptorUtils.GetBaseType(propertyDescriptor, propertyOwner, serviceProvider);
                if (baseType == null)
                {
                    throw new InvalidOperationException(SR.GetString(SR.Error_CantDeterminePropertyBaseType, propertyDescriptor.Name));
                }
                newCustomProperty.Type = baseType.FullName;
            }
            else
            {
                newCustomProperty.Type = propertyDescriptor.PropertyType.FullName;
            }

            if (propertyDescriptor is ActivityBindPropertyDescriptor)
            {
                DependencyProperty dependencyProperty = DependencyProperty.FromName(propertyDescriptor.Name, propertyDescriptor.ComponentType);
                newCustomProperty.IsEvent = (dependencyProperty != null && dependencyProperty.IsEvent);
            }

            newCustomProperty.Category = propertyDescriptor.Category;
            return(newCustomProperty);
        }
Exemplo n.º 4
0
        public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
        {
            if (destinationType != typeof(string))
            {
                return(base.ConvertTo(context, culture, value, destinationType));
            }

            string convertedValue = null;

            ActivityBind activityBind = value as ActivityBind;

            if (activityBind != null)
            {
                Activity activity = PropertyDescriptorUtils.GetComponent(context) as Activity;
                activity       = (activity != null) ? Helpers.ParseActivityForBind(activity, activityBind.Name) : null;
                convertedValue = String.Format(CultureInfo.InvariantCulture, ("Activity={0}, Path={1}"), (activity != null) ? activity.QualifiedName : activityBind.Name, activityBind.Path);
            }
            else
            {
                ITypeDescriptorContext actualContext = null; TypeConverter actualConverter = null;
                GetActualTypeConverterAndContext(context, out actualConverter, out actualContext);
                if (actualConverter != null && actualConverter.GetType() != typeof(ActivityBindTypeConverter) && actualConverter.CanConvertTo(actualContext, destinationType))
                {
                    convertedValue = actualConverter.ConvertTo(actualContext, culture, value, destinationType) as string;
                }
                else
                {
                    convertedValue = base.ConvertTo(context, culture, value, destinationType) as string;
                }
            }

            return(convertedValue);
        }
Exemplo n.º 5
0
 public override void SetValue(object component, object value)
 {
     if (component is IComponent)
     {
         this.realPropertyDescriptor.SetValue(component, value);
     }
     else
     {
         PropertyDescriptorUtils.SetPropertyValue(ServiceProvider, this.realPropertyDescriptor, component, value);
     }
 }
Exemplo n.º 6
0
        public override object GetValue(object component)
        {
            object obj2 = base.GetValue(component);
            string str  = obj2 as string;

            if (!string.IsNullOrEmpty(str))
            {
                Activity context = PropertyDescriptorUtils.GetComponent(this.context) as Activity;
                context = (context != null) ? Helpers.ParseActivityForBind(context, str) : null;
                obj2    = (context != null) ? context.QualifiedName : str;
            }
            return(obj2);
        }
        public override object GetValue(object component)
        {
            object value = base.GetValue(component);
            string id    = value as string;

            if (!String.IsNullOrEmpty(id))
            {
                Activity activity = PropertyDescriptorUtils.GetComponent(this.context) as Activity;
                activity = (activity != null) ? Helpers.ParseActivityForBind(activity, id) : null;
                value    = (activity != null) ? activity.QualifiedName : id;
            }

            return(value);
        }
Exemplo n.º 8
0
        public override void SetValue(object component, object value)
        {
            string str = value as string;

            if (string.IsNullOrEmpty(str))
            {
                throw new InvalidOperationException(SR.GetString("Error_ActivityIdentifierCanNotBeEmpty"));
            }
            Activity context = PropertyDescriptorUtils.GetComponent(this.context) as Activity;

            if ((context != null) && (Helpers.ParseActivityForBind(context, str) == null))
            {
                throw new InvalidOperationException(SR.GetString("Error_InvalidActivityIdentifier", new object[] { str }));
            }
            base.SetValue(component, value);
        }
        public override PropertyDescriptorCollection GetProperties(ITypeDescriptorContext context, object value, Attribute[] attributes)
        {
            PropertyDescriptorCollection descriptors = new PropertyDescriptorCollection(new PropertyDescriptor[0]);
            TypeConverter converter = TypeDescriptor.GetConverter(value.GetType());

            if (((converter != null) && (converter.GetType() != base.GetType())) && converter.GetPropertiesSupported())
            {
                return(converter.GetProperties(context, value, attributes));
            }
            IComponent component = PropertyDescriptorUtils.GetComponent(context);

            if (component != null)
            {
                descriptors = PropertyDescriptorFilter.FilterProperties(component.Site, value, TypeDescriptor.GetProperties(value, new Attribute[] { BrowsableAttribute.Yes }));
            }
            return(descriptors);
        }
Exemplo n.º 10
0
 public override void SetValue(object component, object value)
 {
     if (component == null)
     {
         throw new ArgumentNullException("component");
     }
     if (value != null)
     {
         Type type = value as Type;
         ITypeFilterProvider provider = PropertyDescriptorUtils.GetComponent(new TypeDescriptorContext(base.ServiceProvider, base.RealPropertyDescriptor, component)) as ITypeFilterProvider;
         if (provider != null)
         {
             provider.CanFilterType(type, true);
         }
     }
     base.SetValue(component, value);
 }
Exemplo n.º 11
0
        public override void SetValue(object component, object value)
        {
            if (component == null)
            {
                throw new ArgumentNullException("component");
            }

            if (value != null)
            {
                Type type = value as Type;
                ITypeFilterProvider filterProvider = PropertyDescriptorUtils.GetComponent(new TypeDescriptorContext(ServiceProvider, RealPropertyDescriptor, component)) as ITypeFilterProvider;
                if (filterProvider != null)
                {
                    filterProvider.CanFilterType(type, true); //this will throw an exception if the type is not correctly filterable
                }
            }

            base.SetValue(component, value);
        }
Exemplo n.º 12
0
        public override PropertyDescriptorCollection GetProperties(ITypeDescriptorContext context, object value, Attribute[] attributes)
        {
            PropertyDescriptorCollection props = new PropertyDescriptorCollection(new PropertyDescriptor[] { });

            TypeConverter typeConverter = TypeDescriptor.GetConverter(value.GetType());

            if (typeConverter != null && typeConverter.GetType() != GetType() && typeConverter.GetPropertiesSupported())
            {
                return(typeConverter.GetProperties(context, value, attributes));
            }
            else
            {
                IComponent component = PropertyDescriptorUtils.GetComponent(context);
                if (component != null)
                {
                    props = PropertyDescriptorFilter.FilterProperties(component.Site, value, TypeDescriptor.GetProperties(value, new Attribute[] { BrowsableAttribute.Yes }));
                }
            }

            return(props);
        }
        public override void SetValue(object component, object value)
        {
            string id = value as string;

            if (String.IsNullOrEmpty(id))
            {
                throw new InvalidOperationException(SR.GetString(SR.Error_ActivityIdentifierCanNotBeEmpty));
            }

            Activity activity = PropertyDescriptorUtils.GetComponent(this.context) as Activity;

            if (activity != null)
            {
                if (Helpers.ParseActivityForBind(activity, id) == null)
                {
                    throw new InvalidOperationException(SR.GetString(SR.Error_InvalidActivityIdentifier, id));
                }
            }

            base.SetValue(component, value);
        }
Exemplo n.º 14
0
        public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
        {
            if (destinationType != typeof(string))
            {
                return(base.ConvertTo(context, culture, value, destinationType));
            }
            ActivityBind bind = value as ActivityBind;

            if (bind != null)
            {
                Activity component = PropertyDescriptorUtils.GetComponent(context) as Activity;
                component = (component != null) ? Helpers.ParseActivityForBind(component, bind.Name) : null;
                return(string.Format(CultureInfo.InvariantCulture, "Activity={0}, Path={1}", new object[] { (component != null) ? component.QualifiedName : bind.Name, bind.Path }));
            }
            ITypeDescriptorContext realContext       = null;
            TypeConverter          realTypeConverter = null;

            this.GetActualTypeConverterAndContext(context, out realTypeConverter, out realContext);
            if (((realTypeConverter != null) && (realTypeConverter.GetType() != typeof(ActivityBindTypeConverter))) && realTypeConverter.CanConvertTo(realContext, destinationType))
            {
                return(realTypeConverter.ConvertTo(realContext, culture, value, destinationType) as string);
            }
            return(base.ConvertTo(context, culture, value, destinationType) as string);
        }
 internal static IList<MemberInfo> GetBindableMembers(object obj, ITypeDescriptorContext context)
 {
     List<MemberInfo> list = new List<MemberInfo>();
     IDesignerHost service = context.GetService(typeof(IDesignerHost)) as IDesignerHost;
     Activity activity = (service != null) ? (service.RootComponent as Activity) : null;
     Type type = (obj == activity) ? Helpers.GetDataSourceClass(activity, context) : obj.GetType();
     Type toType = PropertyDescriptorUtils.GetBaseType(context.PropertyDescriptor, context.Instance, context);
     if ((type != null) && (toType != null))
     {
         DependencyProperty property = DependencyProperty.FromName(context.PropertyDescriptor.Name, context.PropertyDescriptor.ComponentType);
         bool flag = (property != null) && property.IsEvent;
         BindingFlags bindingAttr = BindingFlags.FlattenHierarchy | BindingFlags.Public | BindingFlags.Static | BindingFlags.Instance;
         if (obj == activity)
         {
             bindingAttr |= BindingFlags.NonPublic;
         }
         foreach (MemberInfo info in type.GetMembers(bindingAttr))
         {
             object[] customAttributes = info.GetCustomAttributes(typeof(DebuggerNonUserCodeAttribute), false);
             if (((customAttributes == null) || (customAttributes.Length <= 0)) || !(customAttributes[0] is DebuggerNonUserCodeAttribute))
             {
                 object[] objArray2 = info.GetCustomAttributes(typeof(BrowsableAttribute), false);
                 if (objArray2.Length > 0)
                 {
                     bool browsable = false;
                     BrowsableAttribute attribute = objArray2[0] as BrowsableAttribute;
                     if (attribute != null)
                     {
                         browsable = attribute.Browsable;
                     }
                     else
                     {
                         try
                         {
                             AttributeInfoAttribute attribute2 = objArray2[0] as AttributeInfoAttribute;
                             if ((attribute2 != null) && (attribute2.AttributeInfo.ArgumentValues.Count > 0))
                             {
                                 browsable = (bool) attribute2.AttributeInfo.GetArgumentValueAs(context, 0, typeof(bool));
                             }
                         }
                         catch
                         {
                         }
                     }
                     if (!browsable)
                     {
                         continue;
                     }
                 }
                 if ((info.DeclaringType != typeof(object)) || (!string.Equals(info.Name, "Equals", StringComparison.Ordinal) && !string.Equals(info.Name, "ReferenceEquals", StringComparison.Ordinal)))
                 {
                     bool flag3 = false;
                     bool flag4 = false;
                     bool isAssembly = false;
                     if (flag && (info is EventInfo))
                     {
                         EventInfo info2 = info as EventInfo;
                         MethodInfo addMethod = info2.GetAddMethod();
                         MethodInfo removeMethod = info2.GetRemoveMethod();
                         flag4 = ((((addMethod != null) && addMethod.IsFamily) || ((removeMethod != null) && removeMethod.IsFamily)) || ((addMethod != null) && addMethod.IsPublic)) || ((removeMethod != null) && removeMethod.IsPublic);
                         isAssembly = ((addMethod != null) && addMethod.IsAssembly) || ((removeMethod != null) && removeMethod.IsAssembly);
                         flag3 = TypeProvider.IsAssignable(toType, info2.EventHandlerType);
                     }
                     else if (info is FieldInfo)
                     {
                         FieldInfo info5 = info as FieldInfo;
                         flag4 = info5.IsFamily || info5.IsPublic;
                         isAssembly = info5.IsAssembly;
                         flag3 = TypeProvider.IsAssignable(toType, info5.FieldType);
                     }
                     else if (info is PropertyInfo)
                     {
                         PropertyInfo info6 = info as PropertyInfo;
                         MethodInfo getMethod = info6.GetGetMethod();
                         MethodInfo setMethod = info6.GetSetMethod();
                         flag4 = ((((getMethod != null) && getMethod.IsFamily) || ((setMethod != null) && setMethod.IsFamily)) || ((getMethod != null) && getMethod.IsPublic)) || ((setMethod != null) && setMethod.IsPublic);
                         isAssembly = ((getMethod != null) && getMethod.IsAssembly) || ((setMethod != null) && setMethod.IsAssembly);
                         flag3 = (getMethod != null) && TypeProvider.IsAssignable(toType, info6.PropertyType);
                     }
                     if (((info.DeclaringType != type) && !flag4) && ((info.DeclaringType.Assembly != null) || !isAssembly))
                     {
                         flag3 = false;
                     }
                     if (flag3)
                     {
                         list.Add(info);
                     }
                 }
             }
         }
     }
     return list.AsReadOnly();
 }
 internal static bool CreateField(ITypeDescriptorContext context, ActivityBind activityBind, bool throwOnError)
 {
     if (!string.IsNullOrEmpty(activityBind.Path))
     {
         Type toType = PropertyDescriptorUtils.GetBaseType(context.PropertyDescriptor, context.Instance, context);
         Activity component = PropertyDescriptorUtils.GetComponent(context) as Activity;
         if ((component != null) && (toType != null))
         {
             component = Helpers.ParseActivityForBind(component, activityBind.Name);
             if (component == Helpers.GetRootActivity(component))
             {
                 bool ignoreCase = CompilerHelpers.GetSupportedLanguage(context) == SupportedLanguages.VB;
                 Type dataSourceClass = Helpers.GetDataSourceClass(component, context);
                 if (dataSourceClass != null)
                 {
                     string path = activityBind.Path;
                     int length = path.IndexOfAny(new char[] { '.', '/', '[' });
                     if (length != -1)
                     {
                         path = path.Substring(0, length);
                     }
                     MemberInfo info = FindMatchingMember(path, dataSourceClass, ignoreCase);
                     if (info != null)
                     {
                         Type fromType = null;
                         bool isPrivate = false;
                         if (info is FieldInfo)
                         {
                             isPrivate = ((FieldInfo) info).IsPrivate;
                             fromType = ((FieldInfo) info).FieldType;
                         }
                         else if (info is PropertyInfo)
                         {
                             MethodInfo getMethod = ((PropertyInfo) info).GetGetMethod();
                             MethodInfo setMethod = ((PropertyInfo) info).GetSetMethod();
                             isPrivate = ((getMethod != null) && getMethod.IsPrivate) || ((setMethod != null) && setMethod.IsPrivate);
                         }
                         else if (info is MethodInfo)
                         {
                             isPrivate = ((MethodInfo) info).IsPrivate;
                         }
                         if (length != -1)
                         {
                             PathWalker walker = new PathWalker();
                             PathMemberInfoEventArgs finalEventArgs = null;
                             walker.MemberFound = (EventHandler<PathMemberInfoEventArgs>) Delegate.Combine(walker.MemberFound, delegate (object sender, PathMemberInfoEventArgs eventArgs) {
                                 finalEventArgs = eventArgs;
                             });
                             if (!walker.TryWalkPropertyPath(dataSourceClass, activityBind.Path))
                             {
                                 if (throwOnError)
                                 {
                                     throw new InvalidOperationException(SR.GetString("Error_MemberWithSameNameExists", new object[] { activityBind.Path, dataSourceClass.FullName }));
                                 }
                                 return false;
                             }
                             fromType = BindHelpers.GetMemberType(finalEventArgs.MemberInfo);
                         }
                         if (((info.DeclaringType == dataSourceClass) || !isPrivate) && ((info is FieldInfo) && TypeProvider.IsAssignable(toType, fromType)))
                         {
                             return true;
                         }
                         if (throwOnError)
                         {
                             throw new InvalidOperationException(SR.GetString("Error_MemberWithSameNameExists", new object[] { activityBind.Path, dataSourceClass.FullName }));
                         }
                         return false;
                     }
                     Activity activity2 = null;
                     if (string.Compare(component.Name, path, ignoreCase ? StringComparison.OrdinalIgnoreCase : StringComparison.Ordinal) == 0)
                     {
                         activity2 = component;
                     }
                     else if ((component is CompositeActivity) && (component is CompositeActivity))
                     {
                         foreach (Activity activity3 in Helpers.GetAllNestedActivities(component as CompositeActivity))
                         {
                             if (string.Compare(activity3.Name, path, ignoreCase ? StringComparison.OrdinalIgnoreCase : StringComparison.Ordinal) == 0)
                             {
                                 activity2 = activity3;
                             }
                         }
                     }
                     if (activity2 != null)
                     {
                         if (TypeProvider.IsAssignable(toType, activity2.GetType()))
                         {
                             return true;
                         }
                         if (throwOnError)
                         {
                             throw new InvalidOperationException(SR.GetString("Error_MemberWithSameNameExists", new object[] { activityBind.Path, dataSourceClass.FullName }));
                         }
                         return false;
                     }
                     IMemberCreationService service = context.GetService(typeof(IMemberCreationService)) as IMemberCreationService;
                     if (service != null)
                     {
                         IDesignerHost host = context.GetService(typeof(IDesignerHost)) as IDesignerHost;
                         if (host != null)
                         {
                             service.CreateField(host.RootComponentClassName, activityBind.Path, toType, null, MemberAttributes.Public, null, false);
                             return true;
                         }
                         if (throwOnError)
                         {
                             throw new InvalidOperationException(SR.GetString("General_MissingService", new object[] { typeof(IDesignerHost).FullName }));
                         }
                     }
                     else if (throwOnError)
                     {
                         throw new InvalidOperationException(SR.GetString("General_MissingService", new object[] { typeof(IMemberCreationService).FullName }));
                     }
                 }
             }
         }
         else
         {
             if ((component == null) && throwOnError)
             {
                 throw new InvalidOperationException(SR.GetString("Error_InvalidActivityIdentifier", new object[] { activityBind.Name }));
             }
             if ((toType == null) && throwOnError)
             {
                 throw new InvalidOperationException(SR.GetString("Error_PropertyTypeNotDefined", new object[] { context.PropertyDescriptor.Name, typeof(ActivityBind).Name, typeof(IDynamicPropertyTypeProvider).Name }));
             }
         }
     }
     return false;
 }
        internal static IList <MemberInfo> GetBindableMembers(object obj, ITypeDescriptorContext context)
        {
            List <MemberInfo> memberInfos = new List <MemberInfo>();

            IDesignerHost designerHost = context.GetService(typeof(IDesignerHost)) as IDesignerHost;
            Activity      rootActivity = (designerHost != null) ? designerHost.RootComponent as Activity : null;
            Type          objectType   = (obj == rootActivity) ? Helpers.GetDataSourceClass(rootActivity, context) : obj.GetType();

            Type memberType = PropertyDescriptorUtils.GetBaseType(context.PropertyDescriptor, context.Instance, context);

            if (objectType != null && memberType != null)
            {
                DependencyProperty dependencyProperty = DependencyProperty.FromName(context.PropertyDescriptor.Name, context.PropertyDescriptor.ComponentType);
                bool includeEvents = (dependencyProperty != null && dependencyProperty.IsEvent);

                BindingFlags bindingFlags = BindingFlags.Public | BindingFlags.Instance | BindingFlags.Static | BindingFlags.FlattenHierarchy;
                if (obj == rootActivity)
                {
                    bindingFlags |= BindingFlags.NonPublic;
                }

                foreach (MemberInfo memberInfo in objectType.GetMembers(bindingFlags))
                {
                    //filter our methods with System.Diagnostics.DebuggerNonUserCodeAttribute
                    object[] nonUserCodeAttributes = memberInfo.GetCustomAttributes(typeof(System.Diagnostics.DebuggerNonUserCodeAttribute), false);
                    if (nonUserCodeAttributes != null && nonUserCodeAttributes.Length > 0 && nonUserCodeAttributes[0] is System.Diagnostics.DebuggerNonUserCodeAttribute)
                    {
                        continue;
                    }

                    object[] browsableAttributes = memberInfo.GetCustomAttributes(typeof(BrowsableAttribute), false);
                    if (browsableAttributes.Length > 0)
                    {
                        bool browsable = false;

                        BrowsableAttribute browsableAttribute = browsableAttributes[0] as BrowsableAttribute;
                        if (browsableAttribute != null)
                        {
                            browsable = browsableAttribute.Browsable;
                        }
                        else
                        {
                            try
                            {
                                AttributeInfoAttribute attributeInfoAttribute = browsableAttributes[0] as AttributeInfoAttribute;
                                if (attributeInfoAttribute != null && attributeInfoAttribute.AttributeInfo.ArgumentValues.Count > 0)
                                {
                                    browsable = (bool)attributeInfoAttribute.AttributeInfo.GetArgumentValueAs(context, 0, typeof(bool));
                                }
                            }
                            catch
                            {
                            }
                        }

                        if (!browsable)
                        {
                            continue;
                        }
                    }

                    if (memberInfo.DeclaringType == typeof(System.Object) && (string.Equals(memberInfo.Name, "Equals", StringComparison.Ordinal) || string.Equals(memberInfo.Name, "ReferenceEquals", StringComparison.Ordinal)))
                    {
                        continue;
                    }

                    bool addMember = false;
                    bool isProtectedOrPublicMember = false;
                    bool isInternalMember          = false;
                    if (includeEvents && memberInfo is EventInfo)
                    {
                        EventInfo eventInfo = memberInfo as EventInfo;

                        MethodInfo addAccessor    = eventInfo.GetAddMethod();
                        MethodInfo removeAccessor = eventInfo.GetRemoveMethod();

                        isProtectedOrPublicMember = ((addAccessor != null && addAccessor.IsFamily) || (removeAccessor != null && removeAccessor.IsFamily) ||
                                                     (addAccessor != null && addAccessor.IsPublic) || (removeAccessor != null && removeAccessor.IsPublic));
                        isInternalMember = ((addAccessor != null && addAccessor.IsAssembly) || (removeAccessor != null && removeAccessor.IsAssembly));

                        addMember = TypeProvider.IsAssignable(memberType, eventInfo.EventHandlerType);
                    }
                    else if (memberInfo is FieldInfo)
                    {
                        FieldInfo fieldInfo = memberInfo as FieldInfo;
                        isProtectedOrPublicMember = (fieldInfo.IsFamily || fieldInfo.IsPublic);
                        isInternalMember          = fieldInfo.IsAssembly;
                        addMember = TypeProvider.IsAssignable(memberType, fieldInfo.FieldType);
                    }
                    else if (memberInfo is PropertyInfo)
                    {
                        PropertyInfo propertyInfo = memberInfo as PropertyInfo;

                        MethodInfo getAccessor = propertyInfo.GetGetMethod();
                        MethodInfo setAccessor = propertyInfo.GetSetMethod();

                        isProtectedOrPublicMember = ((getAccessor != null && getAccessor.IsFamily) || (setAccessor != null && setAccessor.IsFamily) ||
                                                     (getAccessor != null && getAccessor.IsPublic) || (setAccessor != null && setAccessor.IsPublic));
                        isInternalMember = ((getAccessor != null && getAccessor.IsAssembly) || (setAccessor != null && setAccessor.IsAssembly));
                        addMember        = (getAccessor != null && TypeProvider.IsAssignable(memberType, propertyInfo.PropertyType));
                    }

                    //We only want to allow binding to protected, public and internal members of baseType
                    if (memberInfo.DeclaringType != objectType && !isProtectedOrPublicMember && !(memberInfo.DeclaringType.Assembly == null && isInternalMember))
                    {
                        addMember = false;
                    }

                    if (addMember)
                    {
                        memberInfos.Add(memberInfo);
                    }
                }
            }

            return(memberInfos.AsReadOnly());
        }
        internal static bool CreateField(ITypeDescriptorContext context, ActivityBind activityBind, bool throwOnError)
        {
            //Check if the activity is root activity and has valid design time type
            if (!String.IsNullOrEmpty(activityBind.Path))
            {
                Type     boundType = PropertyDescriptorUtils.GetBaseType(context.PropertyDescriptor, context.Instance, context);
                Activity activity  = PropertyDescriptorUtils.GetComponent(context) as Activity;
                if (activity != null && boundType != null)
                {
                    activity = Helpers.ParseActivityForBind(activity, activityBind.Name);
                    if (activity == Helpers.GetRootActivity(activity))
                    {
                        bool isVB         = (CompilerHelpers.GetSupportedLanguage(context) == SupportedLanguages.VB);
                        Type designedType = Helpers.GetDataSourceClass(activity, context);
                        if (designedType != null)
                        {
                            //field path could be nested too.
                            //need to find field only with the name up to the first dot (CimplexTypeField in the example below)
                            //and the right type (that would be tricky if the field doesnt exist yet)
                            //example: CimplexTypeField.myIDictionary_int_string[10].someOtherGood2

                            string fieldName  = activityBind.Path;
                            int    indexOfDot = fieldName.IndexOfAny(new char[] { '.', '/', '[' });
                            if (indexOfDot != -1)
                            {
                                fieldName = fieldName.Substring(0, indexOfDot); //path is a nested field access
                            }
                            MemberInfo matchingMember = ActivityBindPropertyDescriptor.FindMatchingMember(fieldName, designedType, isVB);
                            if (matchingMember != null)
                            {
                                Type memberType = null;
                                bool isPrivate  = false;
                                if (matchingMember is FieldInfo)
                                {
                                    isPrivate  = ((FieldInfo)matchingMember).IsPrivate;
                                    memberType = ((FieldInfo)matchingMember).FieldType;
                                }
                                else if (matchingMember is PropertyInfo)
                                {
                                    MethodInfo getMethod = ((PropertyInfo)matchingMember).GetGetMethod();
                                    MethodInfo setMethod = ((PropertyInfo)matchingMember).GetSetMethod();
                                    isPrivate = ((getMethod != null && getMethod.IsPrivate) || (setMethod != null && setMethod.IsPrivate));
                                }
                                else if (matchingMember is MethodInfo)
                                {
                                    isPrivate = ((MethodInfo)matchingMember).IsPrivate;
                                }

                                if (indexOfDot != -1)
                                { //need to find the type of the member the path references (and if the path is valid at all)
                                    PathWalker pathWalker = new PathWalker();
                                    PathMemberInfoEventArgs finalEventArgs = null;
                                    pathWalker.MemberFound += delegate(object sender, PathMemberInfoEventArgs eventArgs)
                                    { finalEventArgs = eventArgs; };

                                    if (pathWalker.TryWalkPropertyPath(designedType, activityBind.Path))
                                    {
                                        //successfully walked the entire path
                                        memberType = BindHelpers.GetMemberType(finalEventArgs.MemberInfo);
                                    }
                                    else
                                    {
                                        //the path is invalid
                                        if (throwOnError)
                                        {
                                            throw new InvalidOperationException(SR.GetString(SR.Error_MemberWithSameNameExists, activityBind.Path, designedType.FullName));
                                        }

                                        return(false);
                                    }
                                }

                                if ((matchingMember.DeclaringType == designedType || !isPrivate) &&
                                    matchingMember is FieldInfo &&
                                    TypeProvider.IsAssignable(boundType, memberType))
                                {
                                    return(true);
                                }
                                else
                                {
                                    if (throwOnError)
                                    {
                                        throw new InvalidOperationException(SR.GetString(SR.Error_MemberWithSameNameExists, activityBind.Path, designedType.FullName));
                                    }
                                    return(false);
                                }
                            }
                            else
                            {
                                // Find out if the name conflicts with an existing activity that has not be flushed in to the
                                // code beside.  An activity bind can bind to this field only if the type of the property
                                // is the assignable from the activity type.
                                Activity matchingActivity = null;
                                if (string.Compare(activity.Name, fieldName, isVB ? StringComparison.OrdinalIgnoreCase : StringComparison.Ordinal) == 0)
                                {
                                    matchingActivity = activity;
                                }
                                else if (activity is CompositeActivity)
                                {
                                    if (activity is CompositeActivity)
                                    {
                                        foreach (Activity existingActivity in Helpers.GetAllNestedActivities(activity as CompositeActivity))
                                        {
                                            if (string.Compare(existingActivity.Name, fieldName, isVB ? StringComparison.OrdinalIgnoreCase : StringComparison.Ordinal) == 0)
                                            {
                                                matchingActivity = existingActivity;
                                            }
                                        }
                                    }
                                }

                                if (matchingActivity != null)
                                {
                                    if (TypeProvider.IsAssignable(boundType, matchingActivity.GetType()))
                                    {
                                        return(true);
                                    }
                                    else
                                    {
                                        if (throwOnError)
                                        {
                                            throw new InvalidOperationException(SR.GetString(SR.Error_MemberWithSameNameExists, activityBind.Path, designedType.FullName));
                                        }
                                        return(false);
                                    }
                                }
                            }

                            IMemberCreationService memberCreationService = context.GetService(typeof(IMemberCreationService)) as IMemberCreationService;
                            if (memberCreationService == null)
                            {
                                if (throwOnError)
                                {
                                    throw new InvalidOperationException(SR.GetString(SR.General_MissingService, typeof(IMemberCreationService).FullName));
                                }
                            }
                            else
                            {
                                IDesignerHost designerHost = context.GetService(typeof(IDesignerHost)) as IDesignerHost;
                                if (designerHost == null)
                                {
                                    if (throwOnError)
                                    {
                                        throw new InvalidOperationException(SR.GetString("General_MissingService", typeof(IDesignerHost).FullName));
                                    }
                                }
                                else
                                {
                                    memberCreationService.CreateField(designerHost.RootComponentClassName, activityBind.Path, boundType, null, MemberAttributes.Public, null, false);
                                    return(true);
                                }
                            }
                        }
                    }
                }
                else
                {
                    if (activity == null && throwOnError)
                    {
                        throw new InvalidOperationException(SR.GetString(SR.Error_InvalidActivityIdentifier, activityBind.Name));
                    }

                    if (boundType == null && throwOnError)
                    {
                        throw new InvalidOperationException(SR.GetString(SR.Error_PropertyTypeNotDefined, context.PropertyDescriptor.Name, typeof(ActivityBind).Name, typeof(IDynamicPropertyTypeProvider).Name));
                    }
                }
            }

            return(false);
        }