/// <summary> /// Generates all of the properties for the type. /// </summary> private void GenerateProperties() { IEnumerable <PropertyDescriptor> properties = TypeDescriptor.GetProperties(this.Type) .Cast <PropertyDescriptor>() .OrderBy(p => p.Name); foreach (PropertyDescriptor pd in properties) { if (!this.ShouldDeclareProperty(pd)) { continue; } // Generate a property getter/setter pair for every property whose type // we support. Non supported property types will be skipped. if (this.CanGenerateProperty(pd)) { // Ensure the property is not virtual, abstract or new // If there is a violation, we log the error and keep // running to accumulate all such errors. This function // may return an "okay" for non-error case polymorphics. if (!this.CanGeneratePropertyIfPolymorphic(pd)) { continue; } if (!this.GenerateNonSerializableProperty(pd)) { Type propType = CodeGenUtilities.TranslateType(pd.PropertyType); List <Type> typesToCodeGen = new List <Type>(); bool isTypeSafeToGenerate = true; // Create a list containing the types we will require on the client if (TypeUtility.IsPredefinedDictionaryType(propType)) { typesToCodeGen.AddRange(CodeGenUtilities.GetDictionaryGenericArgumentTypes(propType)); } else { typesToCodeGen.Add(TypeUtility.GetElementType(propType)); } // We consider all predefined types as legal to code-gen *except* those // that would generate a compile error on the client due to missing reference. // We treat "don't know" and "false" as grounds for a warning. // Note that we do this *after* TranslateType so that types like System.Data.Linq.Binary // which cannot exist on the client anyway has been translated foreach (Type type in typesToCodeGen) { // Enum (and nullable<enum>) types may require generation on client Type nonNullableType = TypeUtility.GetNonNullableType(type); if (nonNullableType.IsEnum) { // Register use of this enum type, which could cause deferred generation this.ClientProxyGenerator.RegisterUseOfEnumType(nonNullableType); } // If this is not an enum or nullable<enum> and we're not generating the complex type, determine whether this // property type is visible to the client. If it is not, log a warning. else if (!this.ComplexTypes.Contains(type)) { // "Don't know" counts as "no" CodeMemberShareKind enumShareKind = this.ClientProxyGenerator.GetTypeShareKind(nonNullableType); if ((enumShareKind & CodeMemberShareKind.Shared) == 0) { this.ClientProxyGenerator.LogWarning(string.Format(CultureInfo.CurrentCulture, Resource.ClientCodeGen_PropertyType_Not_Shared, pd.Name, this.Type.FullName, type.FullName, this.ClientProxyGenerator.ClientProjectName)); isTypeSafeToGenerate = false; // Flag error but continue to allow accumulation of additional errors. } } } if (isTypeSafeToGenerate) { // Generate OnMethodXxxChanging/Changed partial methods. // Note: the parameter type reference needs to handle the possibility the // property type is defined in the project's root namespace and that VB prepends // that namespace. The utility helper gives us the right type reference. CodeTypeReference parameterTypeRef = CodeGenUtilities.GetTypeReference(propType, this.ClientProxyGenerator, this.ProxyClass); this.NotificationMethodGen.AddMethodFor(pd.Name + "Changing", new CodeParameterDeclarationExpression(parameterTypeRef, "value"), null); this.NotificationMethodGen.AddMethodFor(pd.Name + "Changed", null); this.GenerateProperty(pd); } } } else { this.OnPropertySkipped(pd); } } }